Package: piuparts
Version: 0.41
Severity: wishlist
Tags: patch
Attached patch addresses TODO item in sbuject.
I chose to implement this by using the set type in place of a list and
unique(),
and then using set.pop() method in place of random.shuffle().
I 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.
diff --git a/piuparts-master.py b/piuparts-master.py
--- a/piuparts-master.py
+++ b/piuparts-master.py
@@ -152,8 +152,8 @@
(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
--- a/piuparts-report.py
+++ b/piuparts-report.py
@@ -684,7 +684,7 @@
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 @@
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 @@
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
--- a/piupartslib/packagesdb.py
+++ b/piupartslib/packagesdb.py
@@ -26,7 +26,6 @@
import dircache
import os
-import random
import tempfile
import UserDict
@@ -46,43 +45,6 @@
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 @@
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 @@
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