[Piuparts-commits] rev 72 - trunk

Ana Beatriz Guerrero López ana at alioth.debian.org
Tue Aug 28 09:51:07 UTC 2007


Author: ana
Date: 2007-08-28 09:51:07 +0000 (Tue, 28 Aug 2007)
New Revision: 72

Modified:
   trunk/piuparts.py
Log:
Add custom scripts,  post-install|remove|purge only


Modified: trunk/piuparts.py
===================================================================
--- trunk/piuparts.py	2007-08-20 08:56:49 UTC (rev 71)
+++ trunk/piuparts.py	2007-08-28 09:51:07 UTC (rev 72)
@@ -56,6 +56,7 @@
     
     def __init__(self):
         self.tmpdir = None
+        self.scriptsdir = None
         self.keep_tmpdir = False
         self.max_command_output_size = 1024 * 1024
         self.args_are_package_files = True
@@ -125,7 +126,7 @@
             "/var/cache/debconf/templates.dat-old",
             "/var/cache/man/index.db",
             "/var/lib/apt/extended_states",
-			"/var/lib/dpkg/available", 
+            "/var/lib/dpkg/available", 
             "/var/lib/dpkg/available-old", 
             "/var/lib/dpkg/diversions",
             "/var/lib/dpkg/diversions-old",
@@ -166,6 +167,7 @@
             "/var/spool/squid(/.*)?",
             "/var/run/.*",
             "/var/www(/.*)?",
+            "/tmp/scripts(/.*)?"
             ]
 
 
@@ -601,6 +603,7 @@
                 self.run(["dpkg", "-i"] + tmp_files, ignore_errors=True)
                 self.run(["apt-get", "-yf", "--no-remove", "install"])
 
+            self.run_scripts("install")
 
             self.run(["apt-get", "clean"])
             remove_files([os.path.join(self.name, name) 
@@ -620,11 +623,12 @@
         for name in packages:
             self.run(["dpkg", "--" + operation, name], ignore_errors=True)
         self.run(["dpkg", "--remove", "--pending"], ignore_errors=True)
-    
+
+ 
     def restore_selections(self, changes, packages):
         """Restore package selections in a chroot by applying 'changes'.
            'changes' is a return value from diff_selections."""
-    
+ 
         deps = {}
         nondeps = {}
         for name, state in changes.iteritems():
@@ -645,6 +649,8 @@
         # First remove all packages.
         self.remove_or_purge("remove", deps_to_remove + deps_to_purge +
                                         nondeps_to_remove + nondeps_to_purge)
+        # Run custom scripts after remove all packages. 
+        self.run_scripts("remove")	
 
         if not settings.skip_cronfiles_test:
             cronfiles, cronfiles_list = self.check_if_cronfiles(packages)
@@ -654,10 +660,13 @@
 
         # Then purge all packages being depended on.
         self.remove_or_purge("purge", deps_to_purge)
-        
+
         # Finally, purge actual packages.
         self.remove_or_purge("purge", nondeps_to_purge)
-    
+
+        # Run custom scripts after purge all packages. 
+        self.run_scripts("purge")
+
         # Now do a final run to see that everything worked.
         self.run(["dpkg", "--purge", "--pending"])
         self.run(["dpkg", "--remove", "--pending"])
@@ -796,7 +805,22 @@
 
             self.run([file])
 
+    def run_scripts (self, step):
+        """ Run custom scripts to given step post-install|remove|purge"""
+	
+	if settings.scriptsdir is None:
+	    exit
+        logging.info("Running scripts post "+ step)
+        basepath = self.relative("tmp/scripts/")
+	list_scripts = os.listdir(basepath)
+	list_scripts.sort()
+        for file in list_scripts:
+		if file.startswith("post_"+step):
+                    script = os.path.join("tmp/scripts", file)
+                    self.run([script]) 
 
+
+
 def objects_are_different(pair1, pair2):
     """Are filesystem objects different based on their meta data?"""
     (m1, target1) = pair1
@@ -1180,7 +1204,10 @@
     parser.add_option("--skip-cronfiles-test", 
                       action="store_true", default=False,
                       help="Skip testing the output from the cron files.")
-		      
+
+    parser.add_option("--scriptsdir", metavar="DIR",
+                      help="Directory where are placed the custom scripts.")
+    
     parser.add_option("-l", "--log-file", metavar="FILENAME",
                       help="Write log file to FILENAME in addition to " +
                            "the standard output.")
@@ -1257,6 +1284,13 @@
         else:
             settings.tmpdir = "/tmp"
 
+    if opts.scriptsdir is not None:
+        settings.scriptsdir = opts.scriptsdir
+	if not os.path.isdir(settings.scriptsdir):
+            logging.error("Scripts directory is not a directory: %s" % 
+                          settings.scriptsdir)
+            panic()
+
     if not settings.debian_distros:
         settings.debian_distros = ["sid"]
 
@@ -1312,6 +1346,14 @@
         root_info = chroot.save_meta_data()
         selections = chroot.get_selections()
     
+        #copy scripts dir into the chroot
+        if settings.scriptsdir is not None:
+            dest = chroot.relative("tmp/scripts/")
+            os.mkdir(dest)
+            for file in os.listdir(settings.scriptsdir):
+                if file.startswith("post_") and os.path.isfile(os.path.join((settings.scriptsdir), file)):
+                    shutil.copy(os.path.join((settings.scriptsdir), file), dest) 
+
         if not install_purge_test(chroot, root_info, selections,
 				  args, packages):
             logging.error("FAIL: Installation and purging test.")




More information about the Piuparts-commits mailing list