1048 def archivelist(ui, nodeid, url): |
1048 def archivelist(ui, nodeid, url): |
1049 for i in ['zip', 'gz', 'bz2']: |
1049 for i in ['zip', 'gz', 'bz2']: |
1050 if ui.configbool("web", "allow" + i, False): |
1050 if ui.configbool("web", "allow" + i, False): |
1051 yield {"type" : i, "node": nodeid, "url": url} |
1051 yield {"type" : i, "node": nodeid, "url": url} |
1052 |
1052 |
1053 def entries(**map): |
1053 def entries(sortcolumn="", descending=False, **map): |
|
1054 rows = [] |
1054 parity = 0 |
1055 parity = 0 |
1055 for name, path in self.repos: |
1056 for name, path in self.repos: |
1056 u = ui.ui() |
1057 u = ui.ui() |
1057 try: |
1058 try: |
1058 u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
1059 u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
1067 try: |
1068 try: |
1068 d = (get_mtime(path), util.makedate()[1]) |
1069 d = (get_mtime(path), util.makedate()[1]) |
1069 except OSError: |
1070 except OSError: |
1070 continue |
1071 continue |
1071 |
1072 |
1072 yield dict(contact=(get("ui", "username") or # preferred |
1073 contact = (get("ui", "username") or # preferred |
1073 get("web", "contact") or # deprecated |
1074 get("web", "contact") or # deprecated |
1074 get("web", "author", "unknown")), # also |
1075 get("web", "author", "")) # also |
1075 name=get("web", "name", name), |
1076 description = get("web", "description", "") |
|
1077 name = get("web", "name", name) |
|
1078 row = dict(contact=contact or "unknown", |
|
1079 contact_sort=contact.upper() or "unknown", |
|
1080 name=name, |
|
1081 name_sort=name.upper(), |
1076 url=url, |
1082 url=url, |
1077 parity=parity, |
1083 description=description or "unknown", |
1078 shortdesc=get("web", "description", "unknown"), |
1084 description_sort=description.upper() or "unknown", |
1079 lastupdate=d, |
1085 lastchange=d, |
|
1086 lastchange_sort=d[1]-d[0], |
1080 archives=archivelist(u, "tip", url)) |
1087 archives=archivelist(u, "tip", url)) |
1081 |
1088 if not sortcolumn: |
1082 parity = 1 - parity |
1089 # fast path for unsorted output |
|
1090 row['parity'] = parity |
|
1091 parity = 1 - parity |
|
1092 yield row |
|
1093 else: |
|
1094 rows.append((row["%s_sort" % sortcolumn], row)) |
|
1095 if rows: |
|
1096 rows.sort() |
|
1097 if descending: |
|
1098 rows.reverse() |
|
1099 for key, row in rows: |
|
1100 row['parity'] = parity |
|
1101 parity = 1 - parity |
|
1102 yield row |
1083 |
1103 |
1084 virtual = req.env.get("PATH_INFO", "").strip('/') |
1104 virtual = req.env.get("PATH_INFO", "").strip('/') |
1085 if virtual: |
1105 if virtual: |
1086 real = dict(self.repos).get(virtual) |
1106 real = dict(self.repos).get(virtual) |
1087 if real: |
1107 if real: |
1098 static = os.path.join(templater.templatepath(), "static") |
1118 static = os.path.join(templater.templatepath(), "static") |
1099 fname = req.form['static'][0] |
1119 fname = req.form['static'][0] |
1100 req.write(staticfile(static, fname) |
1120 req.write(staticfile(static, fname) |
1101 or tmpl("error", error="%r not found" % fname)) |
1121 or tmpl("error", error="%r not found" % fname)) |
1102 else: |
1122 else: |
1103 req.write(tmpl("index", entries=entries)) |
1123 sortable = ["name", "description", "contact", "lastchange"] |
|
1124 sortcolumn = "" |
|
1125 if req.form.has_key('sort'): |
|
1126 sortcolumn = req.form['sort'][0] |
|
1127 descending = sortcolumn.startswith('-') |
|
1128 if descending: |
|
1129 sortcolumn = sortcolumn[1:] |
|
1130 if sortcolumn not in sortable: |
|
1131 sortcolumn = "" |
|
1132 |
|
1133 sort = [("sort_%s" % column, |
|
1134 "%s%s" % ((not descending and column == sortcolumn) |
|
1135 and "-" or "", column)) |
|
1136 for column in sortable] |
|
1137 req.write(tmpl("index", entries=entries, |
|
1138 sortcolumn=sortcolumn, descending=descending, |
|
1139 **dict(sort))) |