comparison mercurial/hgweb/hgweb_mod.py @ 45339:1a4f925f72c3

hgweb: enable reading styles from resources in frozen binaries All we need to do to read styles from resources is to pass the file-like object we get from `open_template()` on to `frommapfile()`. This takes the number of failing tests with PyOxidizer from 62 to 54. Differential Revision: https://phab.mercurial-scm.org/D8901
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 05 Aug 2020 14:19:42 -0700
parents c37ab438ff31
children 4aa484efc926
comparison
equal deleted inserted replaced
45338:c37ab438ff31 45339:1a4f925f72c3
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.open_template(location, path)
82 if mapfile: 82 if mapfile:
83 return style, mapfile 83 return style, mapfile, fp
84 84
85 raise RuntimeError(b"No hgweb templates found in %r" % path) 85 raise RuntimeError(b"No hgweb templates found in %r" % path)
86 86
87 87
88 def makebreadcrumb(url, prefix=b''): 88 def makebreadcrumb(url, prefix=b''):
178 staticurl += b'/' 178 staticurl += b'/'
179 179
180 # figure out which style to use 180 # figure out which style to use
181 181
182 vars = {} 182 vars = {}
183 styles, (style, mapfile) = getstyle(req, self.config, self.templatepath) 183 styles, (style, mapfile, fp) = getstyle(
184 req, self.config, self.templatepath
185 )
184 if style == styles[0]: 186 if style == styles[0]:
185 vars[b'style'] = style 187 vars[b'style'] = style
186 188
187 sessionvars = webutil.sessionvars(vars, b'?') 189 sessionvars = webutil.sessionvars(vars, b'?')
188 190
221 @templatekeyword(b'motd', requires=()) 223 @templatekeyword(b'motd', requires=())
222 def motd(context, mapping): 224 def motd(context, mapping):
223 yield self.config(b'web', b'motd') 225 yield self.config(b'web', b'motd')
224 226
225 tres = formatter.templateresources(self.repo.ui, self.repo) 227 tres = formatter.templateresources(self.repo.ui, self.repo)
226 tmpl = templater.templater.frommapfile( 228 return templater.templater.frommapfile(
227 mapfile, filters=filters, defaults=defaults, resources=tres 229 mapfile, fp=fp, filters=filters, defaults=defaults, resources=tres
228 ) 230 )
229 return tmpl
230 231
231 def sendtemplate(self, name, **kwargs): 232 def sendtemplate(self, name, **kwargs):
232 """Helper function to send a response generated from a template.""" 233 """Helper function to send a response generated from a template."""
233 kwargs = pycompat.byteskwargs(kwargs) 234 kwargs = pycompat.byteskwargs(kwargs)
234 self.res.setbodygen(self.tmpl.generate(name, kwargs)) 235 self.res.setbodygen(self.tmpl.generate(name, kwargs))