changeset 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
files mercurial/commands.py mercurial/hgweb/hgwebdir_mod.py mercurial/hgweb/webcommands.py mercurial/templater.py
diffstat 4 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sun Sep 28 16:57:06 2014 +0200
+++ b/mercurial/commands.py	Sun Sep 28 16:57:37 2014 +0200
@@ -2256,7 +2256,7 @@
 
     # templates
     import templater
-    p = templater.templatepath()
+    p = templater.templatepaths()
     ui.status(_("checking templates (%s)...\n") % ' '.join(p))
     if p:
         m = templater.templatepath("map-cmdline.default")
--- a/mercurial/hgweb/hgwebdir_mod.py	Sun Sep 28 16:57:06 2014 +0200
+++ b/mercurial/hgweb/hgwebdir_mod.py	Sun Sep 28 16:57:37 2014 +0200
@@ -193,7 +193,7 @@
                     static = self.ui.config("web", "static", None,
                                             untrusted=False)
                     if not static:
-                        tp = self.templatepath or templater.templatepath()
+                        tp = self.templatepath or templater.templatepaths()
                         if isinstance(tp, str):
                             tp = [tp]
                         static = [os.path.join(p, 'static') for p in tp]
--- a/mercurial/hgweb/webcommands.py	Sun Sep 28 16:57:06 2014 +0200
+++ b/mercurial/hgweb/webcommands.py	Sun Sep 28 16:57:37 2014 +0200
@@ -933,7 +933,7 @@
     # readable by the user running the CGI script
     static = web.config("web", "static", None, untrusted=False)
     if not static:
-        tp = web.templatepath or templater.templatepath()
+        tp = web.templatepath or templater.templatepaths()
         if isinstance(tp, str):
             tp = [tp]
         static = [os.path.join(p, 'static') for p in tp]
--- 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]