[PATCH] Add support for template path specifications

Jonathan S. Shapiro shap at eros-os.com
Fri Aug 31 14:00:13 CDT 2007


# HG changeset patch
# User Jonathan S. Shapiro <shap at eros-os.com>
# Date 1188586404 14400
# Node ID 90d25cfc76000e40edec2cfe2fe18bf3cfe9db4c
# Parent  c36b3419c3d6b97f09d316cca05d82f1153d1a54
Add support for template path specifications.

This patch adds a new section [templatepaths] that can be used to
specify where templates are to be found.

diff -r c36b3419c3d6 -r 90d25cfc7600 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Fri Aug 31 14:31:16 2007 -0400
+++ b/mercurial/dispatch.py	Fri Aug 31 14:53:24 2007 -0400
@@ -9,6 +9,7 @@ from i18n import _
 from i18n import _
 import os, sys, atexit, signal, pdb, traceback, socket, errno, shlex, time
 import util, commands, hg, lock, fancyopts, revlog, version, extensions, hook
+import templater
 import cmdutil
 import ui as _ui
 
@@ -269,6 +270,7 @@ def _dispatch(ui, args):
         lui = _ui.ui(parentui=ui)
         lui.readconfig(os.path.join(path, ".hg", "hgrc"))
 
+    templater.load_paths(lui)
     extensions.loadall(lui)
     for name, module in extensions.extensions():
         if name in _loaded:
@@ -278,6 +280,7 @@ def _dispatch(ui, args):
         if overrides:
             ui.warn(_("extension '%s' overrides commands: %s\n")
                     % (name, " ".join(overrides)))
+
         commands.table.update(cmdtable)
         _loaded[name] = 1
     # check for fallback encoding
diff -r c36b3419c3d6 -r 90d25cfc7600 mercurial/templater.py
--- a/mercurial/templater.py	Fri Aug 31 14:31:16 2007 -0400
+++ b/mercurial/templater.py	Fri Aug 31 14:53:24 2007 -0400
@@ -8,6 +8,8 @@ from i18n import _
 from i18n import _
 from node import *
 import cgi, re, sys, os, time, urllib, util, textwrap
+
+_templatepaths = ['templates', '../templates' ]
 
 def parsestring(s, quoted=True):
     '''parse a string using simple c-like syntax.
@@ -280,6 +282,15 @@ common_filters = {
     "stringescape": lambda x: x.encode('string_escape'),
     }
 
+def load_paths(ui):
+    global _templatepaths
+    templatepath_items = ui.configitems("templatepaths")
+    for i, (name,path) in enumerate(templatepath_items):
+        if path:
+            _templatepaths.append(path)
+        else:
+            ui.warn(_("*** Malformed extpath entry %s ignored\n") % name)
+    
 def templatepath(name=None):
     '''return location of template file or directory (if no name).
     returns None if not found.'''
@@ -289,7 +300,8 @@ def templatepath(name=None):
         module = sys.executable
     else:
         module = __file__
-    for f in 'templates', '../templates':
+        
+    for f in _templatepaths:
         fl = f.split('/')
         if name: fl.append(name)
         p = os.path.join(os.path.dirname(module), *fl)


More information about the Mercurial-devel mailing list