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, fp) = templater.open_template(b"map-cmdline.default") |
|
1675 | (m, fp) = templater.try_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 |
@@ -600,9 +600,9 b' def lookuptemplate(ui, topic, tmpl):' | |||||
600 |
|
600 | |||
601 | # perhaps a stock style? |
|
601 | # perhaps a stock style? | |
602 | if not os.path.split(tmpl)[0]: |
|
602 | if not os.path.split(tmpl)[0]: | |
603 | (mapname, fp) = templater.open_template( |
|
603 | (mapname, fp) = templater.try_open_template( | |
604 | b'map-cmdline.' + tmpl |
|
604 | b'map-cmdline.' + tmpl | |
605 | ) or templater.open_template(tmpl) |
|
605 | ) or templater.try_open_template(tmpl) | |
606 | if mapname: |
|
606 | if mapname: | |
607 | return mapfile_templatespec(topic, mapname, fp) |
|
607 | return mapfile_templatespec(topic, mapname, fp) | |
608 |
|
608 |
@@ -78,7 +78,7 b' def _stylemap(styles, path=None):' | |||||
78 | locations = (os.path.join(style, b'map'), b'map-' + style, b'map') |
|
78 | locations = (os.path.join(style, b'map'), b'map-' + style, b'map') | |
79 |
|
79 | |||
80 | for location in locations: |
|
80 | for location in locations: | |
81 | mapfile, fp = templater.open_template(location, path) |
|
81 | mapfile, fp = templater.try_open_template(location, path) | |
82 | if mapfile: |
|
82 | if mapfile: | |
83 | return style, mapfile, fp |
|
83 | return style, mapfile, fp | |
84 |
|
84 |
@@ -628,9 +628,9 b' def _lookuptemplate(ui, tmpl, style):' | |||||
628 | mapfile = style |
|
628 | mapfile = style | |
629 | fp = None |
|
629 | fp = None | |
630 | if not os.path.split(mapfile)[0]: |
|
630 | if not os.path.split(mapfile)[0]: | |
631 | (mapname, fp) = templater.open_template( |
|
631 | (mapname, fp) = templater.try_open_template( | |
632 | b'map-cmdline.' + mapfile |
|
632 | b'map-cmdline.' + mapfile | |
633 | ) or templater.open_template(mapfile) |
|
633 | ) or templater.try_open_template(mapfile) | |
634 | if mapname: |
|
634 | if mapname: | |
635 | mapfile = mapname |
|
635 | mapfile = mapname | |
636 | return formatter.mapfile_templatespec(b'changeset', mapfile, fp) |
|
636 | return formatter.mapfile_templatespec(b'changeset', mapfile, fp) |
@@ -1095,17 +1095,18 b' def open_template(name, templatepath=Non' | |||||
1095 | templatepath = templatedir() |
|
1095 | templatepath = templatedir() | |
1096 | if templatepath is not None or os.path.isabs(name): |
|
1096 | if templatepath is not None or os.path.isabs(name): | |
1097 | f = os.path.join(templatepath, name) |
|
1097 | f = os.path.join(templatepath, name) | |
1098 | try: |
|
|||
1099 |
|
|
1098 | return f, open(f, mode='rb') | |
1100 | except EnvironmentError: |
|
|||
1101 | return None, None |
|
|||
1102 | else: |
|
1099 | else: | |
1103 | name_parts = pycompat.sysstr(name).split('/') |
|
1100 | name_parts = pycompat.sysstr(name).split('/') | |
1104 | package_name = '.'.join(['mercurial', 'templates'] + name_parts[:-1]) |
|
1101 | package_name = '.'.join(['mercurial', 'templates'] + name_parts[:-1]) | |
1105 | try: |
|
|||
1106 |
|
|
1102 | return ( | |
1107 |
|
|
1103 | name, | |
1108 |
|
|
1104 | resourceutil.open_resource(package_name, name_parts[-1]), | |
1109 |
|
|
1105 | ) | |
1110 | except (ImportError, OSError): |
|
1106 | ||
|
1107 | ||||
|
1108 | def try_open_template(name, templatepath=None): | |||
|
1109 | try: | |||
|
1110 | return open_template(name, templatepath) | |||
|
1111 | except (EnvironmentError, ImportError): | |||
1111 |
|
|
1112 | return None, None |
General Comments 0
You need to be logged in to leave comments.
Login now