Changeset 7ccfe44 in trunk


Ignore:
Timestamp:
2019-12-21T10:56:13Z (5 years ago)
Author:
meejah <meejah@…>
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)
Message:

port manifest to twisted.web.template

Location:
src/allmydata/web
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/web/directory.py

    r4a73f80 r7ccfe44  
    966966        return ctx.tag
    967967
    968 class ManifestResults(MultiFormatPage, ReloadMixin):
    969     docFactory = getxmlfile("manifest.xhtml")
     968
     969class 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
     1014def _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
     1024def _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
     1047class 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
     1082class ManifestResults(MultiFormatResource, ReloadMixin):
    9701083
    9711084    # Control MultiFormatPage
     
    9801093    render_HTML = None
    9811094
    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        )
    9861100
    9871101    def render_TEXT(self, req):
     
    9901104        is_finished = self.monitor.is_finished()
    9911105        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)
    9941108        return "\n".join(lines) + "\n"
    9951109
     
    10251139        return json.dumps(status, indent=1)
    10261140
    1027     def _si_abbrev(self):
    1028         si = self.monitor.origin_si
    1029         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_cap
    1044         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 string
    1047         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.tag
    10581141
    10591142class 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">
    22  <head>
    3     <title n:render="title"></title>
     3    <title t:render="title"></title>
    44    <link href="/tahoe.css" rel="stylesheet" type="text/css"/>
    55    <link href="/icon.png" rel="shortcut icon" />
    66    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    7     <meta n:render="refresh" />
     7    <meta t:render="refresh" />
    88  </head>
    99  <body>
    1010
    11 <h1><p n:render="header"></p></h1>
     11<h1><p t:render="header"></p></h1>
    1212
    13 <h2 n:render="reload" />
     13<h2 t:render="reload" />
    1414
    15 <table n:render="sequence" n:data="items">
    16   <tr n:pattern="header">
     15<table t:render="items">
     16  <tr t:pattern="header">
    1717    <td>Path</td>
    1818    <td>cap</td>
    1919  </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>
    2323  </tr>
    2424
    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>
    2626
    2727</table>
Note: See TracChangeset for help on using the changeset viewer.