From 64bf8f032827803cf52b0eacf163a49c7e1b7296 Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Wed, 14 Jan 2009 08:13:24 -0600 Subject: [PATCH] Add run_controller_action() function and replace manual calls to controller file --- ChangeLog | 7 +++ modules/catalyst/target/embedded.py | 2 +- modules/catalyst/target/generic.py | 10 ++++ modules/catalyst/target/generic_stage.py | 72 +++++++----------------- modules/catalyst/target/grp.py | 23 ++++---- modules/catalyst/target/netboot.py | 8 +-- modules/catalyst/target/tinderbox.py | 4 +- 7 files changed, 54 insertions(+), 72 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4aa49609..71ffcb75 100644 --- 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 + 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 modules/catalyst/spawn.py, targets/system/system-controller.sh: Add clean no-op for system target diff --git a/modules/catalyst/target/embedded.py b/modules/catalyst/target/embedded.py index ae4ec18b..11d0bafe 100644 --- a/modules/catalyst/target/embedded.py +++ b/modules/catalyst/target/embedded.py @@ -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",\ diff --git a/modules/catalyst/target/generic.py b/modules/catalyst/target/generic.py index 20b84224..55212015 100644 --- a/modules/catalyst/target/generic.py +++ b/modules/catalyst/target/generic.py @@ -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) + diff --git a/modules/catalyst/target/generic_stage.py b/modules/catalyst/target/generic_stage.py index 0bee86b5..43902ee3 100644 --- a/modules/catalyst/target/generic_stage.py +++ b/modules/catalyst/target/generic_stage.py @@ -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() diff --git a/modules/catalyst/target/grp.py b/modules/catalyst/target/grp.py index f29437ea..c7348083 100644 --- a/modules/catalyst/target/grp.py +++ b/modules/catalyst/target/grp.py @@ -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() diff --git a/modules/catalyst/target/netboot.py b/modules/catalyst/target/netboot.py index 313b958d..63554e23 100644 --- a/modules/catalyst/target/netboot.py +++ b/modules/catalyst/target/netboot.py @@ -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() diff --git a/modules/catalyst/target/tinderbox.py b/modules/catalyst/target/tinderbox.py index a1cbd787..75f52bc8 100644 --- a/modules/catalyst/target/tinderbox.py +++ b/modules/catalyst/target/tinderbox.py @@ -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() -- 2.26.2