]> git.ipfire.org Git - people/jschlag/pbs.git/blobdiff - src/buildservice/mirrors.py
Refacor iterating through all mirrors
[people/jschlag/pbs.git] / src / buildservice / mirrors.py
index aefa7862a72eef195094b9ac5c918492f63e4ba1..df6576a35526483586bbfb58293be2f8e49796eb 100644 (file)
@@ -17,23 +17,24 @@ log.propagate = 1
 from .decorators import lazy_property
 
 class Mirrors(base.Object):
-       def __iter__(self):
-               res = self.db.query("SELECT * FROM mirrors \
-                       WHERE deleted IS FALSE ORDER BY hostname")
-
-               mirrors = []
-               for row in res:
-                       mirror = Mirror(self.backend, row.id, data=row)
-                       mirrors.append(mirror)
-
-               return iter(mirrors)
-
        def _get_mirror(self, query, *args):
                res = self.db.get(query, *args)
 
                if res:
                        return Mirror(self.backend, res.id, data=res)
 
+       def _get_mirrors(self, query, *args):
+               res = self.db.query(query, *args)
+
+               for row in res:
+                       yield Mirror(self.backend, row.id, data=row)
+
+       def __iter__(self):
+               mirrors = self._get_mirrors("SELECT * FROM mirrors \
+                       WHERE deleted IS FALSE ORDER BY hostname")
+
+               return iter(mirrors)
+
        def create(self, hostname, path="", owner=None, contact=None, user=None):
                mirror = self._get_mirror("INSERT INTO mirrors(hostname, path, owner, contact) \
                        VALUES(%s, %s, %s, %s) RETURNING *", hostname, path, owner, contact)