Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pystache_custom
Commits
2550417f
Commit
2550417f
authored
Dec 29, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored Locator: added _find_path() method.
parent
d7475e63
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
6 deletions
+21
-6
pystache/locator.py
+21
-6
No files found.
pystache/locator.py
View file @
2550417f
...
@@ -30,6 +30,21 @@ class Locator(object):
...
@@ -30,6 +30,21 @@ class Locator(object):
self
.
template_extension
=
extension
self
.
template_extension
=
extension
def
_find_path
(
self
,
file_name
,
search_dirs
):
"""
Search for the given file, and return the path.
Returns None if the file is not found.
"""
for
dir_path
in
search_dirs
:
file_path
=
os
.
path
.
join
(
dir_path
,
file_name
)
if
os
.
path
.
exists
(
file_path
):
return
file_path
return
None
def
make_file_name
(
self
,
template_name
):
def
make_file_name
(
self
,
template_name
):
file_name
=
template_name
file_name
=
template_name
if
self
.
template_extension
is
not
False
:
if
self
.
template_extension
is
not
False
:
...
@@ -74,11 +89,11 @@ class Locator(object):
...
@@ -74,11 +89,11 @@ class Locator(object):
"""
"""
file_name
=
self
.
make_file_name
(
template_name
)
file_name
=
self
.
make_file_name
(
template_name
)
for
dir_path
in
search_dirs
:
path
=
self
.
_find_path
(
file_name
,
search_dirs
)
file_path
=
os
.
path
.
join
(
dir_path
,
file_name
)
if
os
.
path
.
exists
(
file_path
):
return
file_path
# TODO: we should probably raise an exception of our own type.
if
path
is
not
None
:
raise
IOError
(
'"
%
s" not found in "
%
s"'
%
(
template_name
,
':'
.
join
(
search_dirs
),))
return
path
# TODO: we should probably raise an exception of our own type.
raise
IOError
(
'Template
%
s not found in directories:
%
s'
%
(
repr
(
template_name
),
repr
(
search_dirs
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment