r151 - in /debtorrent/trunk: DebTorrent/BT1/AptListener.py DebTorrent/ConfigDir.py DebTorrent/launchmanycore.py btlaunchmany.py config.debtorrent.ini
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Thu Jul 12 21:01:04 UTC 2007
Author: camrdale-guest
Date: Thu Jul 12 21:01:04 2007
New Revision: 151
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=151
Log:
Add the allow_get functionality to the AptListener info page.
Improve the layout of the info page.
Modified:
debtorrent/trunk/DebTorrent/BT1/AptListener.py
debtorrent/trunk/DebTorrent/ConfigDir.py
debtorrent/trunk/DebTorrent/launchmanycore.py
debtorrent/trunk/btlaunchmany.py
debtorrent/trunk/config.debtorrent.ini
Modified: debtorrent/trunk/DebTorrent/BT1/AptListener.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/AptListener.py?rev=151&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/AptListener.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/AptListener.py Thu Jul 12 21:01:04 2007
@@ -291,47 +291,64 @@
# Write the table headers
s.write('<table summary="files" border="1">\n' \
- '<tr><th>name</th>\n' \
+ '<tr>\n' \
+ '<th>name/<br>\n' \
+ 'info hash</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">peers/<br>\n' \
+ '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">download/<br>\n' \
+ 'upload</th>\n' \
+ '<th align="right">downloaded/<br>\n' \
+ 'uploaded</th>\n' \
'<th align="right">size</th>\n' \
'<th align="right">time remaining</th>\n' \
- '<th>error message</th></tr>\n')
+ '<th>error message</th>\n' \
+ '</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')
+ s.write('<tr><td colspan="10" 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,
+ ( name, hash, status, progress, peers, seeds, seedsmsg, dist,
uprate, dnrate, upamt, dnamt, size, t, msg ) = x
- s.write('<tr><td>%s</td>\n' \
+
+ if self.allow_get:
+ linkname = '<a href="/file?info_hash=' + quote(hash) + '">' + name + '</a>'
+ else:
+ linkname = name
+
+ s.write('<tr>\n'
+ '<td>%s<br>\n' \
+ '<code>%s</code></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">%s<br>\n' \
+ '%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">%0.1fK/s<br>\n' \
+ '%0.1fK/s</td>\n' \
+ '<td align="right">%s<br>\n' \
+ '%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')
+ % (linkname, b2a_hex(hash), status, progress, peers, seeds,
+ dist, dnrate/1000, uprate/1000, size_format(dnamt),
+ size_format(upamt), size_format(size), hours(t), msg))
+
+ s.write('</table>\n' \
+ '<ul>\n' \
+ '<li><em>info hash:</em> SHA1 hash of the "info" section of the metainfo (.dtorrent) file</li>\n' \
+ '<li><em>status:</em> the current operation under way</li>\n' \
+ '<li><em>progress:</em> the current progress in the operation under way</li>\n' \
+ '<li><em>distributed copies:</em> the number of copies of the complete torrent seen in non-seeding peers</li>\n' \
+ '</ul>\n')
s.write('</body>\n' \
'</html>\n')
@@ -592,6 +609,41 @@
self.handler.add(infohash, a)
+
+ def get_file(self, hash):
+ """Get the metainfo file for a torrent.
+
+ @type hash: C{string}
+ @param hash: the infohash of the torrent to get the metainfo of
+ @rtype: (C{int}, C{string}, C{dictionary}, C{string})
+ @return: the HTTP status code, status message, headers, and bencoded
+ metainfo file
+
+ """
+
+ if not self.allow_get:
+ return (400, 'Not Authorized', {'Server': VERSION,
+ 'Content-Type': 'text/plain',
+ 'Pragma': 'no-cache'},
+ 'get function is not available with this tracker.')
+ if hash not in self.handler.torrent_cache:
+ return (404, 'Not Found', {'Server': VERSION,
+ 'Content-Type': 'text/plain',
+ 'Pragma': 'no-cache'},
+ alas)
+ fname = self.handler.torrent_cache[hash]['file'] + '.dtorrent'
+ response = self.handler.configdir.getTorrentFile(hash)
+ if not response:
+ return (404, 'Not Found', {'Server': VERSION,
+ 'Content-Type': 'text/plain',
+ 'Pragma': 'no-cache'},
+ alas)
+ return (200, 'OK', {'Server': VERSION,
+ 'Content-Type': 'application/x-debtorrent',
+ 'Content-Disposition': 'attachment; filename=' + fname},
+ response)
+
+
def get(self, connection, path, headers):
"""Respond to a GET request.
@@ -670,6 +722,8 @@
return (200, 'OK', {'Server': VERSION, 'Content-Type' : 'image/x-icon'}, self.favicon)
else:
return (404, 'Not Found', {'Server': VERSION, 'Content-Type': 'text/plain', 'Pragma': 'no-cache'}, alas)
+ if (path == 'file'):
+ return self.get_file(params('info_hash'))
# Process the rest as a proxy
path = path.split('/')
Modified: debtorrent/trunk/DebTorrent/ConfigDir.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/ConfigDir.py?rev=151&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/ConfigDir.py (original)
+++ debtorrent/trunk/DebTorrent/ConfigDir.py Thu Jul 12 21:01:04 2007
@@ -388,6 +388,34 @@
d.sort()
return d
+ def getTorrentFile(self, t, v = -1):
+ """Get the undecoded torrent file for the hash.
+
+ @type t: C{string}
+ @param t: the torrent hash to lookup
+ @type v: C{int}
+ @param v: the variation to get (optional, default is the largest)
+ @rtype: C{string}
+ @return: the contents of the torrent file
+
+ """
+
+ if v == -1:
+ v = max(self.getTorrentVariations(t)) # potential exception
+ t = tohex(t)
+ if v:
+ t += '.'+str(v)
+ try:
+ f = open(os.path.join(self.dir_torrentcache,t),'rb')
+ r = f.read()
+ except:
+ r = None
+ try:
+ f.close()
+ except:
+ pass
+ return r
+
def getTorrent(self, t, v = -1):
"""Get the torrent data for the hash.
@@ -400,20 +428,14 @@
"""
- if v == -1:
- v = max(self.getTorrentVariations(t)) # potential exception
- t = tohex(t)
- if v:
- t += '.'+str(v)
- try:
- f = open(os.path.join(self.dir_torrentcache,t),'rb')
- r = bdecode(f.read())
- except:
+ f = self.getTorrentFile(t, v)
+ if f:
+ try:
+ r = bdecode(f)
+ except:
+ r = None
+ else:
r = None
- try:
- f.close()
- except:
- pass
return r
def writeTorrent(self, data, t, v = -1):
Modified: debtorrent/trunk/DebTorrent/launchmanycore.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/launchmanycore.py?rev=151&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/launchmanycore.py (original)
+++ debtorrent/trunk/DebTorrent/launchmanycore.py Thu Jul 12 21:01:04 2007
@@ -420,11 +420,15 @@
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})
+ (C{string}, 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.
+ Which are the name, info hash, 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
@@ -489,8 +493,8 @@
else:
msg = ''
- data.append(( name, status, progress, peers, seeds, seedsmsg, dist,
- uprate, dnrate, upamt, dnamt, size, t, msg ))
+ data.append(( name, hash, status, progress, peers, seeds, seedsmsg,
+ dist, uprate, dnrate, upamt, dnamt, size, t, msg ))
return data
Modified: debtorrent/trunk/btlaunchmany.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/btlaunchmany.py?rev=151&op=diff
==============================================================================
--- debtorrent/trunk/btlaunchmany.py (original)
+++ debtorrent/trunk/btlaunchmany.py Thu Jul 12 21:01:04 2007
@@ -95,7 +95,7 @@
if not data:
self.message('no torrents')
for x in data:
- ( name, status, progress, peers, seeds, seedsmsg, dist,
+ ( name, hash, status, progress, peers, seeds, seedsmsg, dist,
uprate, dnrate, upamt, dnamt, size, t, msg ) = x
print '"%s": "%s" (%s) - %sP%s%s%.3fD u%0.1fK/s-d%0.1fK/s u%dK-d%dK "%s"' % (
name, status, progress, peers, seeds, seedsmsg, dist,
Modified: debtorrent/trunk/config.debtorrent.ini
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/config.debtorrent.ini?rev=151&op=diff
==============================================================================
--- debtorrent/trunk/config.debtorrent.ini (original)
+++ debtorrent/trunk/config.debtorrent.ini Thu Jul 12 21:01:04 2007
@@ -336,8 +336,8 @@
#
# Allow Get
#
-# Add a /file?hash={hash} url that allows users to download the torrent file
-# from the APT request listener's info page.
+# Add a /file?info_hash=<hash> url that allows users to download the dtorrent
+# file from the APT request listener's info page.
#
# allow_get = 0
More information about the Debtorrent-commits
mailing list