[PATCH 3 of 7] templater: introduce templatepaths for getting paths searched for templates
Mads Kiilerich
mads at kiilerich.com
Sun Sep 28 10:03:00 CDT 2014
# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1411916257 -7200
# Sun Sep 28 16:57:37 2014 +0200
# Node ID 6bdef4ab93246c687a4811b7bf496ae90f19ef43
# Parent da31d28c71a46741a8f1d28785859ffb91f6a026
templater: introduce templatepaths for getting paths searched for templates
Avoid function with different return types depending on parameters.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2256,7 +2256,7 @@ def debuginstall(ui):
# 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")
diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -193,7 +193,7 @@ class hgwebdir(object):
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]
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -933,7 +933,7 @@ def static(web, req, tmpl):
# 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]
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -625,7 +625,7 @@ class engine(object):
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 @@ class templater(object):
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 @@ def stylemap(styles, paths=None):
"""
if paths is None:
- paths = templatepath()
+ paths = templatepaths()
elif isinstance(paths, str):
paths = [paths]
More information about the Mercurial-devel
mailing list