2 # Maintained in full by:
3 # Catalyst Team <catalyst@gentoo.org>
4 # Release Engineering Team <releng@gentoo.org>
5 # Andrew Gaffney <agaffney@gentoo.org>
6 # Chris Gianelloni <wolf31o2@wolf31o2.org>
17 __selfpath__ = os.path.abspath(os.path.dirname(__file__))
19 sys.path.append(__selfpath__ + "/modules")
21 import catalyst.config
23 from catalyst.support import (required_build_targets,
24 valid_build_targets, CatalystError, hash_map, find_binary, LockInUse)
26 __maintainer__="Catalyst <catalyst@gentoo.org>"
32 print """Usage catalyst [options] [-C variable=value...] [ -s identifier]
33 -a --clear-autoresume clear autoresume flags
34 -c --config use specified configuration file
35 -C --cli catalyst commandline (MUST BE LAST OPTION)
36 -d --debug enable debugging
37 -f --file read specfile
38 -F --fetchonly fetch files only
39 -h --help print this help message
40 -p --purge clear tmp dirs,package cache, autoresume flags
41 -P --purgeonly clear tmp dirs,package cache, autoresume flags and exit
42 -T --purgetmponly clear tmp dirs and autoresume flags and exit
43 -s --snapshot generate a release snapshot
44 -V --version display version information
45 -v --verbose verbose output
49 Using the commandline option (-C, --cli) to build a Portage snapshot:
50 catalyst -C target=snapshot version_stamp=my_date
52 Using the snapshot option (-s, --snapshot) to build a release snapshot:
55 Using the specfile option (-f, --file) to build a stage target:
56 catalyst -f stage1-specfile.spec
61 print "Catalyst, version "+__version__
62 print "Copyright 2003-2008 Gentoo Foundation"
63 print "Copyright 2008-2012 various authors"
64 print "Distributed under the GNU General Public License version 2.1\n"
66 def parse_config(myconfig):
67 # search a couple of different areas for the main config file
72 "distdir": "/usr/portage/distfiles",
73 "hash_function": "crc32",
74 "icecream": "/var/cache/icecream",
75 "local_overlay": "/usr/local/portage",
77 "packagedir": "/usr/portage/packages",
78 "portdir": "/usr/portage",
79 "repo_name": "portage",
80 "sharedir": "/usr/share/catalyst",
81 "snapshot_name": "portage-",
82 "snapshot_cache": "/var/tmp/catalyst/snapshot_cache",
83 "storedir": "/var/tmp/catalyst",
86 # first, try the one passed (presumably from the cmdline)
88 if os.path.exists(myconfig):
89 print "Using command line specified Catalyst configuration file, "+myconfig
93 print "!!! catalyst: Could not use specified configuration file "+\
97 # next, try the default location
98 elif os.path.exists("/etc/catalyst/catalyst.conf"):
99 print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf"
100 config_file="/etc/catalyst/catalyst.conf"
102 # can't find a config file (we are screwed), so bail out
104 print "!!! catalyst: Could not find a suitable configuration file"
107 # now, try and parse the config file "config_file"
109 # execfile(config_file, myconf, myconf)
110 myconfig = catalyst.config.ConfigParser(config_file)
111 myconf.update(myconfig.get_values())
114 print "!!! catalyst: Unable to parse configuration file, "+myconfig
117 # now, load up the values into conf_values so that we can use them
118 for x in confdefaults.keys():
120 print "Setting",x,"to config file value \""+myconf[x]+"\""
121 conf_values[x]=myconf[x]
123 print "Setting",x,"to default value \""+confdefaults[x]+"\""
124 conf_values[x]=confdefaults[x]
126 # add our python base directory to use for loading target arch's
127 conf_values["PythonDir"] = __selfpath__
129 # parse out the rest of the options from the config file
130 if "autoresume" in string.split(conf_values["options"]):
131 print "Autoresuming support enabled."
132 conf_values["AUTORESUME"]="1"
134 if "bindist" in string.split(conf_values["options"]):
135 print "Binary redistribution enabled"
136 conf_values["BINDIST"]="1"
138 print "Bindist is not enabled in catalyst.conf"
139 print "Binary redistribution of generated stages/isos may be prohibited by law."
140 print "Please see the use description for bindist on any package you are including."
142 if "ccache" in string.split(conf_values["options"]):
143 print "Compiler cache support enabled."
144 conf_values["CCACHE"]="1"
146 if "clear-autoresume" in string.split(conf_values["options"]):
147 print "Cleaning autoresume flags support enabled."
148 conf_values["CLEAR_AUTORESUME"]="1"
150 if "distcc" in string.split(conf_values["options"]):
151 print "Distcc support enabled."
152 conf_values["DISTCC"]="1"
154 if "icecream" in string.split(conf_values["options"]):
155 print "Icecream compiler cluster support enabled."
156 conf_values["ICECREAM"]="1"
158 if "kerncache" in string.split(conf_values["options"]):
159 print "Kernel cache support enabled."
160 conf_values["KERNCACHE"]="1"
162 if "pkgcache" in string.split(conf_values["options"]):
163 print "Package cache support enabled."
164 conf_values["PKGCACHE"]="1"
166 if "preserve_libs" in string.split(conf_values["options"]):
167 print "Preserving libs during unmerge."
168 conf_values["PRESERVE_LIBS"]="1"
170 if "purge" in string.split(conf_values["options"]):
171 print "Purge support enabled."
172 conf_values["PURGE"]="1"
174 if "seedcache" in string.split(conf_values["options"]):
175 print "Seed cache support enabled."
176 conf_values["SEEDCACHE"]="1"
178 if "snapcache" in string.split(conf_values["options"]):
179 print "Snapshot cache support enabled."
180 conf_values["SNAPCACHE"]="1"
182 if "digests" in myconf:
183 conf_values["digests"]=myconf["digests"]
184 if "contents" in myconf:
185 conf_values["contents"]=myconf["contents"]
187 if "envscript" in myconf:
188 print "Envscript support enabled."
189 conf_values["ENVSCRIPT"]=myconf["envscript"]
191 if "var_tmpfs_portage" in myconf:
192 conf_values["var_tmpfs_portage"]=myconf["var_tmpfs_portage"];
194 if "port_logdir" in myconf:
195 conf_values["port_logdir"]=myconf["port_logdir"];
197 def import_modules():
198 # import catalyst's own modules
199 # (i.e. stage and the arch modules)
203 module_dir = __selfpath__ + "/targets/"
204 for x in required_build_targets:
206 fh=open(module_dir + x + ".py")
207 module=imp.load_module(x, fh,"targets/" + x + ".py",
208 (".py", "r", imp.PY_SOURCE))
212 raise CatalystError, "Can't find " + x + ".py plugin in " + \
214 for x in valid_build_targets:
216 fh=open(module_dir + x + ".py")
217 module=imp.load_module(x, fh, "targets/" + x + ".py",
218 (".py", "r", imp.PY_SOURCE))
219 module.register(targetmap)
223 raise CatalystError,"Can't find " + x + ".py plugin in " + \
227 print "!!! catalyst: Python modules not found in "+\
228 module_dir + "; exiting."
233 def build_target(addlargs, targetmap):
235 if addlargs["target"] not in targetmap:
236 raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
238 mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
243 catalyst.util.print_traceback()
244 print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
252 # catalyst cannot be run as a normal user due to chroots, mounts, etc
253 print "!!! catalyst: This script requires root privileges to operate"
256 # we need some options in order to work correctly
257 if len(sys.argv) < 2:
261 # parse out the command line arguments
263 opts,args = getopt.getopt(sys.argv[1:], "apPThvdc:C:f:FVs:", ["purge", "purgeonly", "purgetmponly", "help", "version", "debug",\
264 "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
266 except getopt.GetoptError:
270 # defaults for commandline opts
279 # check preconditions
281 print "!!! catalyst: please specify one of either -f or -C\n"
287 if o in ("-h", "--help"):
291 if o in ("-V", "--version"):
292 print "Catalyst version "+__version__
295 if o in ("-d", "--debug"):
296 conf_values["DEBUG"]="1"
297 conf_values["VERBOSE"]="1"
299 if o in ("-c", "--config"):
302 if o in ("-C", "--cli"):
304 x=sys.argv.index(o)+1
305 while x < len(sys.argv):
306 mycmdline.append(sys.argv[x])
309 if o in ("-f", "--file"):
313 if o in ("-F", "--fetchonly"):
314 conf_values["FETCH"]="1"
316 if o in ("-v", "--verbose"):
317 conf_values["VERBOSE"]="1"
319 if o in ("-s", "--snapshot"):
320 if len(sys.argv) < 3:
321 print "!!! catalyst: missing snapshot identifier\n"
326 mycmdline.append("target=snapshot")
327 mycmdline.append("version_stamp="+a)
329 if o in ("-p", "--purge"):
330 conf_values["PURGE"] = "1"
332 if o in ("-P", "--purgeonly"):
333 conf_values["PURGEONLY"] = "1"
335 if o in ("-T", "--purgetmponly"):
336 conf_values["PURGETMPONLY"] = "1"
338 if o in ("-a", "--clear-autoresume"):
339 conf_values["CLEAR_AUTORESUME"] = "1"
342 print "!!! catalyst: please specify one of either -f or -C\n"
346 # import configuration file and import our main module using those settings
347 parse_config(myconfig)
349 # Start checking that digests are valid now that the hash_map was imported
350 # from catalyst.support
351 if "digests" in conf_values:
352 for i in conf_values["digests"].split():
353 if i not in hash_map:
355 print i+" is not a valid digest entry"
356 print "Valid digest entries:"
357 print hash_map.keys()
359 print "Catalyst aborting...."
361 if find_binary(hash_map[i][1]) == None:
364 print "\tThe "+hash_map[i][1]+\
365 " binary was not found. It needs to be in your system path"
367 print "Catalyst aborting...."
369 if "hash_function" in conf_values:
370 if conf_values["hash_function"] not in hash_map:
372 print conf_values["hash_function"]+\
373 " is not a valid hash_function entry"
374 print "Valid hash_function entries:"
375 print hash_map.keys()
377 print "Catalyst aborting...."
379 if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
381 print "hash_function="+conf_values["hash_function"]
382 print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
383 " binary was not found. It needs to be in your system path"
385 print "Catalyst aborting...."
388 # import the rest of the catalyst modules
389 targetmap=import_modules()
394 spec = catalyst.config.SpecParser(myspecfile)
395 addlargs.update(spec.get_values())
399 cmdline = catalyst.config.ConfigParser()
400 cmdline.parse_lines(mycmdline)
401 addlargs.update(cmdline.get_values())
402 except CatalystError:
403 print "!!! catalyst: Could not parse commandline, exiting."
406 if "target" not in addlargs:
407 raise CatalystError, "Required value \"target\" not specified."
409 # everything is setup, so the build is a go
411 build_target(addlargs, targetmap)
413 except CatalystError:
415 print "Catalyst aborting...."
417 except KeyboardInterrupt:
418 print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )"
420 print "Catalyst aborting...."
423 print "Catalyst aborting...."
426 print "Catalyst aborting...."