[Piuparts-devel] Bug#589498: [PATCH 5/5] allow multiple --scriptsdir options

Andreas Beckmann debian at abeckmann.de
Fri Nov 11 11:22:40 UTC 2011


content of the directories will be merged together in the chroot,
files with same name in later dirs will overwrite earlier ones,
script execution order is the ordering of the file names

Signed-off-by: Andreas Beckmann <debian at abeckmann.de>
---
 README.txt  |    3 +++
 piuparts.py |   30 ++++++++++++++++--------------
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/README.txt b/README.txt
index 6d00b25..45e6311 100644
--- a/README.txt
+++ b/README.txt
@@ -136,6 +136,9 @@ your package.
 You can specify several custom scripts to be run inside piuparts.
 You have to store them in a directory and give it as argument to
 piuparts: '--scriptsdir=/dir/with/the/scripts'
+This option can be given multiple times. The scripts from all
+directories will be merged together (and later ones may overwrite
+earlier scripts with the same filename).
 
 The script prefix determines in which step it is executed. You
 can run several scripts in every step, they are run in
diff --git a/piuparts.py b/piuparts.py
index 820e169..6eb931e 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -130,7 +130,7 @@ class Settings:
     def __init__(self):
         self.defaults = None
         self.tmpdir = None
-        self.scriptsdir = None
+        self.scriptsdirs = []
         self.keep_tmpdir = False
         self.single_changes_list = False
         # limit output of logfiles to the last megabyte:
@@ -602,15 +602,17 @@ class Chroot:
         self.minimize()
         self.run(["apt-get", "clean"])
 
-        #copy scripts dir into the chroot
-        if settings.scriptsdir is not None:
+        # Copy scripts dirs into the chroot, merging all dirs together,
+        # later files overwriting earlier ones.
+        if settings.scriptsdirs:
             dest = self.relative("tmp/scripts/")
             if not os.path.exists(self.relative("tmp/scripts/")):
                 os.mkdir(dest)
-            logging.debug("Copying scriptsdir to %s" % dest)
-            for sfile in os.listdir(settings.scriptsdir):
-                if (sfile.startswith("post_") or sfile.startswith("pre_")) and os.path.isfile(os.path.join((settings.scriptsdir), sfile)):
-                    shutil.copy(os.path.join((settings.scriptsdir), sfile), dest) 
+            for sdir in settings.scriptsdirs:
+                logging.debug("Copying scriptsdir %s to %s" % (sdir, dest))
+                for sfile in os.listdir(sdir):
+                    if (sfile.startswith("post_") or sfile.startswith("pre_")) and os.path.isfile(os.path.join(sdir, sfile)):
+                        shutil.copy(os.path.join(sdir, sfile), dest)
 
         # Run custom scripts after creating the chroot.
         self.run_scripts("post_setup")
@@ -1157,7 +1159,7 @@ class Chroot:
     def run_scripts (self, step):
         """ Run custom scripts to given step post-install|remove|purge"""
 
-        if settings.scriptsdir is None:
+        if not settings.scriptsdirs:
             return
         logging.info("Running scripts "+ step)
         basepath = self.relative("tmp/scripts/")
@@ -2095,7 +2097,8 @@ def parse_command_line():
                       help="Minimize chroot with debfoster. This used to be the default until #539142 was fixed.")
 
     parser.add_option("--scriptsdir", metavar="DIR",
-                      help="Directory where are placed the custom scripts.")
+                      action="append", default=[],
+                      help="Directory where are placed the custom scripts. Can be given multiple times.")
 
     parser.add_option("-t", "--tmpdir", metavar="DIR",
                       help="Use DIR for temporary storage. Default is " +
@@ -2207,11 +2210,10 @@ def parse_command_line():
         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)
+    settings.scriptsdirs = opts.scriptsdir
+    for sdir in settings.scriptsdirs:
+        if not os.path.isdir(sdir):
+            logging.error("Scripts directory is not a directory: %s" % sdir)
             panic()
 
     if not settings.debian_distros:
-- 
1.7.7.1






More information about the Piuparts-devel mailing list