r116 - in /debtorrent/trunk/DebTorrent: BT1/AptListener.py launchmanycore.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Tue Jun 19 22:08:29 UTC 2007


Author: camrdale-guest
Date: Tue Jun 19 22:08:29 2007
New Revision: 116

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=116
Log:
Add simple status reporting to the infopage in AptListener.

Modified:
    debtorrent/trunk/DebTorrent/BT1/AptListener.py
    debtorrent/trunk/DebTorrent/launchmanycore.py

Modified: debtorrent/trunk/DebTorrent/BT1/AptListener.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/AptListener.py?rev=116&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/AptListener.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/AptListener.py Tue Jun 19 22:08:29 2007
@@ -371,7 +371,6 @@
         
         """
         
-        # TODO: add simple status reporting
         try:
             if not self.config['show_infopage']:
                 return (404, 'Not Found', {'Server': VERSION, 'Content-Type': 'text/plain', 'Pragma': 'no-cache'}, alas)
@@ -380,80 +379,63 @@
                 return (302, 'Found', {'Server': VERSION, 'Content-Type': 'text/html', 'Location': red},
                         '<A HREF="'+red+'">Click Here</A>')
             
+            # Write the document header
             s = StringIO()
-            s.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n' \
-                '<html><head><title>DebTorrent download info</title>\n')
+            s.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" ' \
+                    '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n' \
+                    '<html><head><title>DebTorrent download info</title>\n')
             if self.favicon is not None:
                 s.write('<link rel="shortcut icon" href="/favicon.ico">\n')
             s.write('</head>\n<body>\n' \
-                '<h3>DebTorrent download info</h3>\n'\
-                '<ul>\n'
-                '<li><strong>client version:</strong> %s</li>\n' \
-                '<li><strong>client time:</strong> %s</li>\n' \
-                '</ul>\n' % (version, isotime()))
-#            if self.config['allowed_dir']:
-#                if self.show_names:
-#                    names = [ (self.allowed[hash]['name'],hash)
-#                              for hash in self.allowed.keys() ]
-#                else:
-#                    names = [ (None,hash)
-#                              for hash in self.allowed.keys() ]
-#            else:
-#                names = [ (None,hash) for hash in self.downloads.keys() ]
-#            if not names:
-#                s.write('<p>not downloading any files yet...</p>\n')
-#            else:
-#                names.sort()
-#                tn = 0
-#                tc = 0
-#                td = 0
-#                tt = 0  # Total transferred
-#                ts = 0  # Total size
-#                nf = 0  # Number of files displayed
-#                if self.config['allowed_dir'] and self.show_names:
-#                    s.write('<table summary="files" border="1">\n' \
-#                        '<tr><th>info hash</th><th>torrent name</th><th align="right">size</th><th align="right">complete</th><th align="right">downloading</th><th align="right">downloaded</th><th align="right">transferred</th></tr>\n')
-#                else:
-#                    s.write('<table summary="files">\n' \
-#                        '<tr><th>info hash</th><th align="right">complete</th><th align="right">downloading</th><th align="right">downloaded</th></tr>\n')
-#                for name,hash in names:
-#                    l = self.downloads[hash]
-#                    n = self.completed.get(hash, 0)
-#                    tn = tn + n
-#                    c = self.seedcount[hash]
-#                    tc = tc + c
-#                    d = len(l) - c
-#                    td = td + d
-#                    if self.config['allowed_dir'] and self.show_names:
-#                        if self.allowed.has_key(hash):
-#                            nf = nf + 1
-#                            sz = self.allowed[hash]['length']  # size
-#                            ts = ts + sz
-#                            szt = sz * n   # Transferred for this torrent
-#                            tt = tt + szt
-#                            if self.allow_get == 1:
-#                                linkname = '<a href="/file?info_hash=' + quote(hash) + '">' + name + '</a>'
-#                            else:
-#                                linkname = name
-#                            s.write('<tr><td><code>%s</code></td><td>%s</td><td align="right">%s</td><td align="right">%i</td><td align="right">%i</td><td align="right">%i</td><td align="right">%s</td></tr>\n' \
-#                                % (b2a_hex(hash), linkname, size_format(sz), c, d, n, size_format(szt)))
-#                    else:
-#                        s.write('<tr><td><code>%s</code></td><td align="right"><code>%i</code></td><td align="right"><code>%i</code></td><td align="right"><code>%i</code></td></tr>\n' \
-#                            % (b2a_hex(hash), c, d, n))
-#                if self.config['allowed_dir'] and self.show_names:
-#                    s.write('<tr><td align="right" colspan="2">%i files</td><td align="right">%s</td><td align="right">%i</td><td align="right">%i</td><td align="right">%i</td><td align="right">%s</td></tr>\n'
-#                            % (nf, size_format(ts), tc, td, tn, size_format(tt)))
-#                else:
-#                    s.write('<tr><td align="right">%i files</td><td align="right">%i</td><td align="right">%i</td><td align="right">%i</td></tr>\n'
-#                            % (nf, tc, td, tn))
-#                s.write('</table>\n' \
-#                    '<ul>\n' \
-#                    '<li><em>info hash:</em> SHA1 hash of the "info" section of the metainfo (*.dtorrent)</li>\n' \
-#                    '<li><em>complete:</em> number of connected clients with the complete file</li>\n' \
-#                    '<li><em>downloading:</em> number of connected clients still downloading</li>\n' \
-#                    '<li><em>downloaded:</em> reported complete downloads</li>\n' \
-#                    '<li><em>transferred:</em> torrent size * total downloaded (does not include partial transfers)</li>\n' \
-#                    '</ul>\n')
+                    '<h3>DebTorrent download info</h3>\n'\
+                    '<ul>\n'
+                    '<li><strong>client version:</strong> %s</li>\n' \
+                    '<li><strong>client time:</strong> %s</li>\n' \
+                    '</ul>\n' % (version, isotime()))
+            
+            # Write the table headers
+            s.write('<table summary="files" border="1">\n' \
+                    '<tr><th>name</th>\n' \
+                    '<th>status</th>\n' \
+                    '<th align="right">progress</th>\n' \
+                    '<th align="right">peers</th>\n' \
+                    '<th align="right">seeds</th>\n' \
+                    '<th align="right">distributed copies</th>\n' \
+                    '<th align="right">upload rate</th>\n' \
+                    '<th align="right">download rate</th>\n' \
+                    '<th align="right">uploaded</th>\n' \
+                    '<th align="right">downloaded</th>\n' \
+                    '<th align="right">size</th>\n' \
+                    '<th align="right">time remaining</th>\n' \
+                    '<th>error message</th></tr>\n')
+
+            # Get the data from the statistics gatherer
+            data = self.handler.gather_stats()
+            if not data:
+                s.write('<tr><td colspan="13" align="left">no torrents</td></tr>\n')
+                
+            # Display a table row for each running torrent
+            for x in data:
+                ( name, status, progress, peers, seeds, seedsmsg, dist,
+                  uprate, dnrate, upamt, dnamt, size, t, msg ) = x
+                s.write('<tr><td>%s</td>\n' \
+                        '<td>%s</td>\n' \
+                        '<td align="right">%s</td>\n' \
+                        '<td align="right">%s</td>\n' \
+                        '<td align="right">%s</td>\n' \
+                        '<td align="right">%.3f</td>\n' \
+                        '<td align="right">%0.1fK/s</td>\n' \
+                        '<td align="right">%0.1fK/s</td>\n' \
+                        '<td align="right">%s</td>\n' \
+                        '<td align="right">%s</td>\n' \
+                        '<td align="right">%s</td>\n' \
+                        '<td align="right">%s</td>\n' \
+                        '<td>%s</td></tr>\n' \
+                        % (name, status, progress, peers, seeds, dist, 
+                           uprate/1000, dnrate/1000, size_format(upamt), 
+                           size_format(dnamt), size_format(size), hours(t), msg))
+
+            s.write('</table>\n')
 
             s.write('</body>\n' \
                 '</html>\n')
@@ -899,3 +881,30 @@
         r = str(int((s/1099511627776.0)*100.0)/100.0) + 'TiB'
     return(r)
 
+def hours(n):
+    """Formats seconds into a human-readable time.
+    
+    Formats a given number of seconds into a human-readable time appropriate
+    for display to the user.
+    
+    @type n: C{int}
+    @param n: the number of seconds
+    @rtype: C{string}
+    @return: a displayable representation of the number of seconds
+    
+    """
+    
+    if n == 0:
+        return 'complete!'
+    try:
+        n = int(n)
+        assert n >= 0 and n < 5184000  # 60 days
+    except:
+        return '<unknown>'
+    m, s = divmod(n, 60)
+    h, m = divmod(m, 60)
+    if h > 0:
+        return '%d hour %02d min %02d sec' % (h, m, s)
+    else:
+        return '%d min %02d sec' % (m, s)
+

Modified: debtorrent/trunk/DebTorrent/launchmanycore.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/launchmanycore.py?rev=116&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/launchmanycore.py (original)
+++ debtorrent/trunk/DebTorrent/launchmanycore.py Tue Jun 19 22:08:29 2007
@@ -411,6 +411,27 @@
     def stats(self):
         """Call the Output display with the currently running torrents' statistics."""
         self.rawserver.add_task(self.stats, self.stats_period)
+        data = self.gather_stats()
+        stop = self.Output.display(data)
+        if stop:
+            self.doneflag.set()
+
+    def gather_stats(self):
+        """Gather the statistics for the currently running torrents.
+        
+        Returns a list, one per running torrent, of tuples:
+        
+        (C{string}, C{string}, C{string}, C{int}, C{int}, C{string}, C{float},
+        C{float}, C{float}, C{long}, C{long}, C{long}, C{float}, C{string})
+            
+        Which are the name, current status, progress report, number of peers, number of seeds, unknown, number of distributed copies,
+        upload rate, download rate, amount uploaded, amount downloaded, total length, time remaining, and latest error message.
+        
+        @rtype: C{list}
+        @return: various statistics for the running torrents
+        
+        """
+        
         data = []
         for hash in self.torrent_list:
             cache = self.torrent_cache[hash]
@@ -471,9 +492,8 @@
 
             data.append(( name, status, progress, peers, seeds, seedsmsg, dist,
                           uprate, dnrate, upamt, dnamt, size, t, msg ))
-        stop = self.Output.display(data)
-        if stop:
-            self.doneflag.set()
+
+        return data
 
     def remove(self, hash):
         """Stop and remove a running torrent.




More information about the Debtorrent-commits mailing list