Mercurial > hg
comparison mercurial/templater.py @ 45200:4e9b39033d3f
templater: simplify stylemap() now that templatedir() returns a single path
Differential Revision: https://phab.mercurial-scm.org/D8787
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 21 Jul 2020 13:41:26 -0700 |
parents | 91aa9bba3dc9 |
children | 8ec3062b7047 |
comparison
equal
deleted
inserted
replaced
45199:91aa9bba3dc9 | 45200:4e9b39033d3f |
---|---|
1055 if f and os.path.exists(f): | 1055 if f and os.path.exists(f): |
1056 return f | 1056 return f |
1057 return None | 1057 return None |
1058 | 1058 |
1059 | 1059 |
1060 def stylemap(styles, paths=None): | 1060 def stylemap(styles, path=None): |
1061 """Return path to mapfile for a given style. | 1061 """Return path to mapfile for a given style. |
1062 | 1062 |
1063 Searches mapfile in the following locations: | 1063 Searches mapfile in the following locations: |
1064 1. templatepath/style/map | 1064 1. templatepath/style/map |
1065 2. templatepath/map-style | 1065 2. templatepath/map-style |
1066 3. templatepath/map | 1066 3. templatepath/map |
1067 """ | 1067 """ |
1068 | 1068 |
1069 if paths is None: | 1069 if path is None: |
1070 paths = [templatedir()] | 1070 path = templatedir() |
1071 elif isinstance(paths, bytes): | |
1072 paths = [paths] | |
1073 | 1071 |
1074 if isinstance(styles, bytes): | 1072 if isinstance(styles, bytes): |
1075 styles = [styles] | 1073 styles = [styles] |
1076 | 1074 |
1077 for style in styles: | 1075 for style in styles: |
1085 ): | 1083 ): |
1086 continue | 1084 continue |
1087 locations = [os.path.join(style, b'map'), b'map-' + style] | 1085 locations = [os.path.join(style, b'map'), b'map-' + style] |
1088 locations.append(b'map') | 1086 locations.append(b'map') |
1089 | 1087 |
1090 for path in paths: | 1088 for location in locations: |
1091 for location in locations: | 1089 mapfile = os.path.join(path, location) |
1092 mapfile = os.path.join(path, location) | 1090 if os.path.isfile(mapfile): |
1093 if os.path.isfile(mapfile): | 1091 return style, mapfile |
1094 return style, mapfile | 1092 |
1095 | 1093 raise RuntimeError(b"No hgweb templates found in %r" % path) |
1096 raise RuntimeError(b"No hgweb templates found in %r" % paths) |