2 # Copyright 1999-2004 Gentoo Technologies, Inc.
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.41 2004/07/11 21:24:15 zhen Exp $
6 # Maintained in full by John Davis <zhen@gentoo.org>
8 import os,sys,imp,string,getopt,types
10 __maintainer__="John Davis <zhen@gentoo.org>"
16 print "Usage catalyst [options] [-C variable=value...]"
17 print " -h --help print this help message"
18 print " -v --version display version information"
19 print " -d --debug enable debugging"
20 print " -c --config use specified configuration file"
21 print " -C --cli catalyst commandline (MUST BE LAST OPTION)"
22 print " -f --file read specfile"
23 print " -V --verbose verbose output"
26 print "Gentoo Catalyst, version "+__version__
27 print "Copyright 2003-2004 The Gentoo Foundation"
28 print "Distributed under the GNU General Public License version 2\n"
31 def parse_config(myconfig):
32 # search a couple of different areas for the main config file
36 confdefaults={ "storedir":"/var/tmp/catalyst",\
37 "sharedir":"/usr/share/catalyst","distdir":"/usr/portage/distfiles",\
38 "portdir":"/usr/portage","options":""}
40 # first, try the one passed (presumably from the cmdline)
42 if os.path.exists(myconfig):
43 print "Using command line specified Catalyst configuration file, "+myconfig
47 print "!!! catalyst: Could not use specified configuration file "+\
51 # next, try the default location
52 elif os.path.exists("/etc/catalyst/catalyst.conf"):
53 print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf"
54 config_file="/etc/catalyst/catalyst.conf"
56 # can't find a config file (we are screwed), so bail out
58 print "!!! catalyst: Could not find a suitable configuration file"
61 # now, try and parse the config file "config_file"
63 execfile(config_file, myconf, myconf)
66 print "!!! catalyst: Unable to parse configuration file, "+myconfig
69 # now, load up the values into conf_values so that we can use them
70 for x in confdefaults.keys():
72 print "Setting",x,"to config file value \""+myconf[x]+"\""
73 conf_values[x]=myconf[x]
75 print "Setting",x,"to default value \""+confdefaults[x]+"\""
76 conf_values[x]=confdefaults[x]
78 # parse out the rest of the options from the config file
79 if "ccache" in string.split(conf_values["options"]):
80 print "Compiler cache support enabled."
81 conf_values["CCACHE"]="1"
83 if "pkgcache" in string.split(conf_values["options"]):
84 print "Package cache support enabled."
85 conf_values["PKGCACHE"]="1"
87 if "distcc" in string.split(conf_values["options"]):
88 print "Distcc support enabled."
89 conf_values["DISTCC"]="1"
91 if "autoresume" in string.split(conf_values["options"]):
92 print "Autoresuming support enabled."
93 conf_values["AUTORESUME"]="1"
95 if myconf.has_key("envscript"):
96 print "Envscript support enabled."
97 conf_values["ENVSCRIPT"]=myconf["envscript"]
100 # import catalyst's own modules (i.e. catalyst_support and the arch modules)
104 for x in required_build_targets:
106 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
107 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
111 raise CatalystError,"Can't find "+x+".py plugin in "+\
112 conf_values.settings["sharedir"]+"/modules/"
114 for x in valid_build_targets:
116 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
117 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
118 module.register(targetmap)
122 raise CatalystError,"Can't find "+x+".py plugin in "+\
123 conf_values.settings["sharedir"]+"/modules/"
126 print "!!! catalyst: Python modules not found in "+\
127 conf_values["sharedir"]+"/modules; exiting."
132 def do_spec(myspecfile):
134 addlargs=read_spec(myspecfile)
142 return arg_parse(cmdline)
144 except CatalystError:
145 print "!!! catalyst: Could not parse commandline, exiting."
148 def build_target(addlargs, targetmap):
150 if not targetmap.has_key(addlargs["target"]):
151 raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
153 mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
156 except CatalystError:
159 if __name__ == "__main__":
164 # catalyst cannot be run as a normal user due to chroots, mounts, etc
165 print "!!! catalyst: This script requires root privileges to operate"
168 # we need some options in order to work correctly
169 if len(sys.argv) < 2:
173 # parse out the command line arguments
175 opts,args = getopt.getopt(sys.argv[1:], "hvdc:C:f:V", ["help", "version", "debug",\
176 "config=", "cli=", "file=", "verbose"])
178 except getopt.GetoptError:
182 # defaults for commandline opts
190 if o in ("-h", "--help"):
194 if o in ("-v", "--version"):
195 print "Catalyst version "+__version__
198 if o in ("-d", "--debug"):
201 if o in ("-c", "--config"):
204 if o in ("-C", "--cli"):
205 x=sys.argv.index(o)+1
206 while x < len(sys.argv):
207 mycmdline.append(sys.argv[x])
210 if o in ("-f", "--file"):
213 if o in ("-V", "--verbose"):
216 # import configuration file and import our main module using those settings
217 parse_config(myconfig)
218 sys.path.append(conf_values["sharedir"]+"/modules")
219 from catalyst_support import *
221 # import the rest of the catalyst modules
222 targetmap=import_modules()
225 addlargs=do_spec(myspecfile)
228 addlargs=do_cli(mycmdline)
230 # everything is setup, so the build is a go
232 build_target(addlargs, targetmap)
234 print "!!! catalyst: could not complete build"