changeset 45337:1b983985edd9

hgweb: open mapfile using templater.open_template() This will help us read templates from resources in frozen binaries. Differential Revision: https://phab.mercurial-scm.org/D8899
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 05 Aug 2020 14:03:14 -0700
parents 2901133ec982
children c37ab438ff31
files mercurial/hgweb/hgweb_mod.py mercurial/templater.py
diffstat 2 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Wed Aug 05 13:58:30 2020 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Wed Aug 05 14:03:14 2020 -0700
@@ -82,8 +82,8 @@
             locations = (os.path.join(style, b'map'), b'map-' + style, b'map')
 
             for location in locations:
-                mapfile = os.path.join(path, location)
-                if os.path.isfile(mapfile):
+                mapfile, fp = templater.open_template(location, path)
+                if mapfile:
                     return style, mapfile
 
     raise RuntimeError(b"No hgweb templates found in %r" % path)
--- a/mercurial/templater.py	Wed Aug 05 13:58:30 2020 -0700
+++ b/mercurial/templater.py	Wed Aug 05 14:03:14 2020 -0700
@@ -1084,14 +1084,15 @@
     return path if os.path.isdir(path) else None
 
 
-def open_template(name):
+def open_template(name, templatepath=None):
     '''returns a file-like object for the given template, and its full path
 
     If the name is a relative path and we're in a frozen binary, the template
     will be read from the mercurial.templates package instead. The returned path
     will then be the relative path.
     '''
-    templatepath = templatedir()
+    if templatepath is None:
+        templatepath = templatedir()
     if templatepath is not None or os.path.isabs(name):
         f = os.path.join(templatepath, name)
         try: