comparison mercurial/templater.py @ 8194:63c47e4ac617

templater: use new config parser This gives us the ability to use includes and continuations
author Matt Mackall <mpm@selenic.com>
date Sun, 26 Apr 2009 16:50:43 -0500
parents b5db7dcc1497
children cf9accffd0b3
comparison
equal deleted inserted replaced
8193:94246e90081e 8194:63c47e4ac617
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 from i18n import _ 8 from i18n import _
9 import re, sys, os 9 import re, sys, os
10 from mercurial import util 10 from mercurial import util, config
11 11
12 path = ['templates', '../templates'] 12 path = ['templates', '../templates']
13 13
14 def parsestring(s, quoted=True): 14 def parsestring(s, quoted=True):
15 '''parse a string using simple c-like syntax. 15 '''parse a string using simple c-like syntax.
61 if not mapfile: 61 if not mapfile:
62 return 62 return
63 if not os.path.exists(mapfile): 63 if not os.path.exists(mapfile):
64 raise util.Abort(_('style not found: %s') % mapfile) 64 raise util.Abort(_('style not found: %s') % mapfile)
65 65
66 i = 0 66 conf = config.config()
67 for l in file(mapfile): 67 conf.read(mapfile)
68 l = l.strip() 68
69 i += 1 69 for key, val in conf[''].items():
70 if not l or l[0] in '#;': continue 70 if val[0] in "'\"":
71 m = re.match(r'([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(.+)$', l) 71 try:
72 if m: 72 self.cache[key] = parsestring(val)
73 key, val = m.groups() 73 except SyntaxError, inst:
74 if val[0] in "'\"": 74 raise SyntaxError('%s: %s' %
75 try: 75 (conf.getsource('', key), inst.args[0]))
76 self.cache[key] = parsestring(val) 76 else:
77 except SyntaxError, inst: 77 self.map[key] = os.path.join(self.base, val)
78 raise SyntaxError('%s:%s: %s' %
79 (mapfile, i, inst.args[0]))
80 else:
81 self.map[key] = os.path.join(self.base, val)
82 else:
83 raise SyntaxError(_("%s:%s: parse error") % (mapfile, i))
84 78
85 def __contains__(self, key): 79 def __contains__(self, key):
86 return key in self.cache or key in self.map 80 return key in self.cache or key in self.map
87 81
88 def _template(self, t): 82 def _template(self, t):