##// END OF EJS Templates
templater: handle None returned from templatedir()...
Martin von Zweigbergk -
r45773:d5ccc059 default
parent child Browse files
Show More
@@ -1669,7 +1669,7 b' def debuginstall(ui, **opts):'
1669
1669
1670 # templates
1670 # templates
1671 p = templater.templatedir()
1671 p = templater.templatedir()
1672 fm.write(b'templatedirs', b'checking templates (%s)...\n', p)
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 = templater.templatepath(b"map-cmdline.default")
@@ -415,7 +415,8 b' class hgwebdir(object):'
415 static = self.ui.config(b"web", b"static", untrusted=False)
415 static = self.ui.config(b"web", b"static", untrusted=False)
416 if not static:
416 if not static:
417 tp = self.templatepath or templater.templatedir()
417 tp = self.templatepath or templater.templatedir()
418 static = [os.path.join(tp, b'static')]
418 if tp is not None:
419 static = [os.path.join(tp, b'static')]
419
420
420 staticfile(static, fname, res)
421 staticfile(static, fname, res)
421 return res.sendresponse()
422 return res.sendresponse()
@@ -828,6 +828,8 b' def _readmapfile(mapfile):'
828 def include(rel, abs, remap, sections):
828 def include(rel, abs, remap, sections):
829 templatedirs = [base, templatedir()]
829 templatedirs = [base, templatedir()]
830 for dir in templatedirs:
830 for dir in templatedirs:
831 if dir is None:
832 continue
831 abs = os.path.normpath(os.path.join(dir, rel))
833 abs = os.path.normpath(os.path.join(dir, rel))
832 if os.path.isfile(abs):
834 if os.path.isfile(abs):
833 data = util.posixfile(abs, b'rb').read()
835 data = util.posixfile(abs, b'rb').read()
@@ -850,13 +852,15 b' def _readmapfile(mapfile):'
850
852
851 # fallback check in template paths
853 # fallback check in template paths
852 if not os.path.exists(path):
854 if not os.path.exists(path):
853 p2 = util.normpath(os.path.join(templatedir(), val))
855 dir = templatedir()
854 if os.path.isfile(p2):
856 if dir is not None:
855 path = p2
857 p2 = util.normpath(os.path.join(dir, val))
856 else:
858 if os.path.isfile(p2):
857 p3 = util.normpath(os.path.join(p2, b"map"))
859 path = p2
858 if os.path.isfile(p3):
860 else:
859 path = p3
861 p3 = util.normpath(os.path.join(p2, b"map"))
862 if os.path.isfile(p3):
863 path = p3
860
864
861 cache, tmap, aliases = _readmapfile(path)
865 cache, tmap, aliases = _readmapfile(path)
862
866
@@ -1064,6 +1068,9 b' def templatedir():'
1064
1068
1065 def templatepath(name):
1069 def templatepath(name):
1066 '''return location of template file. returns None if not found.'''
1070 '''return location of template file. returns None if not found.'''
1071 dir = templatedir()
1072 if dir is None:
1073 return None
1067 f = os.path.join(templatedir(), name)
1074 f = os.path.join(templatedir(), name)
1068 if f and os.path.exists(f):
1075 if f and os.path.exists(f):
1069 return f
1076 return f
@@ -1085,22 +1092,23 b' def stylemap(styles, path=None):'
1085 if isinstance(styles, bytes):
1092 if isinstance(styles, bytes):
1086 styles = [styles]
1093 styles = [styles]
1087
1094
1088 for style in styles:
1095 if path is not None:
1089 # only plain name is allowed to honor template paths
1096 for style in styles:
1090 if (
1097 # only plain name is allowed to honor template paths
1091 not style
1098 if (
1092 or style in (pycompat.oscurdir, pycompat.ospardir)
1099 not style
1093 or pycompat.ossep in style
1100 or style in (pycompat.oscurdir, pycompat.ospardir)
1094 or pycompat.osaltsep
1101 or pycompat.ossep in style
1095 and pycompat.osaltsep in style
1102 or pycompat.osaltsep
1096 ):
1103 and pycompat.osaltsep in style
1097 continue
1104 ):
1098 locations = [os.path.join(style, b'map'), b'map-' + style]
1105 continue
1099 locations.append(b'map')
1106 locations = [os.path.join(style, b'map'), b'map-' + style]
1107 locations.append(b'map')
1100
1108
1101 for location in locations:
1109 for location in locations:
1102 mapfile = os.path.join(path, location)
1110 mapfile = os.path.join(path, location)
1103 if os.path.isfile(mapfile):
1111 if os.path.isfile(mapfile):
1104 return style, mapfile
1112 return style, mapfile
1105
1113
1106 raise RuntimeError(b"No hgweb templates found in %r" % path)
1114 raise RuntimeError(b"No hgweb templates found in %r" % path)
General Comments 0
You need to be logged in to leave comments. Login now