Package: piuparts
Version: 0.40
Severity: wishlist
Tags: patch


Primarily as debugging aid, but hopefully also useful in production
environment, the attached patch causes piuparts-master to produce a
"dump" of package states upon receipt of SIGUSR1 (tempfile name
written to configured 'master-directory').


-- System Information:
Debian Release: 6.0.1
  APT prefers stable
  APT policy: (990, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.32-5-686 (SMP w/4 CPU cores)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages piuparts depends on:
ii  apt                     0.8.10.3         Advanced front-end for dpkg
ii  debootstrap             1.0.26+squeeze1  Bootstrap a basic Debian system
ii lsb-release 3.2-23.2squeeze1 Linux Standard Base version report
ii  lsof                    4.81.dfsg.1-1    List open files
ii python 2.6.6-3+squeeze6 interactive high-level object-orie ii python-debian 0.1.18 Python modules to work with Debian

piuparts recommends no packages.

Versions of packages piuparts suggests:
ii ghostscript 8.71~dfsg2-9 The GPL Ghostscript PostScript/PDF
pn  python-rpy <none>       (no description available)

-- no debconf information

diff --git a/piuparts-master.py b/piuparts-master.py
--- a/piuparts-master.py
+++ b/piuparts-master.py
@@ -27,12 +27,24 @@
 import logging
 import ConfigParser
 import os
+import signal
+import tempfile 
 
 import piupartslib
 
 
 CONFIG_FILE = "/etc/piuparts/piuparts.conf"
 
+usr1_flag = 0;
+
+def usr1_handler(signum,frame):
+    global usr1_flag
+    flag = usr1_flag
+    if flag != 1:
+        usr1_flag = 1
+        if flag == 2:
+           raise IOError;
+
 
 def setup_logging(log_level, log_file_name):
     logger = logging.getLogger()
@@ -111,7 +123,7 @@
         "successfully-tested",
     )
 
-    def __init__(self, input, output, packages_file, known_circular_depends="", section=None):
+    def __init__(self, input, output, packages_file, known_circular_depends="", section=None, dir="."):
         Protocol.__init__(self, input, output)
         self._commands = {
             "reserve": self._reserve,
@@ -120,6 +132,7 @@
             "fail": self._fail,
             "untestable": self._untestable,
         }
+        self.basedir = dir
         self._binary_db = piupartslib.packagesdb.PackagesDB(prefix=section)
         self._binary_db.create_subdirs()
         self._binary_db.read_packages_file(packages_file)
@@ -135,7 +148,19 @@
         self._writeline("hello")
 
     def do_transaction(self):
-        line = self._readline()
+        global usr1_flag
+        flag = usr1_flag
+        line = None
+        if flag == 0:
+            usr1_flag = 2
+            try:
+              line = self._readline()
+            except IOError:
+              pass
+        flag = usr1_flag
+        if flag == 2:
+            usr1_flag = 0
+
         if line:
             parts = line.split()
             if len(parts) > 0:
@@ -144,16 +169,27 @@
                 self._commands[command](command, args)
             return True
         else:
-            return False
+            if flag == 1:
+                (h, fname) = tempfile.mkstemp(suffix='.dmp', dir=self.basedir)
+                self.dump_pkgs(h, fname)
+                usr1_flag = 0
+                return True
+            else:
+                return False
 
     def _check_args(self, count, command, args):
         if len(args) != count:
             raise CommandSyntaxError("Need exactly %d args: %s %s" %
                                      (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))
+
+    def dump_pkgs(self, oshndl, filename):
+         f = os.fdopen(oshndl, 'w')
+         if f:
+            logging.debug("SIGUSR1: Dumping package states to " + filename)
+            for st in self._binary_db.get_states():
+               for pkg in self._binary_db.get_pkg_names_in_state(st):
+                   f.write("%s : %s\n" % (pkg,st))
+            f.close()
 
     def _reserve(self, command, args):
         self._check_args(0, command, args)
@@ -208,7 +244,8 @@
         packages_file = piupartslib.open_packages_url(config["packages-url"])
         known_circular_depends = config["known_circular_depends"]
 
-        m = Master(sys.stdin, sys.stdout, packages_file, known_circular_depends, section=section)
+        m = Master(sys.stdin, sys.stdout, packages_file, known_circular_depends, section=section, dir=master_directory)
+        signal.signal(signal.SIGUSR1,usr1_handler)
         while m.do_transaction():
             pass
         packages_file.close()

Reply via email to