[Piuparts-devel] Bug#589498: [PATCH 1/2] check for settings.scriptsdir inside run_scripts()

Andreas Beckmann debian at abeckmann.de
Sat Nov 5 23:56:09 UTC 2011


move the check for settings.scriptsdir inside run_scripts(),
no need to replicate it before every call

Signed-off-by: Andreas Beckmann <debian at abeckmann.de>

---
 piuparts.py |   37 ++++++++++++++-----------------------
 1 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/piuparts.py b/piuparts.py
index a731af2..1a67fb1 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -612,8 +612,7 @@ class Chroot:
                     shutil.copy(os.path.join((settings.scriptsdir), sfile), dest) 
 
         # Run custom scripts after creating the chroot.
-        if settings.scriptsdir is not None: 
-            self.run_scripts("post_setup")
+        self.run_scripts("post_setup")
 
         if settings.savetgz:
             self.pack_into_tgz(settings.savetgz)
@@ -762,9 +761,8 @@ class Chroot:
         for distro in distros:
             logging.debug("Upgrading %s to %s" % (self.name, distro))
             self.create_apt_sources(distro)
-	    # Run custom scripts before upgrade
-            if settings.scriptsdir is not None:
-                self.run_scripts("pre_distupgrade")
+            # Run custom scripts before upgrade
+            self.run_scripts("pre_distupgrade")
             self.run(["apt-get", "update"])
             self.run(["apt-get", "-yf", "dist-upgrade"])
             # Sometimes dist-upgrade won't upgrade the packages we want
@@ -774,8 +772,7 @@ class Chroot:
             # packages. So, we force the installation like this.
             self.install_packages_by_name(packages)
             # Run custom scripts after upgrade
-            if settings.scriptsdir is not None:
-                self.run_scripts("post_distupgrade")
+            self.run_scripts("post_distupgrade")
             self.check_for_no_processes()
     
     def apt_get_knows(self, package_names):
@@ -830,8 +827,7 @@ class Chroot:
             tmp_files = [os.path.basename(a) for a in filenames]
             tmp_files = [os.path.join("tmp", name) for name in tmp_files]
 
-            if settings.scriptsdir is not None:
-                self.run_scripts("pre_install")
+            self.run_scripts("pre_install")
 
             if settings.list_installed_files:
                 pre_info = self.save_meta_data()
@@ -848,8 +844,7 @@ class Chroot:
 
             logging.info ("Installation of %s ok", tmp_files)
 
-            if settings.scriptsdir is not None:
-                self.run_scripts("post_install")
+            self.run_scripts("post_install")
 
             self.run(["apt-get", "clean"])
             remove_files([os.path.join(self.name, name) 
@@ -893,15 +888,13 @@ class Chroot:
                             if state == "purge"]
     
         # Run custom scripts before removing all packages. 
-	if settings.scriptsdir is not None:
-            self.run_scripts("pre_remove")	
+        self.run_scripts("pre_remove")
 
         # 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 removing all packages. 
-	if settings.scriptsdir is not None:
-            self.run_scripts("post_remove")	
+        self.run_scripts("post_remove")
 
         if not settings.skip_cronfiles_test:
             cronfiles, cronfiles_list = self.check_if_cronfiles(packages)
@@ -925,8 +918,7 @@ class Chroot:
         self.remove_or_purge("purge", nondeps_to_purge)
 
         # Run custom scripts after purge all packages.
-        if settings.scriptsdir is not None: 
-            self.run_scripts("post_purge")
+        self.run_scripts("post_purge")
 
         # Now do a final run to see that everything worked.
         self.run(["dpkg", "--purge", "--pending"])
@@ -975,8 +967,7 @@ class Chroot:
 
     def install_packages_by_name(self, packages):
         if packages:
-            if settings.scriptsdir is not None:
-                self.run_scripts("pre_install")
+            self.run_scripts("pre_install")
 
 	    if settings.list_installed_files:
                 pre_info = self.save_meta_data()
@@ -1158,6 +1149,8 @@ class Chroot:
     def run_scripts (self, step):
         """ Run custom scripts to given step post-install|remove|purge"""
 
+        if settings.scriptsdir is None:
+            return
         logging.info("Running scripts "+ step)
         basepath = self.relative("tmp/scripts/")
         if not os.path.exists(basepath):
@@ -1756,8 +1749,7 @@ def install_upgrade_test(chroot, root_info, selections, package_list, package_na
     # First install via apt-get.
     chroot.install_packages_by_name(package_names)
     
-    if settings.scriptsdir is not None:
-        chroot.run_scripts("pre_upgrade")
+    chroot.run_scripts("pre_upgrade")
 
     chroot.check_for_broken_symlinks()
 
@@ -1859,8 +1851,7 @@ def install_and_upgrade_between_distros(filenames, packages):
     chroot.run(["apt-get", "update"])
     chroot.install_packages_by_name(packages)
 
-    if settings.scriptsdir is not None:
-        chroot.run_scripts("pre_upgrade")
+    chroot.run_scripts("pre_upgrade")
 
     chroot.check_for_no_processes()
 
-- 
tg: (4f9e70a..) t/style/centralize-scriptsdir-check (depends on: develop)





More information about the Piuparts-devel mailing list