3 # Maintained in full by:
4 # Catalyst Team <catalyst@gentoo.org>
5 # Release Engineering Team <releng@gentoo.org>
6 # Andrew Gaffney <agaffney@gentoo.org>
7 # Chris Gianelloni <wolf31o2@wolf31o2.org>
10 import os, sys, imp, string, getopt
14 __selfpath__ = os.path.abspath(os.path.dirname(__file__))
16 sys.path.append(__selfpath__ + "/modules")
18 import catalyst.config
21 __maintainer__="Catalyst <catalyst@gentoo.org>"
22 __version__="2.0.12.2"
27 print "Usage catalyst [options] [-C variable=value...] [ -s identifier]"
28 print " -a --clear-autoresume clear autoresume flags"
29 print " -c --config use specified configuration file"
30 print " -C --cli catalyst commandline (MUST BE LAST OPTION)"
31 print " -d --debug enable debugging"
32 print " -f --file read specfile"
33 print " -F --fetchonly fetch files only"
34 print " -h --help print this help message"
35 print " -p --purge clear tmp dirs,package cache and autoresume flags"
36 print " -P --purgeonly clear tmp dirs,package cache and autoresume flags and exit"
37 print " -T --purgetmponly clear tmp dirs and autoresume flags and exit"
38 print " -s --snapshot generate a release snapshot"
39 print " -V --version display version information"
40 print " -v --verbose verbose output"
42 print "Usage examples:"
44 print "Using the commandline option (-C, --cli) to build a Portage snapshot:"
45 print "catalyst -C target=snapshot version_stamp=my_date"
47 print "Using the snapshot option (-s, --snapshot) to build a release snapshot:"
48 print "catalyst -s 20071121"
50 print "Using the specfile option (-f, --file) to build a stage target:"
51 print "catalyst -f stage1-specfile.spec"
54 print "Catalyst, version "+__version__
55 print "Copyright 2003-2008 Gentoo Foundation"
56 print "Copyright 2008-2012 various authors"
57 print "Distributed under the GNU General Public License version 2.1\n"
59 def parse_config(myconfig):
60 # search a couple of different areas for the main config file
64 confdefaults={ "storedir":"/var/tmp/catalyst",\
65 "sharedir":"/usr/share/catalyst","distdir":"/usr/portage/distfiles",\
66 "portdir":"/usr/portage","options":"",\
67 "snapshot_cache":"/var/tmp/catalyst/snapshot_cache",\
68 "hash_function":"crc32"}
70 # first, try the one passed (presumably from the cmdline)
72 if os.path.exists(myconfig):
73 print "Using command line specified Catalyst configuration file, "+myconfig
77 print "!!! catalyst: Could not use specified configuration file "+\
81 # next, try the default location
82 elif os.path.exists("/etc/catalyst/catalyst.conf"):
83 print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf"
84 config_file="/etc/catalyst/catalyst.conf"
86 # can't find a config file (we are screwed), so bail out
88 print "!!! catalyst: Could not find a suitable configuration file"
91 # now, try and parse the config file "config_file"
93 # execfile(config_file, myconf, myconf)
94 myconfig = catalyst.config.ConfigParser(config_file)
95 myconf.update(myconfig.get_values())
98 print "!!! catalyst: Unable to parse configuration file, "+myconfig
101 # now, load up the values into conf_values so that we can use them
102 for x in confdefaults.keys():
104 print "Setting",x,"to config file value \""+myconf[x]+"\""
105 conf_values[x]=myconf[x]
107 print "Setting",x,"to default value \""+confdefaults[x]+"\""
108 conf_values[x]=confdefaults[x]
110 # parse out the rest of the options from the config file
111 if "autoresume" in string.split(conf_values["options"]):
112 print "Autoresuming support enabled."
113 conf_values["AUTORESUME"]="1"
115 if "bindist" in string.split(conf_values["options"]):
116 print "Binary redistribution enabled"
117 conf_values["BINDIST"]="1"
119 print "Bindist is not enabled in catalyst.conf"
120 print "Binary redistribution of generated stages/isos may be prohibited by law."
121 print "Please see the use description for bindist on any package you are including."
123 if "ccache" in string.split(conf_values["options"]):
124 print "Compiler cache support enabled."
125 conf_values["CCACHE"]="1"
127 if "clear-autoresume" in string.split(conf_values["options"]):
128 print "Cleaning autoresume flags support enabled."
129 conf_values["CLEAR_AUTORESUME"]="1"
131 # if "compress" in string.split(conf_values["options"]):
132 # print "Compression enabled."
133 # conf_values["COMPRESS"]="1"
135 if "distcc" in string.split(conf_values["options"]):
136 print "Distcc support enabled."
137 conf_values["DISTCC"]="1"
139 if "icecream" in string.split(conf_values["options"]):
140 print "Icecream compiler cluster support enabled."
141 conf_values["ICECREAM"]="1"
143 if "kerncache" in string.split(conf_values["options"]):
144 print "Kernel cache support enabled."
145 conf_values["KERNCACHE"]="1"
147 if "pkgcache" in string.split(conf_values["options"]):
148 print "Package cache support enabled."
149 conf_values["PKGCACHE"]="1"
151 if "preserve_libs" in string.split(conf_values["options"]):
152 print "Preserving libs during unmerge."
153 conf_values["PRESERVE_LIBS"]="1"
155 if "purge" in string.split(conf_values["options"]):
156 print "Purge support enabled."
157 conf_values["PURGE"]="1"
159 if "seedcache" in string.split(conf_values["options"]):
160 print "Seed cache support enabled."
161 conf_values["SEEDCACHE"]="1"
163 if "snapcache" in string.split(conf_values["options"]):
164 print "Snapshot cache support enabled."
165 conf_values["SNAPCACHE"]="1"
167 # if "tarball" in string.split(conf_values["options"]):
168 # print "Tarball creation enabled."
169 # conf_values["TARBALL"]="1"
171 if "digests" in myconf:
172 conf_values["digests"]=myconf["digests"]
173 if "contents" in myconf:
174 conf_values["contents"]=myconf["contents"]
176 if "envscript" in myconf:
177 print "Envscript support enabled."
178 conf_values["ENVSCRIPT"]=myconf["envscript"]
180 if "var_tmpfs_portage" in myconf:
181 conf_values["var_tmpfs_portage"]=myconf["var_tmpfs_portage"];
183 if "port_logdir" in myconf:
184 conf_values["port_logdir"]=myconf["port_logdir"];
186 def import_modules():
187 # import catalyst's own modules (i.e. catalyst_support and the arch modules)
191 for x in required_build_targets:
193 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
194 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
198 raise CatalystError,"Can't find "+x+".py plugin in "+\
199 conf_values["sharedir"]+"/modules/"
201 for x in valid_build_targets:
203 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
204 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
205 module.register(targetmap)
209 raise CatalystError,"Can't find "+x+".py plugin in "+\
210 conf_values["sharedir"]+"/modules/"
213 print "!!! catalyst: Python modules not found in "+\
214 conf_values["sharedir"]+"/modules; exiting."
219 def build_target(addlargs, targetmap):
221 if addlargs["target"] not in targetmap:
222 raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
224 mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
229 catalyst.util.print_traceback()
230 print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
233 if __name__ == "__main__":
238 # catalyst cannot be run as a normal user due to chroots, mounts, etc
239 print "!!! catalyst: This script requires root privileges to operate"
242 # we need some options in order to work correctly
243 if len(sys.argv) < 2:
247 # parse out the command line arguments
249 opts,args = getopt.getopt(sys.argv[1:], "apPThvdc:C:f:FVs:", ["purge", "purgeonly", "purgetmponly", "help", "version", "debug",\
250 "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
252 except getopt.GetoptError:
256 # defaults for commandline opts
265 # check preconditions
267 print "!!! catalyst: please specify one of either -f or -C\n"
273 if o in ("-h", "--help"):
277 if o in ("-V", "--version"):
278 print "Catalyst version "+__version__
281 if o in ("-d", "--debug"):
282 conf_values["DEBUG"]="1"
283 conf_values["VERBOSE"]="1"
285 if o in ("-c", "--config"):
288 if o in ("-C", "--cli"):
290 x=sys.argv.index(o)+1
291 while x < len(sys.argv):
292 mycmdline.append(sys.argv[x])
295 if o in ("-f", "--file"):
299 if o in ("-F", "--fetchonly"):
300 conf_values["FETCH"]="1"
302 if o in ("-v", "--verbose"):
303 conf_values["VERBOSE"]="1"
305 if o in ("-s", "--snapshot"):
306 if len(sys.argv) < 3:
307 print "!!! catalyst: missing snapshot identifier\n"
312 mycmdline.append("target=snapshot")
313 mycmdline.append("version_stamp="+a)
315 if o in ("-p", "--purge"):
316 conf_values["PURGE"] = "1"
318 if o in ("-P", "--purgeonly"):
319 conf_values["PURGEONLY"] = "1"
321 if o in ("-T", "--purgetmponly"):
322 conf_values["PURGETMPONLY"] = "1"
324 if o in ("-a", "--clear-autoresume"):
325 conf_values["CLEAR_AUTORESUME"] = "1"
328 print "!!! catalyst: please specify one of either -f or -C\n"
332 # import configuration file and import our main module using those settings
333 parse_config(myconfig)
334 sys.path.append(conf_values["sharedir"]+"/modules")
335 from catalyst_support import *
337 # Start checking that digests are valid now that the hash_map was imported
338 # from catalyst_support
339 if "digests" in conf_values:
340 for i in conf_values["digests"].split():
341 if i not in hash_map:
343 print i+" is not a valid digest entry"
344 print "Valid digest entries:"
345 print hash_map.keys()
347 print "Catalyst aborting...."
349 if find_binary(hash_map[i][1]) == None:
352 print "\tThe "+hash_map[i][1]+\
353 " binary was not found. It needs to be in your system path"
355 print "Catalyst aborting...."
357 if "hash_function" in conf_values:
358 if conf_values["hash_function"] not in hash_map:
360 print conf_values["hash_function"]+\
361 " is not a valid hash_function entry"
362 print "Valid hash_function entries:"
363 print hash_map.keys()
365 print "Catalyst aborting...."
367 if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
369 print "hash_function="+conf_values["hash_function"]
370 print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
371 " binary was not found. It needs to be in your system path"
373 print "Catalyst aborting...."
376 # import the rest of the catalyst modules
377 targetmap=import_modules()
382 spec = catalyst.config.SpecParser(myspecfile)
383 addlargs.update(spec.get_values())
387 cmdline = catalyst.config.ConfigParser()
388 cmdline.parse_lines(mycmdline)
389 addlargs.update(cmdline.get_values())
390 except CatalystError:
391 print "!!! catalyst: Could not parse commandline, exiting."
394 if "target" not in addlargs:
395 raise CatalystError, "Required value \"target\" not specified."
397 # everything is setup, so the build is a go
399 build_target(addlargs, targetmap)
401 except CatalystError:
403 print "Catalyst aborting...."
405 except KeyboardInterrupt:
406 print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )"
408 print "Catalyst aborting...."
411 print "Catalyst aborting...."
414 print "Catalyst aborting...."
418 #except CatalystError:
420 # print "Catalyst aborting...."
423 # print "\nproblem with command line or spec file ( Key Error )"
424 # print "Key: "+str(sys.exc_value)+" was not found"
425 # print "Catalyst aborting...."
427 #except UnboundLocalError:
429 # print "UnboundLocalError: "+str(sys.exc_value)+" was not found"
432 # print "Catalyst aborting...."