3 # Maintained in full by:
4 # Andrew Gaffney <agaffney@gentoo.org>
5 # Chris Gianelloni <wolf31o2@gentoo.org>
7 import os,sys,imp,string,getopt
10 sys.path.append("./modules")
12 import catalyst.config
15 __maintainer__="Chris Gianelloni <wolf31o2@gentoo.org>"
16 __version__="2.0.6.902"
21 print "Usage catalyst [options] [-C variable=value...] [ -s identifier]"
22 print " -a --clear-autoresume clear autoresume flags"
23 print " -c --config use specified configuration file"
24 print " -C --cli catalyst commandline (MUST BE LAST OPTION)"
25 print " -d --debug enable debugging"
26 print " -f --file read specfile"
27 print " -F --fetchonly fetch files only"
28 print " -h --help print this help message"
29 print " -p --purge clear tmp dirs,package cache and autoresume flags"
30 print " -P --purgeonly clear tmp dirs,package cache and autoresume flags and exit"
31 print " -s --snapshot generate a release snapshot"
32 print " -V --version display version information"
33 print " -v --verbose verbose output"
35 print "Usage examples:"
37 print "Using the commandline option (-C, --cli) to build a Portage snapshot:"
38 print "catalyst -C target=snapshot version_stamp=my_date"
40 print "Using the snapshot option (-s, --snapshot) to build a release snapshot:"
41 print "catalyst -s 20071121"
43 print "Using the specfile option (-f, --file) to build a stage target:"
44 print "catalyst -f stage1-specfile.spec"
47 print "Catalyst, version "+__version__
48 print "Copyright 2003-2008 Gentoo Foundation"
49 print "Copyright 2008 various authors"
50 print "Distributed under the GNU General Public License version 2.1\n"
52 def parse_config(myconfig):
53 # search a couple of different areas for the main config file
57 confdefaults={ "storedir":"/var/tmp/catalyst",\
58 "sharedir":"/usr/share/catalyst","distdir":"/usr/portage/distfiles",\
59 "portdir":"/usr/portage","options":"",\
60 "snapshot_cache":"/var/tmp/catalyst/snapshot_cache",\
61 "hash_function":"crc32"}
63 # first, try the one passed (presumably from the cmdline)
65 if os.path.exists(myconfig):
66 print "Using command line specified Catalyst configuration file, "+myconfig
70 print "!!! catalyst: Could not use specified configuration file "+\
74 # next, try the default location
75 elif os.path.exists("/etc/catalyst/catalyst.conf"):
76 print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf"
77 config_file="/etc/catalyst/catalyst.conf"
79 # can't find a config file (we are screwed), so bail out
81 print "!!! catalyst: Could not find a suitable configuration file"
84 # now, try and parse the config file "config_file"
86 # execfile(config_file, myconf, myconf)
87 myconfig = catalyst.config.ConfigParser(config_file)
88 myconf.update(myconfig.get_values())
91 print "!!! catalyst: Unable to parse configuration file, "+myconfig
94 # now, load up the values into conf_values so that we can use them
95 for x in confdefaults.keys():
97 print "Setting",x,"to config file value \""+myconf[x]+"\""
98 conf_values[x]=myconf[x]
100 print "Setting",x,"to default value \""+confdefaults[x]+"\""
101 conf_values[x]=confdefaults[x]
103 # parse out the rest of the options from the config file
104 if "autoresume" in string.split(conf_values["options"]):
105 print "Autoresuming support enabled."
106 conf_values["AUTORESUME"]="1"
108 if "ccache" in string.split(conf_values["options"]):
109 print "Compiler cache support enabled."
110 conf_values["CCACHE"]="1"
112 if "clear-autoresume" in string.split(conf_values["options"]):
113 print "Cleaning autoresume flags support enabled."
114 conf_values["CLEAR_AUTORESUME"]="1"
116 # if "compress" in string.split(conf_values["options"]):
117 # print "Compression enabled."
118 # conf_values["COMPRESS"]="1"
120 if "distcc" in string.split(conf_values["options"]):
121 print "Distcc support enabled."
122 conf_values["DISTCC"]="1"
124 if "icecream" in string.split(conf_values["options"]):
125 print "Icecream compiler cluster support enabled."
126 conf_values["ICECREAM"]="1"
128 if "kerncache" in string.split(conf_values["options"]):
129 print "Kernel cache support enabled."
130 conf_values["KERNCACHE"]="1"
132 if "pkgcache" in string.split(conf_values["options"]):
133 print "Package cache support enabled."
134 conf_values["PKGCACHE"]="1"
136 if "purge" in string.split(conf_values["options"]):
137 print "Purge support enabled."
138 conf_values["PURGE"]="1"
140 if "seedcache" in string.split(conf_values["options"]):
141 print "Seed cache support enabled."
142 conf_values["SEEDCACHE"]="1"
144 if "snapcache" in string.split(conf_values["options"]):
145 print "Snapshot cache support enabled."
146 conf_values["SNAPCACHE"]="1"
148 if "metadata_overlay" in conf_values["options"].split():
149 print "Use of metadata_overlay module for portage enabled."
150 conf_values["METADATA_OVERLAY"]="1"
152 # if "tarball" in string.split(conf_values["options"]):
153 # print "Tarball creation enabled."
154 # conf_values["TARBALL"]="1"
156 if myconf.has_key("digests"):
157 conf_values["digests"]=myconf["digests"]
158 if myconf.has_key("contents"):
159 conf_values["contents"]=myconf["contents"]
161 if myconf.has_key("envscript"):
162 print "Envscript support enabled."
163 conf_values["ENVSCRIPT"]=myconf["envscript"]
165 def import_modules():
166 # import catalyst's own modules (i.e. catalyst_support and the arch modules)
170 for x in required_build_targets:
172 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
173 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
177 raise CatalystError,"Can't find "+x+".py plugin in "+\
178 conf_values.settings["sharedir"]+"/modules/"
180 for x in valid_build_targets:
182 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
183 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
184 module.register(targetmap)
188 raise CatalystError,"Can't find "+x+".py plugin in "+\
189 conf_values.settings["sharedir"]+"/modules/"
192 print "!!! catalyst: Python modules not found in "+\
193 conf_values["sharedir"]+"/modules; exiting."
198 def build_target(addlargs, targetmap):
200 if not targetmap.has_key(addlargs["target"]):
201 raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
203 mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
208 catalyst.util.print_traceback()
209 print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
212 if __name__ == "__main__":
217 # catalyst cannot be run as a normal user due to chroots, mounts, etc
218 print "!!! catalyst: This script requires root privileges to operate"
221 # we need some options in order to work correctly
222 if len(sys.argv) < 2:
226 # parse out the command line arguments
228 opts,args = getopt.getopt(sys.argv[1:], "apPhvdc:C:f:FVs:", ["purge", "purgeonly", "help", "version", "debug",\
229 "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
231 except getopt.GetoptError:
235 # defaults for commandline opts
244 # check preconditions
246 print "!!! catalyst: please specify one of either -f or -C\n"
252 if o in ("-h", "--help"):
256 if o in ("-V", "--version"):
257 print "Catalyst version "+__version__
260 if o in ("-d", "--debug"):
261 conf_values["DEBUG"]="1"
262 conf_values["VERBOSE"]="1"
264 if o in ("-c", "--config"):
267 if o in ("-C", "--cli"):
269 x=sys.argv.index(o)+1
270 while x < len(sys.argv):
271 mycmdline.append(sys.argv[x])
274 if o in ("-f", "--file"):
278 if o in ("-F", "--fetchonly"):
279 conf_values["FETCH"]="1"
281 if o in ("-v", "--verbose"):
282 conf_values["VERBOSE"]="1"
284 if o in ("-s", "--snapshot"):
285 if len(sys.argv) < 3:
286 print "!!! catalyst: missing snapshot identifier\n"
291 mycmdline.append("target=snapshot")
292 mycmdline.append("version_stamp="+a)
294 if o in ("-p", "--purge"):
295 conf_values["PURGE"] = "1"
297 if o in ("-P", "--purgeonly"):
298 conf_values["PURGEONLY"] = "1"
300 if o in ("-a", "--clear-autoresume"):
301 conf_values["CLEAR_AUTORESUME"] = "1"
304 print "!!! catalyst: please specify one of either -f or -C\n"
308 # import configuration file and import our main module using those settings
309 parse_config(myconfig)
310 sys.path.append(conf_values["sharedir"]+"/modules")
311 from catalyst_support import *
313 # Start checking that digests are valid now that the hash_map was imported from catalyst_support
314 if conf_values.has_key("digests"):
315 for i in conf_values["digests"].split():
316 if not hash_map.has_key(i):
318 print i+" is not a valid digest entry"
319 print "Valid digest entries:"
320 print hash_map.keys()
322 print "Catalyst aborting...."
324 if find_binary(hash_map[i][1]) == None:
327 print "\tThe "+hash_map[i][1]+\
328 " binary was not found. It needs to be in your system path"
330 print "Catalyst aborting...."
332 if conf_values.has_key("hash_function"):
333 if not hash_map.has_key(conf_values["hash_function"]):
335 print conf_values["hash_function"]+" is not a valid hash_function entry"
336 print "Valid hash_function entries:"
337 print hash_map.keys()
339 print "Catalyst aborting...."
341 if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
343 print "hash_function="+conf_values["hash_function"]
344 print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
345 " binary was not found. It needs to be in your system path"
347 print "Catalyst aborting...."
350 # import the rest of the catalyst modules
351 targetmap=import_modules()
356 spec = catalyst.config.SpecParser(myspecfile)
357 addlargs.update(spec.get_values())
361 cmdline = catalyst.config.ConfigParser()
362 cmdline.parse_lines(mycmdline)
363 addlargs.update(cmdline.get_values())
364 except CatalystError:
365 print "!!! catalyst: Could not parse commandline, exiting."
368 if not addlargs.has_key("target"):
369 raise CatalystError, "Required value \"target\" not specified."
371 # everything is setup, so the build is a go
373 build_target(addlargs, targetmap)
375 except CatalystError:
377 print "Catalyst aborting...."
379 except KeyboardInterrupt:
380 print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )"
382 print "Catalyst aborting...."
385 print "Catalyst aborting...."
388 print "Catalyst aborting...."
392 #except CatalystError:
394 # print "Catalyst aborting...."
397 # print "\nproblem with command line or spec file ( Key Error )"
398 # print "Key: "+str(sys.exc_value)+" was not found"
399 # print "Catalyst aborting...."
401 #except UnboundLocalError:
403 # print "UnboundLocalError: "+str(sys.exc_value)+" was not found"
406 # print "Catalyst aborting...."