Exemple #1
0
    def __call__(self, environ, start_response):
        """ Invoke the Controller.
        """
        c._debug = []
        c._timezone = config['pyroscope.timezone']

        c.engine = Bunch()
        c.engine.startup = fmt.human_duration(rtorrent.get_startup(), precision=3)

        #XXX Use multimethod, or get from poller
        for attr, method in self.GLOBAL_STATE.items():
            c.engine[attr] = getattr(self.proxy.rpc, method)()

        return BaseController.__call__(self, environ, start_response)
Exemple #2
0
    def data(self, id):
        if id == "timeline.xml":
            response.headers['Content-Type'] = 'application/xml; charset="utf-8"'

            proxy = rtorrent.Proxy.create()
            torrents = list(rtorrent.View(proxy, 'main').items())
            torrent_data = []
            rtorrent_start = rtorrent.get_startup()

            span_data = defaultdict(list)
            for item in torrents:
                title = shorten(obfuscate(item.name))
                if item.is_open:
                    # Store in minute-sized buckets
                    span_data[item.state_changed // self.BUCKET_SIZE * self.BUCKET_SIZE].append(item)
                elif item.message:
                    # Add closed torrents with a message (like unregistered ones)
                    torrent_data.append(u'<event start="%s" title="Stopped %s">'
                            u'Stopped %s, possibly due to %s @ %s</event>' % (
                        time.strftime("%c", time.localtime(item.state_changed)),
                        escape(quoted(title), quote=True),
                        escape(quoted(obfuscate(item.name))),
                        escape(quoted(item.message)),
                        ", ".join(escape(obfuscate(i)) for i in item.tracker_domains),
                    ))

                tied_file = os.path.expanduser(item.tied_to_file)
                if os.path.exists(tied_file):
                    torrent_data.append(u'<event start="%s" title="Downloaded %s">'
                            u'Downloaded metafile for %s</event>' % (
                        time.strftime("%c", time.localtime(
                            os.path.getmtime(tied_file)
                        )),
                        escape(quoted(title), quote=True),
                        escape(quoted(obfuscate(item.name))),
                    ))

            for bucket, items in span_data.items():
                if len(items) > self.HOTSPOT_SIZE:
                    # hot spot, f.x. happens when you restart rTorrent
                    # since we filtered open torrents only, they had to be started at that point
                    entries = [Bunch(
                        title = u"Started %d torrents within %d secs, seeding them..." % (
                            len(items), self.BUCKET_SIZE),
                        start = bucket,
                        text = ",\n".join(shorten(obfuscate(item.name), 20) for item in items[:40])
                             + (", ..." if len(items) > 40 else ""),
                    )]
                else:
                    # torrent gets its own event
                    entries = [Bunch(
                            title = u"%s %s" % (
                                u"Seeding" if item.complete else u"Leeching",
                                quoted(shorten(obfuscate(item.name))) ),
                            start = item.state_changed,
                            text = u"NAME: %s | %s" % (
                                obfuscate(item.name), make_tooltip(item)),
                        ) for item in items
                    ]

                torrent_data.extend([u'<event start="%s" end="%s" title="%s">%s</event>' % (
                        time.strftime(u"%c", time.localtime(entry.start)),
                        c.now,
                        escape(entry.title, quote=True),
                        escape(entry.text),
                    ) for entry in entries
                ])

            if rtorrent_start:
                torrent_data.append(u'<event start="%s" title="rTorrent started"></event>' % (
                    time.strftime(u"%c", time.localtime(rtorrent_start)),
                ))

            torrent_data.append(u'<event start="%s" title="The time is now %s"></event>' % (
                c.now, time.strftime("%Y-%m-%d %H:%M:%S", self.now),
            ))

            torrent_data = u'\n'.join(torrent_data)

            return u"""<?xml version="1.0" encoding="utf-8"?>
<data>""" + torrent_data + u"""
Exemple #3
0
    def data(self, id):
        if id == "timeline.xml":
            response.headers["Content-Type"] = 'application/xml; charset="utf-8"'

            proxy = rtorrent.Proxy.create()
            torrents = list(rtorrent.View(proxy, "main").items())
            torrent_data = []
            rtorrent_start = rtorrent.get_startup()

            span_data = defaultdict(list)
            for item in torrents:
                title = shorten(obfuscate(item.name))
                if item.is_open:
                    # Store in minute-sized buckets
                    span_data[item.state_changed // self.BUCKET_SIZE * self.BUCKET_SIZE].append(item)
                elif item.message:
                    # Add closed torrents with a message (like unregistered ones)
                    torrent_data.append(
                        u'<event start="%s" title="Stopped %s">'
                        u"Stopped %s, possibly due to %s @ %s</event>"
                        % (
                            time.strftime("%c", time.localtime(item.state_changed)),
                            escape(quoted(title), quote=True),
                            escape(quoted(obfuscate(item.name))),
                            escape(quoted(item.message)),
                            ", ".join(escape(obfuscate(i)) for i in item.tracker_domains),
                        )
                    )

                tied_file = os.path.expanduser(item.tied_to_file)
                if os.path.exists(tied_file):
                    torrent_data.append(
                        u'<event start="%s" title="Downloaded %s">'
                        u"Downloaded metafile for %s</event>"
                        % (
                            time.strftime("%c", time.localtime(os.path.getmtime(tied_file))),
                            escape(quoted(title), quote=True),
                            escape(quoted(obfuscate(item.name))),
                        )
                    )

            for bucket, items in span_data.items():
                if len(items) > self.HOTSPOT_SIZE:
                    # hot spot, f.x. happens when you restart rTorrent
                    # since we filtered open torrents only, they had to be started at that point
                    entries = [
                        Bunch(
                            title=u"Started %d torrents within %d secs, seeding them..."
                            % (len(items), self.BUCKET_SIZE),
                            start=bucket,
                            text=",\n".join(shorten(obfuscate(item.name), 20) for item in items[:40])
                            + (", ..." if len(items) > 40 else ""),
                        )
                    ]
                else:
                    # torrent gets its own event
                    entries = [
                        Bunch(
                            title=u"%s %s"
                            % (u"Seeding" if item.complete else u"Leeching", quoted(shorten(obfuscate(item.name)))),
                            start=item.state_changed,
                            text=u"NAME: %s | %s" % (obfuscate(item.name), make_tooltip(item)),
                        )
                        for item in items
                    ]

                torrent_data.extend(
                    [
                        u'<event start="%s" end="%s" title="%s">%s</event>'
                        % (
                            time.strftime(u"%c", time.localtime(entry.start)),
                            c.now,
                            escape(entry.title, quote=True),
                            escape(entry.text),
                        )
                        for entry in entries
                    ]
                )

            if rtorrent_start:
                torrent_data.append(
                    u'<event start="%s" title="rTorrent started"></event>'
                    % (time.strftime(u"%c", time.localtime(rtorrent_start)),)
                )

            torrent_data.append(
                u'<event start="%s" title="The time is now %s"></event>'
                % (c.now, time.strftime("%Y-%m-%d %H:%M:%S", self.now))
            )

            torrent_data = u"\n".join(torrent_data)

            return (
                u"""<?xml version="1.0" encoding="utf-8"?>
<data>"""
                + torrent_data
                + u"""
    <event 
            start="Jun 04 2009 00:00:00 GMT"
            title="PyroScope project created on Google Code"
            image="http://code.google.com/p/pyroscope/logo?logo_id=1245201363"
        ><![CDATA[
            Initial directory structure for project 
            <a href="http://pyroscope.googlecode.com/">PyroScope</a> 
            created in SVN.
        ]]>
    </event>
    
    <!--    
    <event 
            start="Jun 13 2009 00:00:00 GMT"
            title="Started rTorrent 0.8.2/0.12.2"
        >
        Started rTorrent 0.8.2/0.12.2
    </event>
    
    <event 
            start="Jun 14 2009 22:00:00 GMT"
            end="Jun 16 2009 01:00:00 GMT"
            isDuration="true"
            title="Downloading Debian.ISO"
        >
        Debian.ISO [3333MiB, Ratio 1.234]
        </event>
        
    <event 
            start="Jun 16 2009 01:00:00 GMT"
            end="Jun 20 2009 14:00:00 GMT"
            isDuration="true"
            title="Seeding Debian.ISO"
        >
        Debian.ISO [3333MiB, Ratio 2.674]
        </event>
        
    <event link="...">
    -->
</data>
"""
            )