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

Attached patch resolves two items:

1) From TODO ...

piuparts-slave: if chroot.tgz is older than N days, regenerate it
- currently this is done via ~piupartss/crontab, but that's a hack
- only throw away tarballs (and recreate them) after testing that they can be 
recreated

I hard-coded the MAX_TGZ_AGE at 30 days.  Log entry is written when the
file is recreated due to becoming too old. The "old" file is renamed to .old so that, should the new file fail to be created, it is simply renamed back and processing
continues.

piatti crontab entry should be removed after install.


2) Bug in piuparts-slave which prevented running a single section (by including
section name as command-line argument).

Variable 'global_config' was initialized only if len(sys.argv) > 1. This would cause python exception and exit when gloval_config was accessed in call to section.setup()



-- 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-slave.py b/piuparts-slave.py
--- a/piuparts-slave.py
+++ b/piuparts-slave.py
@@ -25,17 +25,17 @@
 
 import os
 import sys
+import stat
 import time
 import logging
 import ConfigParser
-import urllib
-
 
 import piupartslib.conf
 import piupartslib.packagesdb
 
 
 CONFIG_FILE = "/etc/piuparts/piuparts.conf"
+MAX_TGZ_AGE = 60*60*24*30
 
 
 def setup_logging(log_level, log_file_name):
@@ -235,13 +235,15 @@
         if self._config["chroot-tgz"] and not self._config["distro"]:
           logging.info("The option --chroot-tgz needs --distro.")
 
-        if self._config["chroot-tgz"] and not os.path.exists(self._config["chroot-tgz"]):
-            create_chroot(self._config, self._config["chroot-tgz"], self._config["distro"])
+        tarball = self._config["chroot-tgz"]
+        if tarball:
+            create_or_replace_chroot_tgz(self._config, tarball,
+                       MAX_TGZ_AGE, self._config["distro"])
 
-        if (self._config["upgrade-test-distros"] and self._config["upgrade-test-chroot-tgz"]
-            and not os.path.exists(self._config["upgrade-test-chroot-tgz"])):
-            create_chroot(self._config, self._config["upgrade-test-chroot-tgz"], 
-                        self._config["upgrade-test-distros"].split()[0])
+        tarball = self._config["upgrade-test-chroot-tgz"]
+        if self._config["upgrade-test-distros"] and tarball: 
+            create_or_replace_chroot_tgz(self._config, tarball,
+                       MAX_TGZ_AGE, self._config["upgrade-test-distros"].split()[0])
     
         for rdir in ["new", "pass", "fail"]:
             rdir = os.path.join(self._slave_directory, rdir)
@@ -416,6 +418,19 @@
     f.close()
     os.rename(tarball + ".new", tarball)
 
+def create_or_replace_chroot_tgz(config, tgz, max_age, distro):
+    age = 0 
+    if os.path.exists(tgz):
+        age = time.time() - os.stat(tgz)[stat.ST_CTIME]
+        if age > max_age:
+            os.rename(tgz, tgz + ".old")
+            logging.info("%s too old.  Renaming to force re-creation" % tgz)
+    if not os.path.exists(tgz):
+        create_chroot(config, tgz, distro)
+        if not os.path.exists(tgz) and age > 0 and age > max_age:
+            os.rename(tgz + ".old", tgz)
+            logging.info("Failed to create ... reverting to old %s" % tgz)
+            create_chroot(config, tgz, distro)
 
 def fetch_packages_file(config, distro):
     mirror = config["mirror"]
@@ -448,11 +463,11 @@
     # argument referring to a section in configuration file.  
     # If no argument is given, the "global" section is assumed.
     section_names = []
+    global_config = Config(section="global")
+    global_config.read(CONFIG_FILE)
     if len(sys.argv) > 1:
         section_names = sys.argv[1:]
     else:
-        global_config = Config(section="global")
-        global_config.read(CONFIG_FILE)
         section_names = global_config["sections"].split()
 
     sections = []

Reply via email to