import logging
import os
import re
-import urllib.request, urllib.parse, urllib.error
+import tornado.gen
import urllib.parse
from . import database
# get all data from database
self.__data = data
- def __cmp__(self, other):
- return cmp(self.prio, other.prio)
+ def __eq__(self, other):
+ if isinstance(other, self.__class__):
+ return self.id == otherid
+
+ def __lt__(self, other):
+ if isinstance(other, self.__class__):
+ return self.prio < other.prio
@property
def data(self):
@property
def url(self):
- return urllib.parse.urljoin("https://downloads.ipfire.org", self.filename)
+ return urllib.parse.urljoin("https://downloads.ipfire.org", self.filename)
@property
def desc(self):
descriptions = {
"armv5tel" : _("Flash Image"),
"armv5tel-scon" : _("Flash Image with serial console"),
- "iso" : _("CD Image"),
+ "iso" : _("ISO Image"),
"torrent" : _("Torrent File"),
"flash" : _("Flash Image"),
"alix" : _("Flash Image with serial console"),
except KeyError:
return 999
- @property
- def rem(self):
- _ = lambda x: x
-
- remarks = {
- "armv5tel" : _("This image runs on many ARM-based boards"),
- "armv5tel-scon" : _("This image runs on ARM boards with a serial console"),
- "iso" : _("Use this image to burn a CD and install IPFire from it."),
- "torrent" : _("Download the CD image from the torrent network."),
- "flash" : _("An image that is meant to run on embedded devices."),
- "alix" : _("Flash image where a serial console is enabled by default."),
- "usbfdd" : _("Install IPFire from a floppy-formated USB key."),
- "usbhdd" : _("If the floppy image doesn't work, use this image instead."),
- "xen" : _("A ready-to-run image for Xen."),
- "xen-downloader": _("Generator for creating a Xen image."),
- }
-
- try:
- return remarks[self.type]
- except KeyError:
- return _("Unknown image type")
-
@property
def sha1(self):
return self.data.get("sha1")
def torrent_hash(self):
return self.data.get("torrent_hash", None)
- @property
- def torrent_url(self):
- if self.torrent_hash:
- return "%s.torrent" % self.url
+ @property
+ def torrent_url(self):
+ if self.torrent_hash:
+ return "%s.torrent" % self.url
@property
def magnet_link(self):
s += "&dn=%s" % urllib.parse.quote(self.basename)
# Add our tracker.
- for tracker in TRACKERS:
- s += "&tr=%s" % tracker
+ for tracker in TRACKERS:
+ s += "&tr=%s" % tracker
- # Add web download URL
- s += "&as=%s" % urllib.parse.quote(self.url)
+ # Add web download URL
+ s += "&as=%s" % urllib.parse.quote(self.url)
return s
if file.type == type:
return file
- def __file_hash(self, filename):
- sha1 = hashlib.sha1()
+ def __file_hash(self, filename, algo="sha256"):
+ h = hashlib.new(algo)
with open(filename) as f:
buf_size = 1024
buf = f.read(buf_size)
while buf:
- sha1.update(buf)
+ h.update(buf)
buf = f.read(buf_size)
- return sha1.hexdigest()
+ return h.hexdigest()
- def scan_files(self, basepath="/srv/mirror0"):
+ def scan_files(self, basepath="/pub/mirror"):
if not self.path:
return
continue
logging.info("Hashing %s..." % filename)
- filehash = self.__file_hash(filename)
+ hash_sha256 = self.__file_hash(filename, "sha256")
+ hash_sha1 = self.__file_hash(filename, "sha1")
filesize = os.path.getsize(filename)
# Check if there is a torrent download available for this file:
torrent_hash = self.torrent_read_hash(torrent_file)
self.db.execute("INSERT INTO files(releases, filename, filesize, \
- sha1, torrent_hash) VALUES(%s, %s, %s, %s, %s)",
- self.id, _filename, filesize, filehash, torrent_hash)
+ sha256, sha1, torrent_hash) VALUES(%s, %s, %s, %s, %s, %s)",
+ self.id, _filename, filesize, hash_sha256, hash_sha1, torrent_hash)
# Search for all files that miss a torrent hash.
files = self.db.query("SELECT id, filename FROM files \
assert self.supports_platform(platform)
if self.sname >= "ipfire-2.19-core100":
- return "https://downloads.ipfire.org/%s/images/%s/vmlinuz" % (self.path, arch)
+ return "https://boot.ipfire.org/%s/images/%s/vmlinuz" % (self.path, arch)
- return "https://downloads.ipfire.org/%s/images/vmlinuz" % self.path
+ return "https://boot.ipfire.org/%s/images/vmlinuz" % self.path
def netboot_initrd_url(self, arch, platform):
assert self.supports_arch(arch)
assert self.supports_platform(platform)
if self.sname >= "ipfire-2.19-core100":
- return "https://downloads.ipfire.org/%s/images/%s/instroot" % (self.path, arch)
+ return "https://boot.ipfire.org/%s/images/%s/instroot" % (self.path, arch)
- return "https://downloads.ipfire.org/%s/images/instroot" % self.path
+ return "https://boot.ipfire.org/%s/images/instroot" % self.path
def netboot_args(self, arch, platform):
return ""
@property
def penetration(self):
- penetration = self.memcache.get("%s-penetration" % self.sname)
-
- # Cache HIT
- if penetration:
- return penetration
-
# Get penetration from fireinfo
- penetration = self.backend.fireinfo.get_release_penetration(self)
-
- # Cache for 1 hour
- self.memcache.set("%s-penetration" % self.sname, penetration, 3600)
-
- return penetration
+ return self.backend.fireinfo.get_release_penetration(self)
class Releases(Object):
for row in res:
yield Release(self.backend, row.id, data=row)
+ def __iter__(self):
+ releases = self._get_releases("SELECT * FROM releases \
+ ORDER BY published DESC NULLS FIRST")
+
+ return iter(releases)
+
def get_by_id(self, id):
ret = self.db.get("SELECT * FROM releases WHERE id = %s", id)
file = File(self.backend, release, file.id)
return file
+
+ @tornado.gen.coroutine
+ def scan_files(self, basepath="/pub/mirror"):
+ for release in self:
+ logging.info("Scanning %s..." % release)
+ release.scan_files(basepath=basepath)