summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--releng/models.py33
-rw-r--r--requirements.txt3
-rw-r--r--requirements_prod.txt3
-rw-r--r--templates/releng/release_detail.html24
4 files changed, 58 insertions, 5 deletions
diff --git a/releng/models.py b/releng/models.py
index 8bc54de..c7d2696 100644
--- a/releng/models.py
+++ b/releng/models.py
@@ -1,4 +1,9 @@
+from base64 import b64decode
+from bencode import bdecode, bencode
+from datetime import datetime
+import hashlib
import markdown
+from pytz import utc
from django.core.urlresolvers import reverse
from django.db import models
@@ -150,6 +155,34 @@ class Release(models.Model):
return mark_safe(markdown.markdown(
self.info, safe_mode=True, enable_attributes=False))
+ def torrent(self):
+ try:
+ data = b64decode(self.torrent_data)
+ except TypeError:
+ return None
+ data = bdecode(data)
+ # transform the data into a template-friendly dict
+ info = data.get('info', {})
+ metadata = {
+ 'comment': data.get('comment', None),
+ 'created_by': data.get('created by', None),
+ 'creation_date': None,
+ 'announce': data.get('announce', None),
+ 'file_name': info.get('name', None),
+ 'file_length': info.get('length', None),
+ 'piece_count': len(info.get('pieces', '')) / 20,
+ 'piece_length': info.get('piece length', None),
+ 'url_list': data.get('url-list', []),
+ 'info_hash': None,
+ }
+ if 'creation date' in data:
+ created= datetime.utcfromtimestamp(data['creation date'])
+ metadata['creation_date'] = created.replace(tzinfo=utc)
+ if info:
+ metadata['info_hash'] = hashlib.sha1(bencode(info)).hexdigest()
+
+ return metadata
+
for model in (Iso, Test, Release):
pre_save.connect(set_created_field, sender=model,
diff --git a/requirements.txt b/requirements.txt
index 1d5b068..ae58ee5 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,6 +1,7 @@
Django==1.4.3
Markdown==2.2.1
South==0.7.6
+bencode==1.0
django-countries==1.5
pgpdump==1.4
-pytz>=2012h
+pytz>=2012j
diff --git a/requirements_prod.txt b/requirements_prod.txt
index f84f46d..ee1b17a 100644
--- a/requirements_prod.txt
+++ b/requirements_prod.txt
@@ -1,9 +1,10 @@
Django==1.4.3
Markdown==2.2.1
South==0.7.6
+bencode==1.0
django-countries==1.5
pgpdump==1.4
psycopg2==2.4.6
pyinotify==0.9.4
python-memcached==1.48
-pytz>=2012h
+pytz>=2012j
diff --git a/templates/releng/release_detail.html b/templates/releng/release_detail.html
index fec9ce2..f4de9e5 100644
--- a/templates/releng/release_detail.html
+++ b/templates/releng/release_detail.html
@@ -9,9 +9,10 @@
<li><strong>Release Date:</strong> {{ release.release_date|date }}</li>
{% if release.kernel_version %}<li><strong>Kernel Version:</strong> {{ release.kernel_version }}</li>{% endif %}
<li><strong>Available:</strong> {{ release.available|yesno }}</li>
- {% if release.available %}<li><a href="https://www.archlinux.org/{{ release.iso_url }}.torrent"
- title="Download torrent for {{ release.version }}">Torrent</a></li>{% endif %}
- {% if release.available %}<li><a href="{{ release.magnet_uri }}">Magnet</a></li>{% endif %}
+ {% if release.available %}<li><strong>Download:</strong> <a href="https://www.archlinux.org/{{ release.iso_url }}.torrent"
+ title="Download torrent for {{ release.version }}">Torrent</a>,
+ <a href="{{ release.magnet_uri }}">Magnet</a></li>{% endif %}
+ {% if release.torrent_infohash %}<li><strong>Torrent Info Hash:</strong> {{ release.torrent_infohash }}</li>{% endif %}
<li><strong>Download Size:</strong> {% if release.file_size %}{{ release.file_size|filesizeformat }}{% else %}Unknown{% endif %}</li>
</ul>
@@ -20,5 +21,22 @@
<div class="article-content">{{ release.info_html }}</div>
{% endif %}
+
+ {% if release.torrent_data %}{% with release.torrent as torrent %}
+ <h3>Torrent Information</h3>
+
+ <ul>
+ <li><strong>Comment:</strong> {{ torrent.comment }}</li>
+ <li><strong>Creation Date:</strong> {{ torrent.creation_date|date:"DATETIME_FORMAT" }} UTC</li>
+ <li><strong>Created By:</strong> {{ torrent.created_by }}</li>
+ <li><strong>Announce URL:</strong> {{ torrent.announce }}</li>
+ <li><strong>File Name:</strong> {{ torrent.file_name }}</li>
+ <li><strong>File Length:</strong> {{ torrent.file_length|filesizeformat }}</li>
+ <li><strong>Piece Count:</strong> {{ torrent.piece_count }} pieces</li>
+ <li><strong>Piece Length:</strong> {{ torrent.piece_length|filesizeformat }}</li>
+ <li><strong>Computed Info Hash:</strong> {{ torrent.info_hash }}</li>
+ <li><strong>URL List Length:</strong> {{ torrent.url_list|length }} URLs</li>
+ </ul>
+ {% endwith %}{% endif %}
</div>
{% endblock %}