]> git.ipfire.org Git - ipfire.org.git/commitdiff
mirror lists: Enhance functionality.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 30 Jun 2013 16:45:08 +0000 (18:45 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 30 Jun 2013 16:45:08 +0000 (18:45 +0200)
* Add option to skip some hosts.
* Add option for development lists.

webapp/backend/mirrors.py
webapp/handlers_mirrors.py

index 4f6fc665d305988a4bf45fc4fa03ed1336a53793..10159458c62122272ab0f150f472a3a648c5dc82 100644 (file)
@@ -109,6 +109,16 @@ class Mirrors(object):
        def get_all(self):
                return MirrorSet(self.list())
 
+       def get_all_up(self):
+               res = self.db.query("SELECT * FROM mirrors WHERE disabled = %s AND state = %s ORDER BY hostname", "N", "UP")
+
+               mirrors = []
+               for row in res:
+                       m = Mirror(row.id, row)
+                       mirrors.append(m)
+
+               return MirrorSet(mirrors)
+
        def get_by_hostname(self, hostname):
                mirror = self.db.get("SELECT id FROM mirrors WHERE hostname=%s", hostname)
 
@@ -270,10 +280,14 @@ class MirrorSet(object):
 
 
 class Mirror(object):
-       def __init__(self, id):
+       def __init__(self, id, data=None):
                self.id = id
 
-               self.reload()
+               if data:
+                       self._info = data
+               else:
+                       self._info = self.db.get("SELECT * FROM mirrors WHERE id = %s", self.id)
+               self._info["url"] = self.generate_url()
 
                self.__location = None
                self.__country_name = None
@@ -288,20 +302,6 @@ class Mirror(object):
        def db(self):
                return Databases().webapp
 
-       def reload(self, force=False):
-               memcached = Memcached()
-               mem_id = "mirror-%s" % self.id
-
-               if force:
-                       memcached.delete(mem_id)
-
-               self._info = memcached.get(mem_id)
-               if not self._info:
-                       self._info = self.db.get("SELECT * FROM mirrors WHERE id=%s", self.id)
-                       self._info["url"] = self.generate_url()
-
-                       memcached.set(mem_id, self._info, 60)
-
        def generate_url(self):
                url = "http://%s" % self.hostname
                if not self.path.startswith("/"):
@@ -397,7 +397,8 @@ class Mirror(object):
                        state, self.id)
 
                # Reload changed settings
-               self.reload(force=True)
+               if hasattr(self, "_info"):
+                       self._info["state"] = state
 
        def check(self):
                logging.info("Running check for mirror %s" % self.hostname)
@@ -444,7 +445,8 @@ class Mirror(object):
                        timestamp, self.id)
 
                # Reload changed settings
-               self.reload(force=True)
+               if hasattr(self, "_info"):
+                       self._info["timestamp"] = timestamp
 
                self.check_state()
 
@@ -537,3 +539,11 @@ class Mirror(object):
 
        def is_pakfire2(self):
                return self.type in ("full", "pakfire2")
+
+       @property
+       def development(self):
+               return self._info.get("development", "N") == "Y"
+
+       @property
+       def mirrorlist(self):
+               return self._info.get("mirrorlist", "N") == "Y"
index 8278ee0d7fa5ab62aa51cbf388f5e1bf178c35ed..70973d643d5ca3f3854d49279ffdebd0f3303607 100644 (file)
@@ -56,14 +56,21 @@ class MirrorDetailHandler(BaseHandler):
 class MirrorListPakfire2Handler(BaseHandler):
        def get(self):
                suffix = self.get_argument("suffix", "")
+               development = self.get_argument("development", None)
 
                self.set_header("Content-Type", "text/plain")
 
-               mirrors = self.mirrors.get_all()
+               # Get all mirror servers that are currently up.
+               mirrors = self.mirrors.get_all_up()
 
                lines = []
                for m in mirrors:
-                       if not m.is_pakfire2():
+                       if not m.mirrorlist or not m.is_pakfire2():
+                               continue
+
+                       # Skip all non-development mirrors
+                       # if we run in development mode.
+                       if development and not m.development:
                                continue
 
                        path = [m.path,]