Mercurial > public > mercurial-scm > hg
diff mercurial/templater.py @ 22634:e48a5d3996c2
templater: introduce templatepaths for getting paths searched for templates
Avoid function with different return types depending on parameters.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Sun, 28 Sep 2014 16:57:37 +0200 |
parents | 92b54547ac5d |
children | 660861a6fad4 |
line wrap: on
line diff
--- a/mercurial/templater.py Sun Sep 28 16:57:06 2014 +0200 +++ b/mercurial/templater.py Sun Sep 28 16:57:37 2014 +0200 @@ -625,7 +625,7 @@ engines = {'default': engine} def stylelist(): - paths = templatepath() + paths = templatepaths() if not paths: return _('no templates found, try `hg debuginstall` for more info') dirlist = os.listdir(paths[0]) @@ -710,25 +710,26 @@ max=self.maxchunk) return stream -def templatepath(name=None): - '''return location of template file or directory (if no name). - returns None if not found.''' +def templatepaths(): + '''return locations used for template files.''' normpaths = [] - for f in path: if f.startswith('/'): p = f else: fl = f.split('/') p = os.path.join(util.datapath, *fl) - if name: - p = os.path.join(p, name) - if name and os.path.exists(p): - return os.path.normpath(p) - elif os.path.isdir(p): + if os.path.isdir(p): normpaths.append(os.path.normpath(p)) + return normpaths - return normpaths +def templatepath(name): + '''return location of template file. returns None if not found.''' + for p in templatepaths(): + f = os.path.join(p, name) + if os.path.exists(f): + return f + return None def stylemap(styles, paths=None): """Return path to mapfile for a given style. @@ -740,7 +741,7 @@ """ if paths is None: - paths = templatepath() + paths = templatepaths() elif isinstance(paths, str): paths = [paths]