Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/common.py @ 7966:aa983c3d94a9
templater: move stylemap function from hgweb to templater
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Sat, 04 Apr 2009 17:46:11 +0200 |
parents | a3d7f99c23c0 |
children | 46293a0c7e9f |
comparison
equal
deleted
inserted
replaced
7965:8503adbd9d49 | 7966:aa983c3d94a9 |
---|---|
76 if err.errno == errno.ENOENT: | 76 if err.errno == errno.ENOENT: |
77 raise ErrorResponse(HTTP_NOT_FOUND) | 77 raise ErrorResponse(HTTP_NOT_FOUND) |
78 else: | 78 else: |
79 raise ErrorResponse(HTTP_SERVER_ERROR, err.strerror) | 79 raise ErrorResponse(HTTP_SERVER_ERROR, err.strerror) |
80 | 80 |
81 def style_map(templatepath, style): | |
82 """Return path to mapfile for a given style. | |
83 | |
84 Searches mapfile in the following locations: | |
85 1. templatepath/style/map | |
86 2. templatepath/map-style | |
87 3. templatepath/map | |
88 """ | |
89 locations = style and [os.path.join(style, "map"), "map-"+style] or [] | |
90 locations.append("map") | |
91 if isinstance(templatepath, str): | |
92 templatepath = [templatepath] | |
93 for path in templatepath: | |
94 for location in locations: | |
95 mapfile = os.path.join(path, location) | |
96 if os.path.isfile(mapfile): | |
97 return mapfile | |
98 raise RuntimeError("No hgweb templates found in %r" % templatepath) | |
99 | |
100 def paritygen(stripecount, offset=0): | 81 def paritygen(stripecount, offset=0): |
101 """count parity of horizontal stripes for easier reading""" | 82 """count parity of horizontal stripes for easier reading""" |
102 if stripecount and offset: | 83 if stripecount and offset: |
103 # account for offset, e.g. due to building the list in reverse | 84 # account for offset, e.g. due to building the list in reverse |
104 count = (stripecount + offset) % stripecount | 85 count = (stripecount + offset) % stripecount |