[Piuparts-commits] [SCM] piuparts git repository branch, master, updated. eda668423fa87898c59d1075118693714aa5a053

Holger Levsen holger at layer-acht.org
Fri Dec 23 10:25:12 UTC 2011


The following commit has been merged in the master branch:
commit ff8afbed3ef36a325bed3b9dec9ccf419a286d1b
Author: Holger Levsen <holger at layer-acht.org>
Date:   Mon Sep 26 21:16:14 2011 +0200

    piupartslib/packagesdb.py: rewrite uniqe() function by using the set type in place of a list and unique(),and then using set.pop() method in place  of random.shuffle(). Also modified the class to no longer pass large "package" objects around,  but rather to just pass list/set of package names (since I was "forced to",  since you cannot add a non-hashable object to a set). This required a new  function to return package object, given name as input.  This required one  change to piuparts-report and several to piuparts-master. (Closes: 640648)

diff --git a/debian/changelog b/debian/changelog
index 47e8408..adea1c5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -12,6 +12,16 @@ piuparts (0.42) UNRELEASED; urgency=low
   [ Holger Levsen ]
   * piuparts.py: apply patch by Stefano Rivera to properly install and remove
     logrotate. Thanks Stefano! (Closes: #638832)
+ 
+  [ Scott Schaefer ]
+  * piupartslib/packagesdb.py: rewrite uniqe() function by using the set type
+    in place of a list and unique(),and then using set.pop() method in place 
+    of random.shuffle().
+    Also modified the class to no longer pass large "package" objects around, 
+    but rather to just pass list/set of package names (since I was "forced to", 
+    since you cannot add a non-hashable object to a set). This required a new 
+    function to return package object, given name as input.  This required one 
+    change to piuparts-report and several to piuparts-master. (Closes: 640648)
 
  -- Holger Levsen <holger at debian.org>  Sun, 28 Aug 2011 09:50:12 +0200
 
diff --git a/piuparts-master.py b/piuparts-master.py
index 50f03fd..f90119e 100644
--- a/piuparts-master.py
+++ b/piuparts-master.py
@@ -152,8 +152,8 @@ class Master(Protocol):
                                      (count, command, " ".join(args)))
     def dump_pkgs(self):
          for st in self._binary_db.get_states():
-            for pkg in self._binary_db.get_pkg_names_in_state(st):
-                logging.debug("%s : %s\n" % (st,pkg))
+            for name in self._binary_db.get_pkg_names_in_state(st):
+                logging.debug("%s : %s\n" % (st,name))
 
     def _reserve(self, command, args):
         self._check_args(0, command, args)
diff --git a/piuparts-report.py b/piuparts-report.py
index a32b419..e3028a7 100644
--- a/piuparts-report.py
+++ b/piuparts-report.py
@@ -684,7 +684,7 @@ class Section:
         counts = current_day
         total = 0
         for state in self._binary_db.get_states():
-            count = len(self._binary_db.get_packages_in_state(state))
+            count = len(self._binary_db.get_pkg_names_in_state(state))
             header += ", %s" % state
             counts += ", %s" % count
             logging.debug("%s: %s" % (state, count))
@@ -952,7 +952,7 @@ class Section:
               analysis = self.create_and_link_to_analysises(state)
             tablerows += ("<tr class=\"normalrow\"><td class=\"contentcell2\"><a href='state-%s.html'>%s</a>%s</td>" +
                           "<td class=\"contentcell2\">%d</td><td class=\"contentcell2\">%s</td></tr>\n") % \
-                          (html_protect(state), html_protect(state), analysis, len(self._binary_db.get_packages_in_state(state)),
+                          (html_protect(state), html_protect(state), analysis, len(self._binary_db.get_pkg_names_in_state(state)),
                           dir_link)
         try:
           tablerows += self.make_stats_graph();
@@ -975,7 +975,8 @@ class Section:
         for state in self._binary_db.get_states():
             logging.debug("Writing page for %s" % state)
             vlist = ""
-            for package in self._binary_db.get_packages_in_state(state):
+            for name in self._binary_db.get_pkg_names_in_state(state):
+                package = self._binary_db.get_package(name)
                 vlist += "<li id=\"%s\">%s (%s)" % (
                                          package["Package"],
                                          self.link_to_source_summary(package["Package"]),
diff --git a/piupartslib/packagesdb.py b/piupartslib/packagesdb.py
index 75100c6..667485c 100644
--- a/piupartslib/packagesdb.py
+++ b/piupartslib/packagesdb.py
@@ -26,7 +26,6 @@ Lars Wirzenius <liw at iki.fi>
 
 import dircache
 import os
-import random
 import tempfile
 import UserDict
 
@@ -46,43 +45,6 @@ def rfc822_like_header_parse(input):
             headers.append(line)
     return headers
  
-def unique (s):
-    # taken from http://code.activestate.com/recipes/52560/ - thanks to Tim Peters
-    n = len(s)
-    if n == 0:
-      return []  
-
-    u = {}
-    try:
-      for x in s:
-          u[x] = 1
-    except TypeError:
-      del u  # move on to the next method
-    else:
-      return u.keys()
-
-    try:
-      t = list(s)
-      t.sort()
-    except TypeError:
-      del t  # move on to the next method
-    else:
-      assert n > 0
-      last = t[0]
-      lasti = i = 1
-      while i < n:
-          if t[i] != last:
-              t[lasti] = last = t[i]
-              lasti += 1
-          i += 1
-      return t[:lasti]
-
-    # Brute force is all that's left.
-    u = []
-    for x in s:
-      if x not in u:
-          u.append(x)
-    return u
 
 class Package(UserDict.UserDict):
 
@@ -502,11 +464,10 @@ class PackagesDB:
 
     def get_pkg_names_in_state(self, state):
         self._compute_package_states()
-        return self._in_state[state]
+        return set(self._in_state[state])
     
-    def get_packages_in_state(self, state):
-      self._compute_package_states()
-      return unique([self._packages[name] for name in self._in_state[state]])
+    def get_package(self, name):
+        return self._packages[name]
     
     def get_all_packages(self):
         self._find_all_packages()
@@ -548,14 +509,13 @@ class PackagesDB:
             return "unknown"
 
     def _find_packages_ready_for_testing(self):
-        return self.get_packages_in_state("waiting-to-be-tested")
+        return self.get_pkg_names_in_state("waiting-to-be-tested")
 
     def reserve_package(self):
-        plist = self._find_packages_ready_for_testing()
-        random.shuffle(plist)
-        for p in plist:
-            if self._logdb.create(self._reserved, p["Package"],
-                                  p["Version"], ""):
+        pset = self._find_packages_ready_for_testing()
+        while (len(pset)):
+            p = self.get_package(pset.pop())
+            if self._logdb.create(self._reserved, p["Package"], p["Version"], ""):
                 return p
         return None
 

-- 
piuparts git repository



More information about the Piuparts-commits mailing list