]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/releases.py
backend: show checksum on thank-you page
[ipfire.org.git] / src / backend / releases.py
index 6b37e23cafde5ce26552698c6bbae0b9c885233c..895c6ca300690dad5f4f9d4ab84fe129195b36ce 100644 (file)
@@ -4,21 +4,12 @@ import hashlib
 import logging
 import os
 import re
-import tornado.gen
 import urllib.parse
-import yabencode
 
 from . import database
 from .misc import Object
 from .decorators import *
 
-TRACKERS = (
-    "http://ipv4.tracker.ipfire.org:6969/announce",
-    "udp://ipv4.tracker.ipfire.org:6969",
-    "http://ipv6.tracker.ipfire.org:6969/announce",
-    "udp://ipv6.tracker.ipfire.org:6969",
-)
-
 class File(Object):
        def __init__(self, backend, release, id, data=None):
                Object.__init__(self, backend)
@@ -60,9 +51,6 @@ class File(Object):
                if filename.endswith(".iso"):
                        return "iso"
 
-               elif filename.endswith(".torrent"):
-                       return "torrent"
-
                elif "xen" in filename:
                        if "downloader" in filename:
                                return "xen-downloader"
@@ -105,7 +93,6 @@ class File(Object):
                        "armv5tel"      : _("Flash Image"),
                        "armv5tel-scon" : _("Flash Image with serial console"),
                        "iso"           : _("ISO Image"),
-                       "torrent"       : _("Torrent File"),
                        "flash"         : _("Flash Image"),
                        "alix"          : _("Flash Image with serial console"),
                        "usbfdd"        : _("USB FDD Image"),
@@ -123,7 +110,6 @@ class File(Object):
        def prio(self):
                priorities = {
                        "iso"           : 10,
-                       "torrent"       : 20,
                        "flash"         : 40,
                        "alix"          : 41,
                        "usbfdd"        : 31,
@@ -133,7 +119,7 @@ class File(Object):
                        "xen"           : 50,
                        "xen-downloader": 51,
                }
-               
+
                try:
                        return priorities[self.type]
                except KeyError:
@@ -161,7 +147,7 @@ class File(Object):
 
        @property
        def arch(self):
-               known_arches = ("x86_64", "i586", "arm")
+               known_arches = ("x86_64", "aarch64", "arm", "i586")
 
                for arch in known_arches:
                        if arch in self.basename:
@@ -169,35 +155,6 @@ class File(Object):
 
                return "N/A"
 
-       @property
-       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 magnet_link(self):
-               # Don't return anything if we have no torrent hash.
-               if self.torrent_hash is None:
-                       return
-
-               s = "magnet:?xt=urn:btih:%s" % self.torrent_hash
-
-               #s += "&xl=%d" % self.size
-               s += "&dn=%s" % urllib.parse.quote(self.basename)
-
-               # Add our tracker.
-               for tracker in TRACKERS:
-                       s += "&tr=%s" % tracker
-
-               # Add web download URL
-               s += "&as=%s" % urllib.parse.quote(self.url)
-
-               return s
-
 
 class Release(Object):
        def __init__(self, backend, id, data=None):
@@ -225,6 +182,42 @@ class Release(Object):
                        if arch in (f.arch for f in self.files):
                                yield arch
 
+       @property
+       def primary_arches(self):
+               arches = []
+
+               # Add x86_64 when available, otherwise add i586
+               for arch in ("x86_64", "i586"):
+                       if arch in self.arches:
+                               arches.append(arch)
+                               break
+
+               # Add aarch64 if available
+               if "aarch64" in self.arches:
+                       arches.append("aarch64")
+
+               # Add ARM before 2.27 if available
+               if "arm" in self.arches and self.sname < "ipfire-2.27-core159":
+                       arches.append("arm")
+
+               return arches
+
+       @property
+       def secondary_arches(self):
+               arches = []
+
+               for arch in self.arches:
+                       if arch in self.primary_arches:
+                               continue
+
+                       arches.append(arch)
+
+               return arches
+
+       @property
+       def experimental_arches(self):
+               return []
+
        @property
        def files(self):
                if not self.__files:
@@ -241,18 +234,6 @@ class Release(Object):
                        if f.arch == arch:
                                yield f
 
-       @property
-       def torrents(self):
-               torrents = []
-
-               for file in self.files:
-                       if not file.torrent_hash:
-                               continue
-
-                       torrents.append(file)
-
-               return torrents
-
        @property
        def name(self):
                return self.__data.name
@@ -269,16 +250,6 @@ class Release(Object):
                if self.__data.blog_id:
                        return self.backend.blog.get_by_id(self.__data.blog_id)
 
-       @property
-       def fireinfo_id(self):
-               name = self.sname.replace("ipfire-", "IPFire ").replace("-", " - ")
-
-               res = self.db.get("SELECT id FROM fireinfo_releases \
-                       WHERE name = %s", name)
-
-               if res:
-                       return res.id
-
        @property
        def stable(self):
                return self.__data.stable
@@ -337,7 +308,7 @@ class Release(Object):
                        if _filename in files:
                                continue
 
-                       if filename.endswith(".md5"):
+                       if filename.endswith(".b2") or filename.endswith(".md5"):
                                continue
 
                        logging.info("Hashing %s..." % filename)
@@ -345,39 +316,9 @@ class Release(Object):
                        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 = ""
-                       torrent_file = "%s.torrent" % filename
-                       if os.path.exists(torrent_file):
-                               torrent_hash = self.torrent_read_hash(torrent_file)
-
                        self.db.execute("INSERT INTO files(releases, filename, filesize, \
-                               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 \
-                       WHERE releases = %s AND torrent_hash IS NULL", self.id)
-
-               for file in files:
-                       path = os.path.join(basepath, file.filename)
-
-                       torrent_file = "%s.torrent" % path
-                       if os.path.exists(torrent_file):
-                               torrent_hash = self.torrent_read_hash(torrent_file)
-
-                               self.db.execute("UPDATE files SET torrent_hash = %s WHERE id = %s",
-                                       torrent_hash, file.id)
-
-       def torrent_read_hash(self, filename):
-               with open(filename, "rb") as f:
-                       metainfo = yabencode.decode(f)
-                       metainfo = yabencode.encode(metainfo["info"])
-
-                       h = hashlib.new("sha1")
-                       h.update(metainfo)
-
-                       return h.hexdigest()
+                               sha256, sha1) VALUES(%s, %s, %s, %s, %s)",
+                               self.id, _filename, filesize, hash_sha256, hash_sha1)
 
        def supports_arch(self, arch):
                return arch in ("x86_64", "i586")
@@ -420,10 +361,13 @@ class Release(Object):
 
        # Fireinfo Stuff
 
-       @property
-       def penetration(self):
+       def get_usage(self, when=None):
+               name = self.sname.replace("ipfire-", "IPFire ").replace("-", " - ")
+
                # Get penetration from fireinfo
-               return self.backend.fireinfo.get_release_penetration(self)
+               releases = self.backend.fireinfo.get_releases_map(when=when)
+
+               return releases.get(name, 0)
 
 
 class Releases(Object):
@@ -532,22 +476,15 @@ class Releases(Object):
 
                return releases
 
-       def get_file_for_torrent_hash(self, torrent_hash):
-               file = self.db.get("SELECT id, releases FROM files WHERE torrent_hash = %s LIMIT 1",
-                       torrent_hash)
-
-               if not file:
-                       return
-
-               release = Release(self.backend, file.releases)
-               file = File(self.backend, release, file.id)
-
-               return file
-
-       @tornado.gen.coroutine
-       def scan_files(self, basepath="/pub/mirror"):
+       async def scan_files(self, basepath="/pub/mirror"):
                for release in self:
                        logging.debug("Scanning %s..." % release)
 
                        with self.db.transaction():
                                release.scan_files(basepath=basepath)
+
+       def get_file_by_filename(self, filename):
+               ret = self.db.get("SELECT * FROM files WHERE filename = %s", filename)
+
+               if ret:
+                       return File(self.backend, None, ret.id, data=ret)