From: John P. Davis Date: Sun, 11 Jul 2004 21:22:07 +0000 (+0000) Subject: rewrote the main catalyst driver script. fixed up arg_parse in catalyst_support.py... X-Git-Tag: CATALYST_2_0_6_916~967 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=34d1b20fa39f33999521ac05f638b9cb12da6b6c;p=catalyst.git rewrote the main catalyst driver script. fixed up arg_parse in catalyst_support.py to help this new script git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/catalyst/trunk@406 d1e1f19c-881f-0410-ab34-b69fee027534 --- diff --git a/ChangeLog b/ChangeLog index 7148b273..3dc69aca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,14 @@ # ChangeLog for gentoo/src/catalyst # Copyright 2002-2004 Gentoo Technologies, Inc.; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.67 2004/07/03 00:33:37 zhen Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.68 2004/07/11 21:22:07 zhen Exp $ + + 11 Jul 2004; +catalyst, -catalyst.new.py, + modules/catalyst_support.py: + completely rewrote the catalyst main script so that it can actually utilize + more than one command line flag. new functionality included, but not active + yet (--debug and --verbose). arguments can still be passed on the commandline + through the use of the -C (--cli) flag. updated the arg_parse function in + catalyst_support.py to accomodate my changes. 02 Jul 2004; John Davis modules/generic_stage_target.py, modules/generic_target.py, modules/grp_target.py, diff --git a/catalyst.new.py b/catalyst similarity index 91% rename from catalyst.new.py rename to catalyst index 6123f05b..4228e84c 100755 --- a/catalyst.new.py +++ b/catalyst @@ -1,7 +1,7 @@ #!/usr/bin/python # Copyright 1999-2004 Gentoo Technologies, Inc. # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo/src/catalyst/Attic/catalyst.new.py,v 1.1 2004/07/07 01:46:31 zhen Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.40 2004/07/11 21:22:07 zhen Exp $ # Maintained in full by John Davis @@ -123,7 +123,7 @@ def import_modules(): conf_values.settings["sharedir"]+"/modules/" except ImportError: - print "!!! catalyst: python modules not found in "+\ + print "!!! catalyst: Python modules not found in "+\ conf_values["sharedir"]+"/modules; exiting." sys.exit(1) @@ -135,8 +135,16 @@ def do_spec(myspecfile): except: sys.exit(1) - return addlargs - + return addlargs + +def do_cli(cmdline): + try: + return arg_parse(cmdline) + + except CatalystError: + print "!!! catalyst: Could not parse commandline, exiting." + sys.exit(1) + def build_target(addlargs, targetmap): try: if not targetmap.has_key(addlargs["target"]): @@ -165,7 +173,7 @@ if __name__ == "__main__": # parse out the command line arguments try: opts,args = getopt.getopt(sys.argv[1:], "hvdc:C:f:V", ["help", "version", "debug",\ - "config=", "commandline=", "file=", "verbose"]) + "config=", "cli=", "file=", "verbose"]) except getopt.GetoptError: usage() @@ -193,13 +201,12 @@ if __name__ == "__main__": if o in ("-c", "--config"): myconfig=a - # needs some work if o in ("-C", "--cli"): - if type(a)==types.StringType: - mycmdline=[a] - else: - mycmdline=a - + x=sys.argv.index(o)+1 + while x < len(sys.argv): + mycmdline.append(sys.argv[x]) + x=x+1 + if o in ("-f", "--file"): myspecfile=a @@ -216,6 +223,9 @@ if __name__ == "__main__": if myspecfile: addlargs=do_spec(myspecfile) + + if mycmdline: + addlargs=do_cli(mycmdline) # everything is setup, so the build is a go try: diff --git a/modules/catalyst_support.py b/modules/catalyst_support.py index ae0fa88a..df5c392e 100644 --- a/modules/catalyst_support.py +++ b/modules/catalyst_support.py @@ -1,6 +1,6 @@ # Distributed under the GNU General Public License version 2 # Copyright 2003-2004 Gentoo Technologies, Inc. -# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.24 2004/06/18 18:06:21 zhen Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.25 2004/07/11 21:22:07 zhen Exp $ import sys,string,os,types @@ -210,21 +210,22 @@ def ismount(path): return 1 return 0 -def arg_parse(mydict,remaining,argv): - "grab settings from argv, storing 'target' in mydict, and everything in remaining for later parsing" - global required_config_file_values - for x in argv: +def arg_parse(cmdline): + #global required_config_file_values + mydict={} + for x in cmdline: foo=string.split(x,"=") if len(foo)!=2: raise CatalystError, "Invalid arg syntax: "+x - remaining[foo[0]]=foo[1] - if not remaining.has_key("target"): - raise CatalystError, "Required value \"target\" not specified." - mydict["target"]=remaining["target"] - for x in required_config_file_values: - if not mydict.has_key(x): - raise CatalystError, "Required config file value \""+x+"\" not found." + else: + mydict[foo[0]]=foo[1] + + if not mydict.has_key("target"): + raise CatalystError, "Required value \"target\" not specified." + + # if all is well, we should return (we should have bailed before here if not) + return mydict def addl_arg_parse(myspec,addlargs,requiredspec,validspec): "helper function to help targets parse additional arguments"