Mercurial > hg
diff mercurial/hgweb.py @ 981:4f81068ed8cd
Merge with jeffpc
author | mpm@selenic.com |
---|---|
date | Sat, 20 Aug 2005 13:08:07 -0700 |
parents | 3f37720e7dc7 5197fb9d65d5 |
children | 8d2e24bae760 |
line wrap: on
line diff
--- a/mercurial/hgweb.py Sat Aug 20 11:59:10 2005 -0700 +++ b/mercurial/hgweb.py Sat Aug 20 13:08:07 2005 -0700 @@ -64,25 +64,6 @@ else: sys.stdout.write(str(thing)) -def template(tmpl, filters = {}, **map): - while tmpl: - m = re.search(r"#([a-zA-Z0-9]+)((\|[a-zA-Z0-9]+)*)#", tmpl) - if m: - yield tmpl[:m.start(0)] - v = map.get(m.group(1), "") - v = callable(v) and v(**map) or v - - fl = m.group(2) - if fl: - for f in fl.split("|")[1:]: - v = filters[f](v) - - yield v - tmpl = tmpl[m.end(0):] - else: - yield tmpl - return - class templater: def __init__(self, mapfile, filters = {}, defaults = {}): self.cache = {} @@ -109,7 +90,37 @@ tmpl = self.cache[t] except KeyError: tmpl = self.cache[t] = file(self.map[t]).read() - return template(tmpl, self.filters, **m) + return self.template(tmpl, self.filters, **m) + + def template(self, tmpl, filters = {}, **map): + while tmpl: + m = re.search(r"#([a-zA-Z0-9]+)((%[a-zA-Z0-9]+)*)((\|[a-zA-Z0-9]+)*)#", tmpl) + if m: + yield tmpl[:m.start(0)] + v = map.get(m.group(1), "") + v = callable(v) and v(**map) or v + + format = m.group(2) + fl = m.group(4) + + if format: + q = v.__iter__ + for i in q(): + lm = map.copy() + lm.update(i) + yield self(format[1:], **lm) + + v = "" + + elif fl: + for f in fl.split("|")[1:]: + v = filters[f](v) + + yield v + tmpl = tmpl[m.end(0):] + else: + yield tmpl + return def rfc822date(x): return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x)) @@ -242,12 +253,12 @@ if pos + f < count: l.append(("+" + r, pos + f)) if pos - f >= 0: l.insert(0, ("-" + r, pos - f)) - yield self.t("naventry", rev = 0, label="(0)") + yield {"rev": 0, "label": "(0)"} for label, rev in l: - yield self.t("naventry", label = label, rev = rev) + yield {"label": label, "rev": rev} - yield self.t("naventry", label="tip") + yield {"label": "tip", "rev": ""} def changelist(**map): parity = (start - end) & 1 @@ -259,22 +270,21 @@ hn = hex(n) t = float(changes[2].split(' ')[0]) - l.insert(0, self.t( - 'changelogentry', - parity = parity, - author = changes[1], - parent = self.parents("changelogparent", + l.insert(0, { + "parity": parity, + "author": changes[1], + "parent": self.parents("changelogparent", cl.parents(n), cl.rev), - changelogtag = self.showtag("changelogtag",n), - manifest = hex(changes[0]), - desc = changes[4], - date = t, - files = self.listfilediffs(changes[3], n), - rev = i, - node = hn)) + "changelogtag": self.showtag("changelogtag",n), + "manifest": hex(changes[0]), + "desc": changes[4], + "date": t, + "files": self.listfilediffs(changes[3], n), + "rev": i, + "node": hn}) parity = 1 - parity - yield l + for e in l: yield e cl = self.repo.changelog mf = cl.read(cl.tip())[0] @@ -389,20 +399,19 @@ cs = cl.read(cl.node(lr)) t = float(cs[2].split(' ')[0]) - l.insert(0, self.t("filelogentry", - parity = parity, - filenode = hex(n), - filerev = i, - file = f, - node = hex(cn), - author = cs[1], - date = t, - parent = self.parents("filelogparent", + l.insert(0, {"parity": parity, + "filenode": hex(n), + "filerev": i, + "file": f, + "node": hex(cn), + "author": cs[1], + "date": t, + "parent": self.parents("filelogparent", fl.parents(n), fl.rev, file=f), - desc = cs[4])) + "desc": cs[4]}) parity = 1 - parity - yield l + for e in l: yield e yield self.t("filelog", file = f, @@ -422,9 +431,9 @@ def lines(): for l, t in enumerate(text.splitlines(1)): - yield self.t("fileline", line = t, - linenumber = "% 6d" % (l + 1), - parity = l & 1) + yield {"line": t, + "linenumber": "% 6d" % (l + 1), + "parity": l & 1} yield self.t("filerevision", file = f, filenode = node, @@ -478,13 +487,12 @@ parity = 1 - parity last = cnode - yield self.t("annotateline", - parity = parity, - node = hex(cnode), - rev = r, - author = name, - file = f, - line = l) + yield {"parity": parity, + "node": hex(cnode), + "rev": r, + "author": name, + "file": f, + "line": l} yield self.t("fileannotate", file = f, @@ -528,28 +536,40 @@ fl.sort() for f in fl: full, fnode = files[f] - if fnode: - yield self.t("manifestfileentry", - file = full, - manifest = mnode, - filenode = hex(fnode), - parity = parity, - basename = f, - permissions = mff[full]) - else: - yield self.t("manifestdirentry", - parity = parity, - path = os.path.join(path, f), - manifest = mnode, basename = f[:-1]) + if not fnode: + continue + + yield {"file": full, + "manifest": mnode, + "filenode": hex(fnode), + "parity": parity, + "basename": f, + "permissions": mff[full]} parity = 1 - parity + def dirlist(**map): + parity = 0 + fl = files.keys() + fl.sort() + for f in fl: + full, fnode = files[f] + if fnode: + continue + + yield {"parity": parity, + "path": os.path.join(path, f), + "manifest": mnode, + "basename": f[:-1]} + parity = 1 - parity + yield self.t("manifest", manifest = mnode, rev = rev, node = hex(node), path = path, up = up(path), - entries = filelist) + fentries = filelist, + dentries = dirlist) def tags(self): cl = self.repo.changelog @@ -561,10 +581,9 @@ def entries(**map): parity = 0 for k,n in i: - yield self.t("tagentry", - parity = parity, - tag = k, - node = hex(n)) + yield {"parity": parity, + "tag": k, + "node": hex(n)} parity = 1 - parity yield self.t("tags",