Get rid of addlargs in the main script
authorAndrew Gaffney <agaffney@gentoo.org>
Tue, 7 Apr 2009 02:44:11 +0000 (21:44 -0500)
committerAndrew Gaffney <agaffney@gentoo.org>
Tue, 7 Apr 2009 02:44:11 +0000 (21:44 -0500)
Initial basics for multiple target support
Move targetmap into global config object

ChangeLog
catalyst
modules/catalyst/config.py

index 38815e459107ea5edde83ebe85fe84f13bb8e8de..5810e857800363c8e982233c8f7a121c304f3af1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,11 @@
 # Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS)
 # Distributed under the GPL v2
 
+  07 Apr 2009; Andrew Gaffney <agaffney@gentoo.org> catalyst,
+  modules/catalyst/config.py:
+  Get rid of addlargs in the main script Initial basics for multiple target
+  support Move targetmap into global config object
+
   07 Apr 2009; Andrew Gaffney <agaffney@gentoo.org>
   modules/catalyst/target/stage1.py:
   Clean up cleanables
index 217be8e28d6850e7857c2d0737334af09582be53..61efc16e96653109b31f2c972a99a9beb0627aa0 100755 (executable)
--- a/catalyst
+++ b/catalyst
@@ -142,21 +142,27 @@ def parse_config(myconfig):
                msg("Envscript support enabled.")
                conf_values["ENVSCRIPT"] = myconf["envscript"]
 
-def build_target(addlargs, targetmap):
-       try:
-               if not addlargs["target"] in targetmap:
-                       raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
+def build_targets():
+       spec_values = config.get_spec().get_values()
+       targetmap = config.get_targetmap()
 
-               config.get_spec().set_target(addlargs["target"])
-#              mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
-               mytarget=targetmap[addlargs["target"]]()
+       if not "targets" in spec_values or not spec_values['targets']:
+               raise CatalystError, "No target(s) specified."
 
-               mytarget.run()
+       for x in spec_values['targets']:
+               if not x in targetmap:
+                       raise CatalystError("Target \"" + x + "\" is not a known target.")
 
-       except:
-               catalyst.util.print_traceback()
-               warn("Error encountered during run of target " + addlargs["target"])
-               raise
+       for x in spec_values['targets']:
+               try:
+                       config.get_spec().set_target(x)
+                       mytarget = targetmap[x]()
+                       mytarget.run()
+
+               except:
+                       catalyst.util.print_traceback()
+                       warn("Error encountered during run of target " + x)
+                       raise
 
 def verify_digest_and_hash_functions():
        # Start checking that digests are valid now that the hash_map was imported from catalyst_support
@@ -292,14 +298,11 @@ if __name__ == "__main__":
        verify_digest_and_hash_functions()
 
        targetmap = catalyst.target.build_target_map()
-
-       addlargs = {}
        spec = catalyst.config.Spec()
 
        if myspecfile:
                specparser = catalyst.config.SpecParser(myspecfile)
                spec_values = specparser.get_values()
-               addlargs.update(spec_values)
                spec.parse_values(spec_values)
 
        if mycmdline:
@@ -307,20 +310,17 @@ if __name__ == "__main__":
                        cmdline = catalyst.config.ConfigParser()
                        cmdline.parse_lines(mycmdline)
                        cmdline_values = cmdline.get_values()
-                       addlargs.update(cmdline.get_values())
                        spec.parse_values(cmdline_values)
                except CatalystError:
                        die("Could not parse commandline, exiting.")
 
        config.set_spec(spec)
        config.set_conf(conf_values)
-
-       if not "target" in addlargs:
-               raise CatalystError, "Required value \"target\" not specified."
+       config.set_targetmap(targetmap)
 
        # everything is setup, so the build is a go
        try:
-               build_target(addlargs, targetmap)
+               build_targets()
 
        except CatalystError:
                msg()
index 212520a2e99c18699c829477a887d2b46561f6db..b6f0a7fba147969c2a1a583974683cafb4af1532 100644 (file)
@@ -164,6 +164,9 @@ class Spec:
                                if not parts[0] in self.values:
                                        self.values[parts[0]] = {}
                                self.values[parts[0]]['/'.join(parts[1:])] = values[x]
+               if 'target' in self.values['global']:
+                       self.values['global']['targets'] = set((self.values['global']['target'], ))
+                       del self.values['global']['target']
 
        def set_target(self, target):
                self.target = target
@@ -214,6 +217,7 @@ class config:
                if not hasattr(self, 'spec'):
                        self.spec = None
                        self.conf = {}
+                       self.targetmap = None
 
        def set_spec(self, spec):
                self.spec = spec
@@ -229,3 +233,9 @@ class config:
 
        def get_conf(self):
                return self.conf
+
+       def set_targetmap(self, targetmap):
+               self.targetmap = targetmap
+
+       def get_targetmap(self):
+               return self.targetmap