diff options
author | Seth Vidal <skvidal@fedoraproject.org> | 2007-05-22 15:31:39 -0400 |
---|---|---|
committer | Seth Vidal <skvidal@fedoraproject.org> | 2007-05-22 15:31:39 -0400 |
commit | 3f9d6695aba27f1b4b4c0c359140b0fde95c1022 (patch) | |
tree | ae62ed5fb400c95b204ca1a237af90304af06a70 /scripts | |
parent | 6935e829c4aefdc669f5351ee55ecbf45d8d3b27 (diff) | |
download | releng-3f9d6695aba27f1b4b4c0c359140b0fde95c1022.tar.gz releng-3f9d6695aba27f1b4b4c0c359140b0fde95c1022.tar.xz releng-3f9d6695aba27f1b4b4c0c359140b0fde95c1022.zip |
add the torrent-generator script
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/torrent-generator/foot.html | 34 | ||||
-rw-r--r-- | scripts/torrent-generator/foot.rss | 3 | ||||
-rw-r--r-- | scripts/torrent-generator/head.html | 42 | ||||
-rw-r--r-- | scripts/torrent-generator/head.rss | 11 | ||||
-rwxr-xr-x | scripts/torrent-generator/torrent-generator | 188 | ||||
-rw-r--r-- | scripts/torrent-generator/torrent_generator.conf | 9 |
6 files changed, 287 insertions, 0 deletions
diff --git a/scripts/torrent-generator/foot.html b/scripts/torrent-generator/foot.html new file mode 100644 index 0000000..50c97ea --- /dev/null +++ b/scripts/torrent-generator/foot.html @@ -0,0 +1,34 @@ + </table> + </p> + <p> + <B>To use this system do the following:</b><br> + <ul> + <li>Download bittorrent:<br> + Use Fedora Extras: yum install bittorrent<br> + or<br> + <a href="http://bitconjurer.org/BitTorrent/download.html">from the homesite</a> + </li> + <li>install bittorrent</li> + <li>Open up ports 6881-6999/tcp so other clients can contact you for bits</li> + <li>figure out where you want the isos to go on your system</li> + <li>download one of the torrent files above:<br> + wget http://torrent.fedoraproject.org/torrents/$torrent-filename-from-above + </li> + <li>To download run: + bittorrent-curses --max_upload_rate 350 $torrent-filename-from-above-here. + </li> + <li>Once your download is complete please leave your downloader running so it + can help upload to the other clients. This is what makes bittorrent + efficient.</li> + </ul> + </p> +<p> +<a href="mailto:admin at fedoraproject.org">admin at fedoraproject.org</a> +</p> +<p> +<hr> +<a href="http://linux.dell.com"><img border=0 src="/images/poweredby_horizontal_lr.gif"></a> +</p> +</body> +</html> + diff --git a/scripts/torrent-generator/foot.rss b/scripts/torrent-generator/foot.rss new file mode 100644 index 0000000..2a31cb0 --- /dev/null +++ b/scripts/torrent-generator/foot.rss @@ -0,0 +1,3 @@ + +</channel> +</rss> diff --git a/scripts/torrent-generator/head.html b/scripts/torrent-generator/head.html new file mode 100644 index 0000000..b549d7a --- /dev/null +++ b/scripts/torrent-generator/head.html @@ -0,0 +1,42 @@ +<html> + <head> + <title>Bittorrent for torrent.fedoraproject.org</title> + <style> +table { + border-collapse:collapse; +} +th { + margin:5px; + padding: 8px; + border:1px solid #336699; + background-color:#336699; + color:#FFFFFF; + font-size: 9pt; + font-weight:bold; +} + +td { + margin:5px; + padding: 5px; + border:1px solid #336699; + background-color:#FFFFFF; + color:#000000; + font-size: 9pt; +} + + + </style> +<link rel="alternate" type="application/xml" title="RSS" href="rss20.xml"> + </head> + <body bgcolor="#ffffff"> + <p> + <h2>This is a tracker for the Fedora Project</h2> + </p> + <p> + <table width="80%" class='middletable'> + <tr> + <th>torrent</th> + <th>description</th> + <th>size</th> + <th>date</th> + </tr>
\ No newline at end of file diff --git a/scripts/torrent-generator/head.rss b/scripts/torrent-generator/head.rss new file mode 100644 index 0000000..3a152a5 --- /dev/null +++ b/scripts/torrent-generator/head.rss @@ -0,0 +1,11 @@ +<?xml version="1.0" ?> +<rss version="2.0"> + +<channel> +<title>Fedora Torrent</title> +<link>http://torrent.fedoraproject.org/</link> +<description>RSS feed for Fedora</description> +<language>en-us</language> +<copyright>admin at fedoraproject.org</copyright> +<ttl>60</ttl> + diff --git a/scripts/torrent-generator/torrent-generator b/scripts/torrent-generator/torrent-generator new file mode 100755 index 0000000..1fb6daa --- /dev/null +++ b/scripts/torrent-generator/torrent-generator @@ -0,0 +1,188 @@ +#!/usr/bin/python -tt +# generate html and rss output files based on ini of torrents. +# (c) 2007 Seth Vidal - skvidal @ fedoraproject.org + +# read in .ini files in a dir +# take each section from them and assemble an html file and an rss feed of the +# data contained w/i + +# ini files should be: +# [.torrent file path] +# description="my description of the torrent" +# group="Name of group it belongs to" +# releasedate=2007-10-06 +# size=629M +# group is optional. if not listed group == description + +import ConfigParser +import sys +import glob +import time + +timeformat = "%Y-%m-%d" +rssformat = "%a, %d %b %Y %H:%M:%S" +globconf = '/etc/torrent_generator.conf' +if len(sys.argv) > 1: + globconf = sys.argv[1] +groups = {} + +def outputtime(etime): + return time.strftime(timeformat, time.localtime(etime)) + +def rsstime(etime): + return time.strftime(rssformat, time.localtime(etime)) + +def do_html_output(config, groups): + myout = open(config.htmlout, 'w') + head = open('%s' % config.htmlheader).read() + foot = open('%s' % config.htmlfooter).read() + + myout.write(head) + + for group in groups: + msg = """ + <tr> + <td colspan=4>%s</td> + </tr> + """ % group.name + myout.write(msg) + + t = group.torrents + t.sort() + t.reverse() + for torrent in t: + msg = """ + <tr> + <td valign=top><a href="%s/%s">%s</a></td> + <td valign=top>%s</td> + <td valign=top>%s</td> + <td valign=top>%s</td> + </tr> + """ % (config.torrent_url, torrent.torrent, torrent.torrent, torrent.description, torrent.size, outputtime(torrent.releasedate)) + myout.write(msg) + + myout.write(foot) + myout.close() + +def do_rss_output(config, groups): + + myout = open(config.rssout, 'w') + head = open('%s' % config.rssheader).read() + foot = open('%s' % config.rssfooter).read() + + myout.write(head) + + for group in groups: + for torrent in group.torrents: + msg = """<item> + <title>%s</title> + <link>%s/%s</link> + <pubDate>%s</pubDate> + </item>""" % (torrent.description, config.torrent_url, torrent.torrent, rsstime(torrent.releasedate)) + myout.write(msg) + myout.write(foot) + myout.close() + + +class Group(object): + def __init__(self, name, date): + self.name = name + self.releasedate = date + self.torrents = [] + + def __cmp__(self, other): + if other.releasedate > self.releasedate: + return -1 + if self.releasedate > other.releasedate: + return 1 + + return 0 + + +class Torrent(object): + def __init__(self): + self.torrent = None + self.group = None + self.releasedate = '1969-01-01' + self.size = None + self.description = None + + def __cmp__(self, other): + if other.releasedate > self.releasedate: + return -1 + if self.releasedate > other.releasedate: + return 1 + + return 0 + + +class Config(object): + def __init__(self, cpobj): + if not cpobj.has_section('main'): + print >> sys.stderr, "no main section in config, exiting" + sys.exit(1) + try: + self.inidir = cpobj.get('main', 'inidir') + self.torrent_url = cpobj.get('main', 'torrent_url') + self.htmlheader = cpobj.get('main', 'htmlheader') + self.htmlfooter = cpobj.get('main', 'htmlfooter') + self.rssheader = cpobj.get('main', 'rssheader') + self.rssfooter = cpobj.get('main', 'rssfooter') + self.htmlout = cpobj.get('main', 'htmlout') + self.rssout = cpobj.get('main', 'rssout') + except ConfigParser.NoOptionError, e: + print >> sys.stderr, "Config file missing required option: %s" % e + sys.exit(1) + +def main(): + + conf = ConfigParser.ConfigParser() + conf.read(globconf) + config = Config(conf) + + fs = glob.glob(config.inidir + '/*.ini') + for fn in fs: + c = ConfigParser.ConfigParser() + c.read(fn) + for s in c.sections(): + if 'releasedate' not in c.options(s) or 'description' not in c.options(s): + print >> sys.stderr, "bad torrent config for %s" % s + continue + if c.has_option(s,'group'): + g = c.get(s, 'group') + else: + g = c.get(s, 'description') + + thisdate = time.mktime(time.strptime(c.get(s, 'releasedate'), timeformat)) + if groups.has_key(g): + thisgroup = groups[g] + if thisgroup.releasedate < thisdate: + thisgroup.releasedate = thisdate + else: + thisgroup = Group(g, thisdate) + groups[thisgroup.name] = thisgroup + + this = Torrent() + this.torrent = s + this.group = g + this.releasedate = thisdate + if c.has_option(s, 'size'): + this.size = c.get(s, 'size') + else: + this.size = 'Unknown' + + this.description = c.get(s, 'description') + + thisgroup.torrents.append(this) + + sortgroups = groups.values() + sortgroups.sort() + sortgroups.reverse() + + do_html_output(config, sortgroups) + do_rss_output(config, sortgroups) + + +if __name__ == "__main__": + main() + diff --git a/scripts/torrent-generator/torrent_generator.conf b/scripts/torrent-generator/torrent_generator.conf new file mode 100644 index 0000000..6fc20d9 --- /dev/null +++ b/scripts/torrent-generator/torrent_generator.conf @@ -0,0 +1,9 @@ +[main] +inidir=/home/skvidal/python/torrent-generator/ +torrent_url=http://torrent.fedoraproject.org/torrents/ +htmlheader=/home/skvidal/python/torrent-generator/head.html +htmlfooter=/home/skvidal/python/torrent-generator/foot.html +rssheader=/home/skvidal/python/torrent-generator/head.rss +rssfooter=/home/skvidal/python/torrent-generator/foot.rss +htmlout=/home/skvidal/python/torrent-generator/index.html +rssout=/home/skvidal/python/torrent-generator/rss20.xml |