[Updated] D8905: templater: add exception-raising version of open_template()
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Fri Aug 7 00:35:17 UTC 2020
Closed by commit rHG4aa484efc926: templater: add exception-raising version of open_template() (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D8905?vs=22315&id=22319
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D8905/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D8905
AFFECTED FILES
mercurial/debugcommands.py
mercurial/formatter.py
mercurial/hgweb/hgweb_mod.py
mercurial/logcmdutil.py
mercurial/templater.py
CHANGE DETAILS
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -1095,17 +1095,18 @@
templatepath = templatedir()
if templatepath is not None or os.path.isabs(name):
f = os.path.join(templatepath, name)
- try:
- return f, open(f, mode='rb')
- except EnvironmentError:
- return None, None
+ return f, open(f, mode='rb')
else:
name_parts = pycompat.sysstr(name).split('/')
package_name = '.'.join(['mercurial', 'templates'] + name_parts[:-1])
- try:
- return (
- name,
- resourceutil.open_resource(package_name, name_parts[-1]),
- )
- except (ImportError, OSError):
- return None, None
+ return (
+ name,
+ resourceutil.open_resource(package_name, name_parts[-1]),
+ )
+
+
+def try_open_template(name, templatepath=None):
+ try:
+ return open_template(name, templatepath)
+ except (EnvironmentError, ImportError):
+ return None, None
diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -628,9 +628,9 @@
mapfile = style
fp = None
if not os.path.split(mapfile)[0]:
- (mapname, fp) = templater.open_template(
+ (mapname, fp) = templater.try_open_template(
b'map-cmdline.' + mapfile
- ) or templater.open_template(mapfile)
+ ) or templater.try_open_template(mapfile)
if mapname:
mapfile = mapname
return formatter.mapfile_templatespec(b'changeset', mapfile, fp)
diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -78,7 +78,7 @@
locations = (os.path.join(style, b'map'), b'map-' + style, b'map')
for location in locations:
- mapfile, fp = templater.open_template(location, path)
+ mapfile, fp = templater.try_open_template(location, path)
if mapfile:
return style, mapfile, fp
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -600,9 +600,9 @@
# perhaps a stock style?
if not os.path.split(tmpl)[0]:
- (mapname, fp) = templater.open_template(
+ (mapname, fp) = templater.try_open_template(
b'map-cmdline.' + tmpl
- ) or templater.open_template(tmpl)
+ ) or templater.try_open_template(tmpl)
if mapname:
return mapfile_templatespec(topic, mapname, fp)
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1672,7 +1672,7 @@
fm.write(b'templatedirs', b'checking templates (%s)...\n', p or b'')
fm.condwrite(not p, b'', _(b" no template directories found\n"))
if p:
- (m, fp) = templater.open_template(b"map-cmdline.default")
+ (m, fp) = templater.try_open_template(b"map-cmdline.default")
if m:
# template found, check if it is working
err = None
To: martinvonz, #hg-reviewers, indygreg
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200807/801db406/attachment-0002.html>
More information about the Mercurial-patches
mailing list