Changeset 7ccfe44 in trunk
- Timestamp:
- 2019-12-21T10:56:13Z (5 years ago)
- Branches:
- master
- Children:
- 3099b18
- Parents:
- 4a73f80
- git-author:
- meejah <meejah@…> (2019-11-05 06:38:43)
- git-committer:
- meejah <meejah@…> (2019-12-21 10:56:13)
- Location:
- src/allmydata/web
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/web/directory.py ¶
r4a73f80 r7ccfe44 966 966 return ctx.tag 967 967 968 class ManifestResults(MultiFormatPage, ReloadMixin): 969 docFactory = getxmlfile("manifest.xhtml") 968 969 class ReloadableMonitorElement(Element, object): 970 """ 971 Like 'ReloadMixin', but for twisted.web.template style. This 972 provides renderers for "reload" and "refesh" and a self.monitor 973 attribute 974 """ 975 refresh_time = 60 # 1 minute 976 977 def __init__(self, monitor): 978 self.monitor = monitor 979 super(ReloadableMonitorElement, self).__init__() 980 981 @renderer 982 def refresh(self, req, tag): 983 if self.monitor.is_finished(): 984 return "" 985 tag.attributes["http-equiv"] = "refresh" 986 tag.attributes["content"] = str(self.refresh_time) 987 return tag 988 989 @renderer 990 def reload(self, req, tag): 991 if self.monitor.is_finished(): 992 return "" 993 # url.gethere would break a proxy, so the correct thing to do is 994 # req.path[-1] + queryargs 995 ophandle = req.prepath[-1] 996 reload_target = ophandle + "?output=html" 997 cancel_target = ophandle + "?t=cancel" 998 cancel_button = tags.form( 999 [ 1000 tags.input(type="submit", value="Cancel"), 1001 ], 1002 action=cancel_target, 1003 method="POST", 1004 enctype="multipart/form-data", 1005 ) 1006 1007 return tag([ 1008 "Operation still running: ", 1009 tags.a("Reload", href=reload_target), 1010 cancel_button, 1011 ]) 1012 1013 1014 def _slashify_path(path): 1015 """ 1016 Converts a tuple from a 'manifest' path into a string with slashes 1017 in it 1018 """ 1019 if not path: 1020 return "" 1021 return "/".join([p.encode("utf-8") for p in path]) 1022 1023 1024 def _cap_to_link(root, path, cap): 1025 """ 1026 Turns a capability-string into a WebAPI link tag 1027 1028 :param root: the root piece of the URI 1029 1030 :param cap: the capability-string 1031 1032 :returns: tags.a instance 1033 """ 1034 # TODO: we need a clean consistent way to get the type of a cap string 1035 if cap: 1036 if cap.startswith("URI:CHK") or cap.startswith("URI:SSK"): 1037 nameurl = urllib.quote(path[-1].encode("utf-8")) 1038 uri_link = "%s/file/%s/@@named=/%s" % (root, urllib.quote(cap), 1039 nameurl) 1040 else: 1041 uri_link = "%s/uri/%s" % (root, urllib.quote(cap, safe="")) 1042 return tags.a(cap, href=uri_link) 1043 else: 1044 return "" 1045 1046 1047 class ManifestElement(ReloadableMonitorElement): 1048 loader = XMLFile(FilePath(__file__).sibling("manifest.xhtml")) 1049 1050 def _si_abbrev(self): 1051 si = self.monitor.origin_si 1052 if not si: 1053 return "<LIT>" 1054 return base32.b2a(si)[:6] 1055 1056 @renderer 1057 def title(self, req, tag): 1058 return tag( 1059 "Manifest of SI={}".format(self._si_abbrev()) 1060 ) 1061 1062 @renderer 1063 def header(self, req, tag): 1064 return tag( 1065 "Manifest of SI={}".format(self._si_abbrev()) 1066 ) 1067 1068 @renderer 1069 def items(self, req, tag): 1070 manifest = self.monitor.get_status()["manifest"] 1071 root = get_root(req) 1072 rows = [ 1073 { 1074 "path": _slashify_path(path), 1075 "cap": _cap_to_link(root, path, cap), 1076 } 1077 for path, cap in manifest 1078 ] 1079 return SlotsSequenceElement(tag, rows) 1080 1081 1082 class ManifestResults(MultiFormatResource, ReloadMixin): 970 1083 971 1084 # Control MultiFormatPage … … 980 1093 render_HTML = None 981 1094 982 def slashify_path(self, path): 983 if not path: 984 return "" 985 return "/".join([p.encode("utf-8") for p in path]) 1095 def render_HTML(self, req): 1096 return renderElement( 1097 req, 1098 ManifestElement(self.monitor) 1099 ) 986 1100 987 1101 def render_TEXT(self, req): … … 990 1104 is_finished = self.monitor.is_finished() 991 1105 lines.append("finished: " + {True: "yes", False: "no"}[is_finished]) 992 for (path, cap)in self.monitor.get_status()["manifest"]:993 lines.append( self.slashify_path(path) + " " + cap)1106 for path, cap in self.monitor.get_status()["manifest"]: 1107 lines.append(_slashify_path(path) + " " + cap) 994 1108 return "\n".join(lines) + "\n" 995 1109 … … 1025 1139 return json.dumps(status, indent=1) 1026 1140 1027 def _si_abbrev(self):1028 si = self.monitor.origin_si1029 if not si:1030 return "<LIT>"1031 return base32.b2a(si)[:6]1032 1033 def render_title(self, ctx):1034 return T.title["Manifest of SI=%s" % self._si_abbrev()]1035 1036 def render_header(self, ctx):1037 return T.p["Manifest of SI=%s" % self._si_abbrev()]1038 1039 def data_items(self, ctx, data):1040 return self.monitor.get_status()["manifest"]1041 1042 def render_row(self, ctx, path_cap):1043 path, cap = path_cap1044 ctx.fillSlots("path", self.slashify_path(path))1045 root = get_root(ctx)1046 # TODO: we need a clean consistent way to get the type of a cap string1047 if cap:1048 if cap.startswith("URI:CHK") or cap.startswith("URI:SSK"):1049 nameurl = urllib.quote(path[-1].encode("utf-8"))1050 uri_link = "%s/file/%s/@@named=/%s" % (root, urllib.quote(cap),1051 nameurl)1052 else:1053 uri_link = "%s/uri/%s" % (root, urllib.quote(cap, safe=""))1054 ctx.fillSlots("cap", T.a(href=uri_link)[cap])1055 else:1056 ctx.fillSlots("cap", "")1057 return ctx.tag1058 1141 1059 1142 class DeepSizeResults(MultiFormatPage): -
TabularUnified src/allmydata/web/manifest.xhtml ¶
r4a73f80 r7ccfe44 1 <html xmlns: n="http://nevow.com/ns/nevow/0.1">1 <html xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"> 2 2 <head> 3 <title n:render="title"></title>3 <title t:render="title"></title> 4 4 <link href="/tahoe.css" rel="stylesheet" type="text/css"/> 5 5 <link href="/icon.png" rel="shortcut icon" /> 6 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 7 <meta n:render="refresh" />7 <meta t:render="refresh" /> 8 8 </head> 9 9 <body> 10 10 11 <h1><p n:render="header"></p></h1>11 <h1><p t:render="header"></p></h1> 12 12 13 <h2 n:render="reload" />13 <h2 t:render="reload" /> 14 14 15 <table n:render="sequence" n:data="items">16 <tr n:pattern="header">15 <table t:render="items"> 16 <tr t:pattern="header"> 17 17 <td>Path</td> 18 18 <td>cap</td> 19 19 </tr> 20 <tr n:pattern="item" n:render="row">21 <td>< n:slot name="path"/></td>22 <td>< n:slot name="cap"/></td>20 <tr t:render="item"> 21 <td><t:slot name="path"/></td> 22 <td><t:slot name="cap"/></td> 23 23 </tr> 24 24 25 <tr n:pattern="empty"><td>no items in the manifest!</td></tr>25 <tr t:render="empty"><td>no items in the manifest!</td></tr> 26 26 27 27 </table>
Note: See TracChangeset
for help on using the changeset viewer.