3 # Maintained in full by:
4 # Andrew Gaffney <agaffney@gentoo.org>
5 # Chris Gianelloni <wolf31o2@gentoo.org>
7 import os, sys, imp, string, getopt
11 __selfpath__ = os.path.abspath(os.path.dirname(__file__))
13 sys.path.append(__selfpath__ + "/modules")
15 import catalyst.config
18 __maintainer__="Chris Gianelloni <wolf31o2@wolf31o2.org>"
19 __version__="2.0.6.904"
24 print "Usage catalyst [options] [-C variable=value...] [ -s identifier]"
25 print " -a --clear-autoresume clear autoresume flags"
26 print " -c --config use specified configuration file"
27 print " -C --cli catalyst commandline (MUST BE LAST OPTION)"
28 print " -d --debug enable debugging"
29 print " -f --file read specfile"
30 print " -F --fetchonly fetch files only"
31 print " -h --help print this help message"
32 print " -p --purge clear tmp dirs,package cache and autoresume flags"
33 print " -P --purgeonly clear tmp dirs,package cache and autoresume flags and exit"
34 print " -s --snapshot generate a release snapshot"
35 print " -V --version display version information"
36 print " -v --verbose verbose output"
38 print "Usage examples:"
40 print "Using the commandline option (-C, --cli) to build a Portage snapshot:"
41 print "catalyst -C target=snapshot version_stamp=my_date"
43 print "Using the snapshot option (-s, --snapshot) to build a release snapshot:"
44 print "catalyst -s 20071121"
46 print "Using the specfile option (-f, --file) to build a stage target:"
47 print "catalyst -f stage1-specfile.spec"
50 print "Catalyst, version "+__version__
51 print "Copyright 2003-2008 Gentoo Foundation"
52 print "Copyright 2008 various authors"
53 print "Distributed under the GNU General Public License version 2.1\n"
55 def parse_config(myconfig):
56 # search a couple of different areas for the main config file
60 confdefaults={ "storedir":"/var/tmp/catalyst",\
61 "sharedir":"/usr/share/catalyst","distdir":"/usr/portage/distfiles",\
62 "portdir":"/usr/portage","options":"",\
63 "snapshot_cache":"/var/tmp/catalyst/snapshot_cache",\
64 "hash_function":"crc32"}
66 # first, try the one passed (presumably from the cmdline)
68 if os.path.exists(myconfig):
69 print "Using command line specified Catalyst configuration file, "+myconfig
73 print "!!! catalyst: Could not use specified configuration file "+\
77 # next, try the default location
78 elif os.path.exists("/etc/catalyst/catalyst.conf"):
79 print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf"
80 config_file="/etc/catalyst/catalyst.conf"
82 # can't find a config file (we are screwed), so bail out
84 print "!!! catalyst: Could not find a suitable configuration file"
87 # now, try and parse the config file "config_file"
89 # execfile(config_file, myconf, myconf)
90 myconfig = catalyst.config.ConfigParser(config_file)
91 myconf.update(myconfig.get_values())
94 print "!!! catalyst: Unable to parse configuration file, "+myconfig
97 # now, load up the values into conf_values so that we can use them
98 for x in confdefaults.keys():
100 print "Setting",x,"to config file value \""+myconf[x]+"\""
101 conf_values[x]=myconf[x]
103 print "Setting",x,"to default value \""+confdefaults[x]+"\""
104 conf_values[x]=confdefaults[x]
106 # parse out the rest of the options from the config file
107 if "autoresume" in string.split(conf_values["options"]):
108 print "Autoresuming support enabled."
109 conf_values["AUTORESUME"]="1"
111 if "ccache" in string.split(conf_values["options"]):
112 print "Compiler cache support enabled."
113 conf_values["CCACHE"]="1"
115 if "clear-autoresume" in string.split(conf_values["options"]):
116 print "Cleaning autoresume flags support enabled."
117 conf_values["CLEAR_AUTORESUME"]="1"
119 # if "compress" in string.split(conf_values["options"]):
120 # print "Compression enabled."
121 # conf_values["COMPRESS"]="1"
123 if "distcc" in string.split(conf_values["options"]):
124 print "Distcc support enabled."
125 conf_values["DISTCC"]="1"
127 if "icecream" in string.split(conf_values["options"]):
128 print "Icecream compiler cluster support enabled."
129 conf_values["ICECREAM"]="1"
131 if "kerncache" in string.split(conf_values["options"]):
132 print "Kernel cache support enabled."
133 conf_values["KERNCACHE"]="1"
135 if "pkgcache" in string.split(conf_values["options"]):
136 print "Package cache support enabled."
137 conf_values["PKGCACHE"]="1"
139 if "purge" in string.split(conf_values["options"]):
140 print "Purge support enabled."
141 conf_values["PURGE"]="1"
143 if "seedcache" in string.split(conf_values["options"]):
144 print "Seed cache support enabled."
145 conf_values["SEEDCACHE"]="1"
147 if "snapcache" in string.split(conf_values["options"]):
148 print "Snapshot cache support enabled."
149 conf_values["SNAPCACHE"]="1"
151 if "metadata_overlay" in conf_values["options"].split():
152 print "Use of metadata_overlay module for portage enabled."
153 conf_values["METADATA_OVERLAY"]="1"
155 # if "tarball" in string.split(conf_values["options"]):
156 # print "Tarball creation enabled."
157 # conf_values["TARBALL"]="1"
159 if myconf.has_key("digests"):
160 conf_values["digests"]=myconf["digests"]
161 if myconf.has_key("contents"):
162 conf_values["contents"]=myconf["contents"]
164 if myconf.has_key("envscript"):
165 print "Envscript support enabled."
166 conf_values["ENVSCRIPT"]=myconf["envscript"]
168 def import_modules():
169 # import catalyst's own modules (i.e. catalyst_support and the arch modules)
173 for x in required_build_targets:
175 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
176 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
180 raise CatalystError,"Can't find "+x+".py plugin in "+\
181 conf_values.settings["sharedir"]+"/modules/"
183 for x in valid_build_targets:
185 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
186 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
187 module.register(targetmap)
191 raise CatalystError,"Can't find "+x+".py plugin in "+\
192 conf_values.settings["sharedir"]+"/modules/"
195 print "!!! catalyst: Python modules not found in "+\
196 conf_values["sharedir"]+"/modules; exiting."
201 def build_target(addlargs, targetmap):
203 if not targetmap.has_key(addlargs["target"]):
204 raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
206 mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
211 catalyst.util.print_traceback()
212 print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
215 if __name__ == "__main__":
220 # catalyst cannot be run as a normal user due to chroots, mounts, etc
221 print "!!! catalyst: This script requires root privileges to operate"
224 # we need some options in order to work correctly
225 if len(sys.argv) < 2:
229 # parse out the command line arguments
231 opts,args = getopt.getopt(sys.argv[1:], "apPhvdc:C:f:FVs:", ["purge", "purgeonly", "help", "version", "debug",\
232 "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
234 except getopt.GetoptError:
238 # defaults for commandline opts
247 # check preconditions
249 print "!!! catalyst: please specify one of either -f or -C\n"
255 if o in ("-h", "--help"):
259 if o in ("-V", "--version"):
260 print "Catalyst version "+__version__
263 if o in ("-d", "--debug"):
264 conf_values["DEBUG"]="1"
265 conf_values["VERBOSE"]="1"
267 if o in ("-c", "--config"):
270 if o in ("-C", "--cli"):
272 x=sys.argv.index(o)+1
273 while x < len(sys.argv):
274 mycmdline.append(sys.argv[x])
277 if o in ("-f", "--file"):
281 if o in ("-F", "--fetchonly"):
282 conf_values["FETCH"]="1"
284 if o in ("-v", "--verbose"):
285 conf_values["VERBOSE"]="1"
287 if o in ("-s", "--snapshot"):
288 if len(sys.argv) < 3:
289 print "!!! catalyst: missing snapshot identifier\n"
294 mycmdline.append("target=snapshot")
295 mycmdline.append("version_stamp="+a)
297 if o in ("-p", "--purge"):
298 conf_values["PURGE"] = "1"
300 if o in ("-P", "--purgeonly"):
301 conf_values["PURGEONLY"] = "1"
303 if o in ("-a", "--clear-autoresume"):
304 conf_values["CLEAR_AUTORESUME"] = "1"
307 print "!!! catalyst: please specify one of either -f or -C\n"
311 # import configuration file and import our main module using those settings
312 parse_config(myconfig)
313 sys.path.append(conf_values["sharedir"]+"/modules")
314 from catalyst_support import *
316 # Start checking that digests are valid now that the hash_map was imported from catalyst_support
317 if conf_values.has_key("digests"):
318 for i in conf_values["digests"].split():
319 if not hash_map.has_key(i):
321 print i+" is not a valid digest entry"
322 print "Valid digest entries:"
323 print hash_map.keys()
325 print "Catalyst aborting...."
327 if find_binary(hash_map[i][1]) == None:
330 print "\tThe "+hash_map[i][1]+\
331 " binary was not found. It needs to be in your system path"
333 print "Catalyst aborting...."
335 if conf_values.has_key("hash_function"):
336 if not hash_map.has_key(conf_values["hash_function"]):
338 print conf_values["hash_function"]+" is not a valid hash_function entry"
339 print "Valid hash_function entries:"
340 print hash_map.keys()
342 print "Catalyst aborting...."
344 if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
346 print "hash_function="+conf_values["hash_function"]
347 print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
348 " binary was not found. It needs to be in your system path"
350 print "Catalyst aborting...."
353 # import the rest of the catalyst modules
354 targetmap=import_modules()
359 spec = catalyst.config.SpecParser(myspecfile)
360 addlargs.update(spec.get_values())
364 cmdline = catalyst.config.ConfigParser()
365 cmdline.parse_lines(mycmdline)
366 addlargs.update(cmdline.get_values())
367 except CatalystError:
368 print "!!! catalyst: Could not parse commandline, exiting."
371 if not addlargs.has_key("target"):
372 raise CatalystError, "Required value \"target\" not specified."
374 # everything is setup, so the build is a go
376 build_target(addlargs, targetmap)
378 except CatalystError:
380 print "Catalyst aborting...."
382 except KeyboardInterrupt:
383 print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )"
385 print "Catalyst aborting...."
388 print "Catalyst aborting...."
391 print "Catalyst aborting...."
395 #except CatalystError:
397 # print "Catalyst aborting...."
400 # print "\nproblem with command line or spec file ( Key Error )"
401 # print "Key: "+str(sys.exc_value)+" was not found"
402 # print "Catalyst aborting...."
404 #except UnboundLocalError:
406 # print "UnboundLocalError: "+str(sys.exc_value)+" was not found"
409 # print "Catalyst aborting...."