示例#1
0
 def render_subscriber_row(self, ctx, s):
     ctx.fillSlots("nickname", s.nickname)
     ctx.fillSlots("tubid", s.tubid)
     ctx.fillSlots("connected", s.remote_address)
     since_s = render_time(s.when)
     ctx.fillSlots("since", since_s)
     ctx.fillSlots("version", s.version)
     ctx.fillSlots("service_name", s.service_name)
     return ctx.tag
示例#2
0
 def __init__(self, introducer_node, introducer_service):
     super(IntroducerRootElement, self).__init__()
     self.introducer_node = introducer_node
     self.introducer_service = introducer_service
     self.node_data_dict = {
         "my_nodeid": idlib.nodeid_b2a(self.introducer_node.nodeid),
         "version": get_package_versions_string(),
         "import_path": str(allmydata).replace("/", "/ "),  # XXX kludge for wrapping
         "rendered_at": render_time(time.time()),
     }
示例#3
0
 def subscribers(self, req, tag):
     subscribers = [{
         "nickname": s.nickname,
         "tubid": s.tubid,
         "connected": s.remote_address,
         "since": render_time(s.when),
         "version": s.version,
         "service_name": s.service_name,
     } for s in self.introducer_service.get_subscribers()]
     return SlotsSequenceElement(tag, subscribers)
示例#4
0
 def render_service_row(self, ctx, ad):
     ctx.fillSlots("serverid", ad.serverid)
     ctx.fillSlots("nickname", ad.nickname)
     ctx.fillSlots("connection-hints",
                   "connection hints: " + " ".join(ad.connection_hints))
     ctx.fillSlots("connected", "?")
     when_s = render_time(ad.when)
     ctx.fillSlots("announced", when_s)
     ctx.fillSlots("version", ad.version)
     ctx.fillSlots("service_name", ad.service_name)
     return ctx.tag
示例#5
0
    def render_row(self, ctx, data):
        s = data

        started_s = render_time(s.get_started())
        ctx.fillSlots("started", started_s)

        si_s = base32.b2a_or_none(s.get_storage_index())
        if si_s is None:
            si_s = "(None)"
        ctx.fillSlots("si", si_s)
        ctx.fillSlots("helper", {True: "Yes",
                                 False: "No"}[s.using_helper()])

        size = s.get_size()
        if size is None:
            size = "(unknown)"
        elif isinstance(size, (int, long, float)):
            size = abbreviate_size(size)
        ctx.fillSlots("total_size", size)

        progress = data.get_progress()
        if IUploadStatus.providedBy(data):
            link = "up-%d" % data.get_counter()
            ctx.fillSlots("type", "upload")
            # TODO: make an ascii-art bar
            (chk, ciphertext, encandpush) = progress
            progress_s = ("hash: %.1f%%, ciphertext: %.1f%%, encode: %.1f%%" %
                          ( (100.0 * chk),
                            (100.0 * ciphertext),
                            (100.0 * encandpush) ))
            ctx.fillSlots("progress", progress_s)
        elif IDownloadStatus.providedBy(data):
            link = "down-%d" % data.get_counter()
            ctx.fillSlots("type", "download")
            ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
        elif IPublishStatus.providedBy(data):
            link = "publish-%d" % data.get_counter()
            ctx.fillSlots("type", "publish")
            ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
        elif IRetrieveStatus.providedBy(data):
            ctx.fillSlots("type", "retrieve")
            link = "retrieve-%d" % data.get_counter()
            ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
        else:
            assert IServermapUpdaterStatus.providedBy(data)
            ctx.fillSlots("type", "mapupdate %s" % data.get_mode())
            link = "mapupdate-%d" % data.get_counter()
            ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
        ctx.fillSlots("status", T.a(href=link)[s.get_status()])
        return ctx.tag
示例#6
0
 def services(self, req, tag):
     services = self.introducer_service.get_announcements()
     services.sort(key=lambda ad: (ad.service_name, ad.nickname))
     services = [{
         "serverid": ad.serverid,
         "nickname": ad.nickname,
         "connection-hints":
             u"connection hints: " + u" ".join(ad.connection_hints),
         "connected": u"?",
         "announced": render_time(ad.when),
         "version": ad.version,
         "service_name": ad.service_name,
     } for ad in services]
     return SlotsSequenceElement(tag, services)
示例#7
0
    def render_row(self, ctx, data):
        s = data

        started_s = render_time(s.get_started())
        ctx.fillSlots("started", started_s)

        si_s = base32.b2a_or_none(s.get_storage_index())
        if si_s is None:
            si_s = "(None)"
        ctx.fillSlots("si", si_s)
        ctx.fillSlots("helper", {True: "Yes",
                                 False: "No"}[s.using_helper()])

        size = s.get_size()
        if size is None:
            size = "(unknown)"
        elif isinstance(size, (int, long, float)):
            size = abbreviate_size(size)
        ctx.fillSlots("total_size", size)

        progress = data.get_progress()
        if IUploadStatus.providedBy(data):
            link = "up-%d" % data.get_counter()
            ctx.fillSlots("type", "upload")
            # TODO: make an ascii-art bar
            (chk, ciphertext, encandpush) = progress
            progress_s = ("hash: %.1f%%, ciphertext: %.1f%%, encode: %.1f%%" %
                          ( (100.0 * chk),
                            (100.0 * ciphertext),
                            (100.0 * encandpush) ))
            ctx.fillSlots("progress", progress_s)
        elif IDownloadStatus.providedBy(data):
            link = "down-%d" % data.get_counter()
            ctx.fillSlots("type", "download")
            ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
        elif IPublishStatus.providedBy(data):
            link = "publish-%d" % data.get_counter()
            ctx.fillSlots("type", "publish")
            ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
        elif IRetrieveStatus.providedBy(data):
            ctx.fillSlots("type", "retrieve")
            link = "retrieve-%d" % data.get_counter()
            ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
        else:
            assert IServermapUpdaterStatus.providedBy(data)
            ctx.fillSlots("type", "mapupdate %s" % data.get_mode())
            link = "mapupdate-%d" % data.get_counter()
            ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
        ctx.fillSlots("status", T.a(href=link)[s.get_status()])
        return ctx.tag
示例#8
0
 def render_finished(self, ctx, data):
     when = data.get_finished()
     if not when:
         return "not yet"
     started_s = render_time(data.get_finished())
     return started_s
示例#9
0
 def render_started(self, ctx, data):
     started_s = render_time(data.get_started())
     return started_s
示例#10
0
文件: root.py 项目: warner/tahoe-lafs
 def data_rendered_at(self, ctx, data):
     return render_time(time.time())
示例#11
0
 def rendered_at(self, req, tag):
     return tag(render_time(time.time()))
示例#12
0
    def render_row(self, ctx, data):
        name, (target, metadata) = data
        name = name.encode("utf-8")
        assert not isinstance(name, unicode)
        nameurl = urllib.quote(name, safe="") # encode any slashes too

        root = get_root(ctx)
        here = "%s/uri/%s/" % (root, urllib.quote(self.node.get_uri()))
        if self.node.is_unknown() or self.node.is_readonly():
            unlink = "-"
            rename = "-"
        else:
            # this creates a button which will cause our _POST_unlink method
            # to be invoked, which unlinks the file and then redirects the
            # browser back to this directory
            unlink = T.form(action=here, method="post")[
                T.input(type='hidden', name='t', value='unlink'),
                T.input(type='hidden', name='name', value=name),
                T.input(type='hidden', name='when_done', value="."),
                T.input(type='submit', _class='btn', value='unlink', name="unlink"),
                ]

            rename = T.form(action=here, method="get")[
                T.input(type='hidden', name='t', value='rename-form'),
                T.input(type='hidden', name='name', value=name),
                T.input(type='hidden', name='when_done', value="."),
                T.input(type='submit', _class='btn', value='rename/relink', name="rename"),
                ]

        ctx.fillSlots("unlink", unlink)
        ctx.fillSlots("rename", rename)

        times = []
        linkcrtime = metadata.get('tahoe', {}).get("linkcrtime")
        if linkcrtime is not None:
            times.append("lcr: " + render_time(linkcrtime))
        else:
            # For backwards-compatibility with links last modified by Tahoe < 1.4.0:
            if "ctime" in metadata:
                ctime = render_time(metadata["ctime"])
                times.append("c: " + ctime)
        linkmotime = metadata.get('tahoe', {}).get("linkmotime")
        if linkmotime is not None:
            if times:
                times.append(T.br())
            times.append("lmo: " + render_time(linkmotime))
        else:
            # For backwards-compatibility with links last modified by Tahoe < 1.4.0:
            if "mtime" in metadata:
                mtime = render_time(metadata["mtime"])
                if times:
                    times.append(T.br())
                times.append("m: " + mtime)
        ctx.fillSlots("times", times)

        assert IFilesystemNode.providedBy(target), target
        target_uri = target.get_uri() or ""
        quoted_uri = urllib.quote(target_uri, safe="") # escape slashes too

        if IMutableFileNode.providedBy(target):
            # to prevent javascript in displayed .html files from stealing a
            # secret directory URI from the URL, send the browser to a URI-based
            # page that doesn't know about the directory at all
            dlurl = "%s/file/%s/@@named=/%s" % (root, quoted_uri, nameurl)

            ctx.fillSlots("filename", T.a(href=dlurl, rel="noreferrer")[name])
            ctx.fillSlots("type", "SSK")

            ctx.fillSlots("size", "?")

            info_link = "%s/uri/%s?t=info" % (root, quoted_uri)

        elif IImmutableFileNode.providedBy(target):
            dlurl = "%s/file/%s/@@named=/%s" % (root, quoted_uri, nameurl)

            ctx.fillSlots("filename", T.a(href=dlurl, rel="noreferrer")[name])
            ctx.fillSlots("type", "FILE")

            ctx.fillSlots("size", target.get_size())

            info_link = "%s/uri/%s?t=info" % (root, quoted_uri)

        elif IDirectoryNode.providedBy(target):
            # directory
            uri_link = "%s/uri/%s/" % (root, urllib.quote(target_uri))
            ctx.fillSlots("filename", T.a(href=uri_link)[name])
            if not target.is_mutable():
                dirtype = "DIR-IMM"
            elif target.is_readonly():
                dirtype = "DIR-RO"
            else:
                dirtype = "DIR"
            ctx.fillSlots("type", dirtype)
            ctx.fillSlots("size", "-")
            info_link = "%s/uri/%s/?t=info" % (root, quoted_uri)

        elif isinstance(target, ProhibitedNode):
            ctx.fillSlots("filename", T.strike[name])
            if IDirectoryNode.providedBy(target.wrapped_node):
                blacklisted_type = "DIR-BLACKLISTED"
            else:
                blacklisted_type = "BLACKLISTED"
            ctx.fillSlots("type", blacklisted_type)
            ctx.fillSlots("size", "-")
            info_link = None
            ctx.fillSlots("info", ["Access Prohibited:", T.br, target.reason])

        else:
            # unknown
            ctx.fillSlots("filename", name)
            if target.get_write_uri() is not None:
                unknowntype = "?"
            elif not self.node.is_mutable() or target.is_alleged_immutable():
                unknowntype = "?-IMM"
            else:
                unknowntype = "?-RO"
            ctx.fillSlots("type", unknowntype)
            ctx.fillSlots("size", "-")
            # use a directory-relative info link, so we can extract both the
            # writecap and the readcap
            info_link = "%s?t=info" % urllib.quote(name)

        if info_link:
            ctx.fillSlots("info", T.a(href=info_link)["More Info"])

        return ctx.tag
示例#13
0
 def started(self, req, tag):
     started_s = render_time(self._retrieve_status.get_started())
     return tag(started_s)
示例#14
0
 def started(self, req, tag):
     started_s = render_time(self._publish_status.get_started())
     return tag(started_s)
示例#15
0
 def render_started(self, ctx, data):
     started_s = render_time(data.get_started())
     return started_s
示例#16
0
文件: root.py 项目: bhyvex/tahoe-lafs
 def data_rendered_at(self, ctx, data):
     return render_time(time.time())
示例#17
0
 def render_finished(self, ctx, data):
     when = data.get_finished()
     if not when:
         return "not yet"
     started_s = render_time(data.get_finished())
     return started_s
示例#18
0
 def finished(self, req, tag):
     when = self._update_status.get_finished()
     if not when:
         return tag("not yet")
     started_s = render_time(self._update_status.get_finished())
     return tag(started_s)