##// END OF EJS Templates
templater: replace templatepath() with function that also opens the file...
Martin von Zweigbergk -
r45869:65a812ed default
parent child Browse files
Show More
@@ -1672,7 +1672,7 b' def debuginstall(ui, **opts):'
1672 fm.write(b'templatedirs', b'checking templates (%s)...\n', p or b'')
1672 fm.write(b'templatedirs', b'checking templates (%s)...\n', p or b'')
1673 fm.condwrite(not p, b'', _(b" no template directories found\n"))
1673 fm.condwrite(not p, b'', _(b" no template directories found\n"))
1674 if p:
1674 if p:
1675 m = templater.templatepath(b"map-cmdline.default")
1675 (m, fp) = templater.open_template(b"map-cmdline.default")
1676 if m:
1676 if m:
1677 # template found, check if it is working
1677 # template found, check if it is working
1678 err = None
1678 err = None
@@ -599,9 +599,9 b' def lookuptemplate(ui, topic, tmpl):'
599
599
600 # perhaps a stock style?
600 # perhaps a stock style?
601 if not os.path.split(tmpl)[0]:
601 if not os.path.split(tmpl)[0]:
602 mapname = templater.templatepath(
602 (mapname, fp) = templater.open_template(
603 b'map-cmdline.' + tmpl
603 b'map-cmdline.' + tmpl
604 ) or templater.templatepath(tmpl)
604 ) or templater.open_template(tmpl)
605 if mapname:
605 if mapname:
606 return mapfile_templatespec(topic, mapname)
606 return mapfile_templatespec(topic, mapname)
607
607
@@ -627,9 +627,9 b' def _lookuptemplate(ui, tmpl, style):'
627 if not tmpl and style:
627 if not tmpl and style:
628 mapfile = style
628 mapfile = style
629 if not os.path.split(mapfile)[0]:
629 if not os.path.split(mapfile)[0]:
630 mapname = templater.templatepath(
630 (mapname, fp) = templater.open_template(
631 b'map-cmdline.' + mapfile
631 b'map-cmdline.' + mapfile
632 ) or templater.templatepath(mapfile)
632 ) or templater.open_template(mapfile)
633 if mapname:
633 if mapname:
634 mapfile = mapname
634 mapfile = mapname
635 return formatter.mapfile_templatespec(b'changeset', mapfile)
635 return formatter.mapfile_templatespec(b'changeset', mapfile)
@@ -1071,12 +1071,15 b' def templatedir():'
1071 return path if os.path.isdir(path) else None
1071 return path if os.path.isdir(path) else None
1072
1072
1073
1073
1074 def templatepath(name):
1074 def open_template(name):
1075 '''return location of template file. returns None if not found.'''
1075 '''returns a file-like object for the given template, and its full path'''
1076 dir = templatedir()
1076 templatepath = templatedir()
1077 if dir is None:
1077 if templatepath is not None or os.path.isabs(name):
1078 return None
1078 f = os.path.join(templatepath, name)
1079 f = os.path.join(templatedir(), name)
1079 try:
1080 if f and os.path.isfile(f):
1080 return f, open(f, mode='rb')
1081 return f
1081 except EnvironmentError:
1082 return None
1082 return None, None
1083 else:
1084 # TODO: read from resources here
1085 return None, None
General Comments 0
You need to be logged in to leave comments. Login now