Add run_controller_action() function and replace manual calls to controller file
authorAndrew Gaffney <agaffney@gentoo.org>
Wed, 14 Jan 2009 14:13:24 +0000 (08:13 -0600)
committerAndrew Gaffney <agaffney@gentoo.org>
Wed, 14 Jan 2009 14:13:24 +0000 (08:13 -0600)
ChangeLog
modules/catalyst/target/embedded.py
modules/catalyst/target/generic.py
modules/catalyst/target/generic_stage.py
modules/catalyst/target/grp.py
modules/catalyst/target/netboot.py
modules/catalyst/target/tinderbox.py

index 4aa49609980bd333b5f24061c35e27abe6847e4a..71ffcb75d1f2453eb17bf3cf461f422c73df30f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,13 @@
 # Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS)
 # Distributed under the GPL v2
 
+  14 Jan 2009; Andrew Gaffney <agaffney@gentoo.org>
+  modules/catalyst/target/embedded.py, modules/catalyst/target/generic.py,
+  modules/catalyst/target/generic_stage.py, modules/catalyst/target/grp.py,
+  modules/catalyst/target/netboot.py, modules/catalyst/target/tinderbox.py:
+  Add run_controller_action() function and replace manual calls to
+  controller file
+
   14 Jan 2009; Andrew Gaffney <agaffney@gentoo.org>
   modules/catalyst/spawn.py, targets/system/system-controller.sh:
   Add clean no-op for system target
index ae4ec18b805ef6f9d2885c04d1c721d0f91adbb0..11d0bafee7734a09cbd8ebf91c0afa3e864c11b7 100644 (file)
@@ -19,7 +19,7 @@ class embedded_target(generic_stage_target):
                self.valid_values = ["empty","rm","unmerge","fs-prepare","fs-finish","mergeroot","packages","fs-type"]
                self.valid_values += ["runscript","boot/kernel","linuxrc", "use", "fs-ops"]
 
-               generic_stage_target.__init__()
+               generic_stage_target.__init__(self)
 
        def set_action_sequence(self):
                self.settings["action_sequence"]=["dir_setup","unpack","unpack_snapshot",\
index 20b84224f5d2306be0ba97c2507423687801a47b..55212015d4a4632a201474d1de0fd9e36c678e35 100644 (file)
@@ -5,6 +5,7 @@ The toplevel class for generic_stage_target. This is about as generic as we get.
 import os
 import catalyst
 from catalyst.output import *
+from catalyst.spawn import cmd
 
 class generic_target:
 
@@ -52,3 +53,12 @@ class generic_target:
                        myf.close()
                else:
                        catalyst.util.touch(self.settings["autoresume_path"] + step)
+
+       def run_controller_action(self, action, args=""):
+               if os.path.exists(self.settings["controller_file"]):
+                       command = action
+                       if args:
+                               command += " " + args
+                       cmd("/bin/bash " + self.settings["controller_file"] + " " + command, \
+                               action + " script failed.", env=self.env)
+
index 0bee86b52de1da5bf44cab32a640e19f84d7a5be..43902ee3aea78eb6880987782816d6da5ace1b2c 100644 (file)
@@ -927,19 +927,15 @@ class generic_stage_target(generic_target):
                        msg("Resume point detected, skipping fsscript operation...")
                else:
                        if "fsscript" in self.settings:
-                               if os.path.exists(self.settings["controller_file"]):
-                                       cmd("/bin/bash "+self.settings["controller_file"]+\
-                                               " fsscript","fsscript script failed.",env=self.env)
-                                       self.set_autoresume("fsscript")
+                               self.run_controller_action("fsscript")
+                               self.set_autoresume("fsscript")
 
        def rcupdate(self):
                if self.check_autoresume("rcupdate"):
                        msg("Resume point detected, skipping rcupdate operation...")
                else:
-                       if os.path.exists(self.settings["controller_file"]):
-                               cmd("/bin/bash "+self.settings["controller_file"]+" rc-update",\
-                                       "rc-update script failed.",env=self.env)
-                               self.set_autoresume("rcupdate")
+                       self.run_controller_action("rc-update")
+                       self.set_autoresume("rcupdate")
 
        def clean(self):
                if self.check_autoresume("clean"):
@@ -970,10 +966,8 @@ class generic_stage_target(generic_target):
                                "/etc -maxdepth 1 -name \"*-\" | xargs rm -f",\
                                "Could not remove stray files in /etc",env=self.env)
 
-               if os.path.exists(self.settings["controller_file"]):
-                       cmd("/bin/bash "+self.settings["controller_file"]+" clean",\
-                               "clean script failed.",env=self.env)
-                       self.set_autoresume("clean")
+               self.run_controller_action("clean")
+               self.set_autoresume("clean")
 
        def empty(self):
                if self.check_autoresume("empty"):
@@ -1013,10 +1007,8 @@ class generic_stage_target(generic_target):
                                        msg("livecd: removing " + x)
                                        os.system("rm -rf "+self.settings["chroot_path"]+x)
                                try:
-                                       if os.path.exists(self.settings["controller_file"]):
-                                               cmd("/bin/bash "+self.settings["controller_file"]+\
-                                                       " clean","Clean  failed.",env=self.env)
-                                               self.set_autoresume("remove")
+                                       self.run_controller_action("clean")
+                                       self.set_autoresume("remove")
                                except:
                                        self.unbind()
                                        raise
@@ -1026,10 +1018,8 @@ class generic_stage_target(generic_target):
                        msg("Resume point detected, skipping preclean operation...")
                else:
                        try:
-                               if os.path.exists(self.settings["controller_file"]):
-                                       cmd("/bin/bash "+self.settings["controller_file"]+\
-                                               " preclean","preclean script failed.",env=self.env)
-                                       self.set_autoresume("preclean")
+                               self.run_controller_action("preclean")
+                               self.set_autoresume("preclean")
 
                        except:
                                self.unbind()
@@ -1064,10 +1054,8 @@ class generic_stage_target(generic_target):
                        msg("Resume point detected, skipping run_local operation...")
                else:
                        try:
-                               if os.path.exists(self.settings["controller_file"]):
-                                       cmd("/bin/bash "+self.settings["controller_file"]+" run",\
-                                               "run script failed.",env=self.env)
-                                       self.set_autoresume("run_local")
+                               self.run_controller_action("run")
+                               self.set_autoresume("run_local")
 
                        except CatalystError:
                                self.unbind()
@@ -1151,9 +1139,7 @@ class generic_stage_target(generic_target):
 
                                """ Before cleaning, unmerge stuff """
                                try:
-                                       cmd("/bin/bash "+self.settings["controller_file"]+\
-                                               " unmerge "+ myunmerge,"Unmerge script failed.",\
-                                               env=self.env)
+                                       self.run_controller_action("unmerge")
                                        msg("unmerge shell script")
                                except CatalystError:
                                        self.unbind()
@@ -1165,9 +1151,7 @@ class generic_stage_target(generic_target):
                        msg("Resume point detected, skipping target_setup operation...")
                else:
                        msg("Setting up filesystems per filesystem type")
-                       cmd("/bin/bash "+self.settings["controller_file"]+\
-                               " target_image_setup "+ self.settings["target_path"],\
-                               "target_image_setup script failed.",env=self.env)
+                       self.run_controller_action("target_image_setup")
                        self.set_autoresume("target_setup")
 
        def setup_overlay(self):
@@ -1189,9 +1173,7 @@ class generic_stage_target(generic_target):
                else:
                        """ Create the ISO """
                        if "iso" in self.settings:
-                               cmd("/bin/bash "+self.settings["controller_file"]+" iso "+\
-                                       self.settings["iso"],"ISO creation script failed.",\
-                                       env=self.env)
+                               self.run_controller_action("iso", self.settings["iso"])
                                catalyst.hash.gen_contents_file(self.settings["iso"], self.settings)
                                catalyst.hash.gen_digest_file(self.settings["iso"], self.settings)
                                self.set_autoresume("create_iso")
@@ -1207,9 +1189,7 @@ class generic_stage_target(generic_target):
                                mypack = \
                                        catalyst.util.list_bashify(self.settings["packages"])
                                try:
-                                       cmd("/bin/bash "+self.settings["controller_file"]+\
-                                               " build_packages "+mypack,\
-                                               "Error in attempt to build packages",env=self.env)
+                                       self.run_controller_action("build_packages", mypack)
                                        self.set_autoresume("build_packages")
                                except CatalystError:
                                        self.unbind()
@@ -1227,9 +1207,7 @@ class generic_stage_target(generic_target):
                                        """
                                        Execute the script that sets up the kernel build environment
                                        """
-                                       cmd("/bin/bash "+self.settings["controller_file"]+\
-                                               " pre-kmerge ","Runscript pre-kmerge failed",\
-                                               env=self.env)
+                                       self.run_controller_action("pre-kmerge")
 
                                        for kname in mynames:
                                                if self.check_autoresume("build_kernel_" + kname):
@@ -1306,9 +1284,7 @@ class generic_stage_target(generic_target):
                                                                                "/initramfs_overlay"],env=self.env)
 
                                                        """ Execute the script that builds the kernel """
-                                                       cmd("/bin/bash "+self.settings["controller_file"]+\
-                                                               " kernel "+kname,\
-                                                               "Runscript kernel build failed",env=self.env)
+                                                       self.run_controller_action("kernel", kname)
 
                                                        if self.settings.has_key("boot/kernel/"+kname+\
                                                                "/initramfs_overlay"):
@@ -1324,9 +1300,7 @@ class generic_stage_target(generic_target):
                                                        Execute the script that cleans up the kernel build
                                                        environment
                                                        """
-                                                       cmd("/bin/bash "+self.settings["controller_file"]+\
-                                                               " post-kmerge ",
-                                                               "Runscript post-kmerge failed",env=self.env)
+                                                       self.run_controller_action("post-kmerge")
 
                                        self.set_autoresume("build_kernel")
 
@@ -1340,9 +1314,7 @@ class generic_stage_target(generic_target):
                        msg("Resume point detected, skipping bootloader operation...")
                else:
                        try:
-                               cmd("/bin/bash "+self.settings["controller_file"]+\
-                                       " bootloader " + self.settings["target_path"],\
-                                       "Bootloader script failed.",env=self.env)
+                               self.run_controller_action("bootloader", self.settings["target_path"])
                                self.set_autoresume("bootloader")
                        except CatalystError:
                                self.unbind()
@@ -1353,9 +1325,7 @@ class generic_stage_target(generic_target):
                        msg("Resume point detected, skipping build_packages operation...")
                else:
                        try:
-                               cmd("/bin/bash "+self.settings["controller_file"]+\
-                                       " livecd-update","livecd-update failed.",env=self.env)
-                               self.set_autoresume("livecd_update")
+                               self.run_controller_action("livecd-update")
 
                        except CatalystError:
                                self.unbind()
index f29437ea2f0a8aee420e3d421bc8c3d84d928217..c7348083c9b81c77e4e01cfe4fac379bb70521e1 100644 (file)
@@ -12,28 +12,28 @@ from catalyst.output import *
 
 class grp_target(generic_stage_target):
        def __init__(self):
+               generic_stage_target.__init__(self)
+
                self.required_values=["version_stamp","target","subarch",\
                        "rel_type","profile","snapshot","source_subpath"]
 
                self.valid_values=self.required_values[:]
                self.valid_values.extend(["grp/use"])
-               if not "grp" in addlargs:
+               if not "grp" in self.settings:
                        raise CatalystError,"Required value \"grp\" not specified in spec."
 
                self.required_values.extend(["grp"])
-               if type(addlargs["grp"])==types.StringType:
-                       addlargs["grp"]=[addlargs["grp"]]
+               if type(self.settings["grp"])==types.StringType:
+                       self.settings["grp"]=[self.settings["grp"]]
 
-               if "grp/use" in addlargs:
-                   if type(addlargs["grp/use"])==types.StringType:
-                           addlargs["grp/use"]=[addlargs["grp/use"]]
+               if "grp/use" in self.settings:
+                   if type(self.settings["grp/use"])==types.StringType:
+                           self.settings["grp/use"]=[self.settings["grp/use"]]
 
-               for x in addlargs["grp"]:
+               for x in self.settings["grp"]:
                        self.required_values.append("grp/"+x+"/packages")
                        self.required_values.append("grp/"+x+"/type")
 
-               generic_stage_target.__init__(self)
-
        def set_target_path(self):
                self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
                if self.check_autoresume("setup_target_path"):
@@ -51,10 +51,9 @@ class grp_target(generic_stage_target):
        def run_local(self):
                for pkgset in self.settings["grp"]:
                        # example call: "grp.sh run pkgset cd1 xmms vim sys-apps/gleep"
-                       mypackages = catalyst.util.list_bashify(self.settings["grp/"+pkgset+"/packages"])
+                       mypackages = catalyst.util.list_bashify(self.settings[pkgset + "/packages"])
                        try:
-                               cmd("/bin/bash "+self.settings["controller_file"]+" run "+self.settings["grp/"+pkgset+"/type"]\
-                                       +" "+pkgset+" "+mypackages,env=self.env)
+                               self.run_controller_action("run", self.settings[pkgset + "/type"] + " " + pkgset)
 
                        except CatalystError:
                                self.unbind()
index 313b958debea0b2392e4458cdec114166876b647..63554e23ad4a1dfcc12105094a0e32ef9996377b 100644 (file)
@@ -30,7 +30,7 @@ class netboot_target(generic_stage_target):
 
                try:
                        if "netboot/packages" in self.settings:
-                               if type(addlargs["netboot/packages"]) == types.StringType:
+                               if type(self.settings["netboot/packages"]) == types.StringType:
                                        loopy=[self.settings["netboot/packages"]]
                                else:
                                        loopy=self.settings["netboot/packages"]
@@ -85,8 +85,7 @@ class netboot_target(generic_stage_target):
                                        myfiles.append(self.settings["netboot/extra_files"])
 
                        try:
-                               cmd("/bin/bash "+self.settings["controller_file"]+\
-                                       " image " + catalyst.util.list_bashify(myfiles),env=self.env)
+                               self.run_controller_action("image", catalyst.util.list_bashify(myfiles))
                        except CatalystError:
                                self.unbind()
                                raise CatalystError,"Failed to copy files to image!"
@@ -109,8 +108,7 @@ class netboot_target(generic_stage_target):
                # no auto resume here as we always want the
                # freshest images moved
                try:
-                       cmd("/bin/bash "+self.settings["controller_file"]+\
-                               " final",env=self.env)
+                       self.run_controller_action("final")
                        msg(">>> Netboot Build Finished!")
                except CatalystError:
                        self.unbind()
index a1cbd787778902d1f46e2b1bbcc0b0a9f8a59a58..75f52bc8cf234f217e4af176ab58d2a68919c572 100644 (file)
@@ -21,9 +21,7 @@ class tinderbox_target(generic_stage_target):
                # tinderbox
                # example call: "grp.sh run xmms vim sys-apps/gleep"
                try:
-                       if os.path.exists(self.settings["controller_file"]):
-                           cmd("/bin/bash "+self.settings["controller_file"]+" run "+\
-                               catalyst.util.list_bashify(self.settings["tinderbox/packages"]),"run script failed.",env=self.env)
+                       self.run_controller_action("run", catalyst.util.list_bashify(self.settings["packages"]))
 
                except CatalystError:
                        self.unbind()