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>"
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 " -s --snapshot generate a release snapshot"
31 print " -V --version display version information"
32 print " -v --verbose verbose output"
34 print "Usage examples:"
36 print "Using the commandline option (-C, --cli) to build a Portage snapshot:"
37 print "catalyst -C target=snapshot version_stamp=my_date"
39 print "Using the snapshot option (-s, --snapshot) to build a release snapshot:"
40 print "catalyst -s 20071121"
42 print "Using the specfile option (-f, --file) to build a stage target:"
43 print "catalyst -f stage1-specfile.spec"
46 print "Catalyst, version "+__version__
47 print "Copyright 2003-2008 Gentoo Foundation"
48 print "Copyright 2008 various authors"
49 print "Distributed under the GNU General Public License version 2.1\n"
51 def parse_config(myconfig):
52 # search a couple of different areas for the main config file
56 confdefaults={ "storedir":"/var/tmp/catalyst",\
57 "sharedir":"/usr/share/catalyst","distdir":"/usr/portage/distfiles",\
58 "portdir":"/usr/portage","options":"",\
59 "snapshot_cache":"/var/tmp/catalyst/snapshot_cache",\
60 "hash_function":"crc32"}
62 # first, try the one passed (presumably from the cmdline)
64 if os.path.exists(myconfig):
65 print "Using command line specified Catalyst configuration file, "+myconfig
69 print "!!! catalyst: Could not use specified configuration file "+\
73 # next, try the default location
74 elif os.path.exists("/etc/catalyst/catalyst.conf"):
75 print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf"
76 config_file="/etc/catalyst/catalyst.conf"
78 # can't find a config file (we are screwed), so bail out
80 print "!!! catalyst: Could not find a suitable configuration file"
83 # now, try and parse the config file "config_file"
85 # execfile(config_file, myconf, myconf)
86 myconfig = catalyst.config.ConfigParser(config_file)
87 myconf.update(myconfig.get_values())
90 print "!!! catalyst: Unable to parse configuration file, "+myconfig
93 # now, load up the values into conf_values so that we can use them
94 for x in confdefaults.keys():
96 print "Setting",x,"to config file value \""+myconf[x]+"\""
97 conf_values[x]=myconf[x]
99 print "Setting",x,"to default value \""+confdefaults[x]+"\""
100 conf_values[x]=confdefaults[x]
102 # parse out the rest of the options from the config file
103 if "autoresume" in string.split(conf_values["options"]):
104 print "Autoresuming support enabled."
105 conf_values["AUTORESUME"]="1"
107 if "ccache" in string.split(conf_values["options"]):
108 print "Compiler cache support enabled."
109 conf_values["CCACHE"]="1"
111 if "clear-autoresume" in string.split(conf_values["options"]):
112 print "Cleaning autoresume flags support enabled."
113 conf_values["CLEAR_AUTORESUME"]="1"
115 # if "compress" in string.split(conf_values["options"]):
116 # print "Compression enabled."
117 # conf_values["COMPRESS"]="1"
119 if "distcc" in string.split(conf_values["options"]):
120 print "Distcc support enabled."
121 conf_values["DISTCC"]="1"
123 if "icecream" in string.split(conf_values["options"]):
124 print "Icecream compiler cluster support enabled."
125 conf_values["ICECREAM"]="1"
127 if "kerncache" in string.split(conf_values["options"]):
128 print "Kernel cache support enabled."
129 conf_values["KERNCACHE"]="1"
131 if "pkgcache" in string.split(conf_values["options"]):
132 print "Package cache support enabled."
133 conf_values["PKGCACHE"]="1"
135 if "purge" in string.split(conf_values["options"]):
136 print "Purge support enabled."
137 conf_values["PURGE"]="1"
139 if "seedcache" in string.split(conf_values["options"]):
140 print "Seed cache support enabled."
141 conf_values["SEEDCACHE"]="1"
143 if "snapcache" in string.split(conf_values["options"]):
144 print "Snapshot cache support enabled."
145 conf_values["SNAPCACHE"]="1"
147 if "metadata_overlay" in conf_values["options"].split():
148 print "Use of metadata_overlay module for portage enabled."
149 conf_values["METADATA_OVERLAY"]="1"
151 # if "tarball" in string.split(conf_values["options"]):
152 # print "Tarball creation enabled."
153 # conf_values["TARBALL"]="1"
155 if myconf.has_key("digests"):
156 conf_values["digests"]=myconf["digests"]
157 if myconf.has_key("contents"):
158 conf_values["contents"]=myconf["contents"]
160 if myconf.has_key("envscript"):
161 print "Envscript support enabled."
162 conf_values["ENVSCRIPT"]=myconf["envscript"]
164 def import_modules():
165 # import catalyst's own modules (i.e. catalyst_support and the arch modules)
169 for x in required_build_targets:
171 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
172 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
176 raise CatalystError,"Can't find "+x+".py plugin in "+\
177 conf_values.settings["sharedir"]+"/modules/"
179 for x in valid_build_targets:
181 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
182 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
183 module.register(targetmap)
187 raise CatalystError,"Can't find "+x+".py plugin in "+\
188 conf_values.settings["sharedir"]+"/modules/"
191 print "!!! catalyst: Python modules not found in "+\
192 conf_values["sharedir"]+"/modules; exiting."
197 def build_target(addlargs, targetmap):
199 if not targetmap.has_key(addlargs["target"]):
200 raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
202 mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
207 catalyst.util.print_traceback()
208 print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
211 if __name__ == "__main__":
216 # catalyst cannot be run as a normal user due to chroots, mounts, etc
217 print "!!! catalyst: This script requires root privileges to operate"
220 # we need some options in order to work correctly
221 if len(sys.argv) < 2:
225 # parse out the command line arguments
227 opts,args = getopt.getopt(sys.argv[1:], "aphvdc:C:f:FVs:", ["purge","help", "version", "debug",\
228 "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
230 except getopt.GetoptError:
234 # defaults for commandline opts
243 # check preconditions
245 print "!!! catalyst: please specify one of either -f or -C\n"
250 if o in ("-h", "--help"):
254 if o in ("-V", "--version"):
255 print "Catalyst version "+__version__
258 if o in ("-d", "--debug"):
259 if len(sys.argv) < 3:
260 print "!!! catalyst: please specify one of either -f or -C\n"
264 conf_values["DEBUG"]="1"
265 conf_values["VERBOSE"]="1"
267 if o in ("-c", "--config"):
268 if len(sys.argv) < 3:
269 print "!!! catalyst: please specify one of either -f or -C\n"
275 if o in ("-C", "--cli"):
277 x=sys.argv.index(o)+1
278 while x < len(sys.argv):
279 mycmdline.append(sys.argv[x])
282 if o in ("-f", "--file"):
286 if o in ("-F", "--fetchonly"):
287 if len(sys.argv) < 3:
288 print "!!! catalyst: please specify one of either -f or -C\n"
292 conf_values["FETCH"]="1"
294 if o in ("-v", "--verbose"):
295 if len(sys.argv) < 3:
296 print "!!! catalyst: please specify one of either -f or -C\n"
300 conf_values["VERBOSE"]="1"
302 if o in ("-s", "--snapshot"):
303 if len(sys.argv) < 3:
304 print "!!! catalyst: missing snapshot identifier\n"
309 mycmdline.append("target=snapshot")
310 mycmdline.append("version_stamp="+a)
312 if o in ("-p", "--purge"):
313 if len(sys.argv) < 3:
314 print "!!! catalyst: please specify one of either -f or -C\n"
318 conf_values["PURGE"]="1"
319 if o in ("-a", "--clear-autoresume"):
320 if len(sys.argv) < 3:
321 print "!!! catalyst: please specify one of either -f or -C\n"
325 conf_values["CLEAR_AUTORESUME"]="1"
327 print "!!! catalyst: please specify one of either -f or -C\n"
331 # import configuration file and import our main module using those settings
332 parse_config(myconfig)
333 sys.path.append(conf_values["sharedir"]+"/modules")
334 from catalyst_support import *
336 # Start checking that digests are valid now that the hash_map was imported from catalyst_support
337 if conf_values.has_key("digests"):
338 for i in conf_values["digests"].split():
339 if not hash_map.has_key(i):
341 print i+" is not a valid digest entry"
342 print "Valid digest entries:"
343 print hash_map.keys()
345 print "Catalyst aborting...."
347 if find_binary(hash_map[i][1]) == None:
350 print "\tThe "+hash_map[i][1]+\
351 " binary was not found. It needs to be in your system path"
353 print "Catalyst aborting...."
355 if conf_values.has_key("hash_function"):
356 if not hash_map.has_key(conf_values["hash_function"]):
358 print conf_values["hash_function"]+" is not a valid hash_function entry"
359 print "Valid hash_function entries:"
360 print hash_map.keys()
362 print "Catalyst aborting...."
364 if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
366 print "hash_function="+conf_values["hash_function"]
367 print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
368 " binary was not found. It needs to be in your system path"
370 print "Catalyst aborting...."
373 # import the rest of the catalyst modules
374 targetmap=import_modules()
379 spec = catalyst.config.SpecParser(myspecfile)
380 addlargs.update(spec.get_values())
384 cmdline = catalyst.config.ConfigParser()
385 cmdline.parse_lines(mycmdline)
386 addlargs.update(cmdline.get_values())
387 except CatalystError:
388 print "!!! catalyst: Could not parse commandline, exiting."
391 if not addlargs.has_key("target"):
392 raise CatalystError, "Required value \"target\" not specified."
394 # everything is setup, so the build is a go
396 build_target(addlargs, targetmap)
398 except CatalystError:
400 print "Catalyst aborting...."
402 except KeyboardInterrupt:
403 print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )"
405 print "Catalyst aborting...."
408 print "Catalyst aborting...."
411 print "Catalyst aborting...."
415 #except CatalystError:
417 # print "Catalyst aborting...."
420 # print "\nproblem with command line or spec file ( Key Error )"
421 # print "Key: "+str(sys.exc_value)+" was not found"
422 # print "Catalyst aborting...."
424 #except UnboundLocalError:
426 # print "UnboundLocalError: "+str(sys.exc_value)+" was not found"
429 # print "Catalyst aborting...."