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>
18 import modules.catalyst.config
19 import modules.catalyst.util
21 __maintainer__="Catalyst <catalyst@gentoo.org>"
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
65 "distdir": "/usr/portage/distfiles",
66 "hash_function": "crc32",
68 "packagedir": "/usr/portage/packages",
69 "portdir": "/usr/portage",
70 "repo_name": "portage",
71 "sharedir": "/usr/share/catalyst",
72 "snapshot_name": "portage-",
73 "snapshot_cache": "/var/tmp/catalyst/snapshot_cache",
74 "storedir": "/var/tmp/catalyst",
77 # first, try the one passed (presumably from the cmdline)
79 if os.path.exists(myconfig):
80 print "Using command line specified Catalyst configuration file, "+myconfig
84 print "!!! catalyst: Could not use specified configuration file "+\
88 # next, try the default location
89 elif os.path.exists("/etc/catalyst/catalyst.conf"):
90 print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf"
91 config_file="/etc/catalyst/catalyst.conf"
93 # can't find a config file (we are screwed), so bail out
95 print "!!! catalyst: Could not find a suitable configuration file"
98 # now, try and parse the config file "config_file"
100 # execfile(config_file, myconf, myconf)
101 myconfig = modules.catalyst.config.ConfigParser(config_file)
102 myconf.update(myconfig.get_values())
105 print "!!! catalyst: Unable to parse configuration file, "+myconfig
108 # now, load up the values into conf_values so that we can use them
109 for x in confdefaults.keys():
111 print "Setting",x,"to config file value \""+myconf[x]+"\""
112 conf_values[x]=myconf[x]
114 print "Setting",x,"to default value \""+confdefaults[x]+"\""
115 conf_values[x]=confdefaults[x]
117 # parse out the rest of the options from the config file
118 if "autoresume" in string.split(conf_values["options"]):
119 print "Autoresuming support enabled."
120 conf_values["AUTORESUME"]="1"
122 if "bindist" in string.split(conf_values["options"]):
123 print "Binary redistribution enabled"
124 conf_values["BINDIST"]="1"
126 print "Bindist is not enabled in catalyst.conf"
127 print "Binary redistribution of generated stages/isos may be prohibited by law."
128 print "Please see the use description for bindist on any package you are including."
130 if "ccache" in string.split(conf_values["options"]):
131 print "Compiler cache support enabled."
132 conf_values["CCACHE"]="1"
134 if "clear-autoresume" in string.split(conf_values["options"]):
135 print "Cleaning autoresume flags support enabled."
136 conf_values["CLEAR_AUTORESUME"]="1"
138 if "distcc" in string.split(conf_values["options"]):
139 print "Distcc support enabled."
140 conf_values["DISTCC"]="1"
142 if "icecream" in string.split(conf_values["options"]):
143 print "Icecream compiler cluster support enabled."
144 conf_values["ICECREAM"]="1"
146 if "kerncache" in string.split(conf_values["options"]):
147 print "Kernel cache support enabled."
148 conf_values["KERNCACHE"]="1"
150 if "pkgcache" in string.split(conf_values["options"]):
151 print "Package cache support enabled."
152 conf_values["PKGCACHE"]="1"
154 if "preserve_libs" in string.split(conf_values["options"]):
155 print "Preserving libs during unmerge."
156 conf_values["PRESERVE_LIBS"]="1"
158 if "purge" in string.split(conf_values["options"]):
159 print "Purge support enabled."
160 conf_values["PURGE"]="1"
162 if "seedcache" in string.split(conf_values["options"]):
163 print "Seed cache support enabled."
164 conf_values["SEEDCACHE"]="1"
166 if "snapcache" in string.split(conf_values["options"]):
167 print "Snapshot cache support enabled."
168 conf_values["SNAPCACHE"]="1"
170 if "digests" in myconf:
171 conf_values["digests"]=myconf["digests"]
172 if "contents" in myconf:
173 conf_values["contents"]=myconf["contents"]
175 if "envscript" in myconf:
176 print "Envscript support enabled."
177 conf_values["ENVSCRIPT"]=myconf["envscript"]
179 if "var_tmpfs_portage" in myconf:
180 conf_values["var_tmpfs_portage"]=myconf["var_tmpfs_portage"];
182 if "port_logdir" in myconf:
183 conf_values["port_logdir"]=myconf["port_logdir"];
185 def import_modules():
186 # import catalyst's own modules (i.e. catalyst_support and the arch modules)
190 for x in required_build_targets:
192 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
193 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
197 raise CatalystError,"Can't find "+x+".py plugin in "+\
198 conf_values["sharedir"]+"/modules/"
200 for x in valid_build_targets:
202 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
203 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
204 module.register(targetmap)
208 raise CatalystError,"Can't find "+x+".py plugin in "+\
209 conf_values["sharedir"]+"/modules/"
212 print "!!! catalyst: Python modules not found in "+\
213 conf_values["sharedir"]+"/modules; exiting."
218 def build_target(addlargs, targetmap):
220 if addlargs["target"] not in targetmap:
221 raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
223 mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
228 modules.catalyst.util.print_traceback()
229 print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
232 if __name__ == "__main__":
237 # catalyst cannot be run as a normal user due to chroots, mounts, etc
238 print "!!! catalyst: This script requires root privileges to operate"
241 # we need some options in order to work correctly
242 if len(sys.argv) < 2:
246 # parse out the command line arguments
248 opts,args = getopt.getopt(sys.argv[1:], "apPThvdc:C:f:FVs:", ["purge", "purgeonly", "purgetmponly", "help", "version", "debug",\
249 "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
251 except getopt.GetoptError:
255 # defaults for commandline opts
264 # check preconditions
266 print "!!! catalyst: please specify one of either -f or -C\n"
272 if o in ("-h", "--help"):
276 if o in ("-V", "--version"):
277 print "Catalyst version "+__version__
280 if o in ("-d", "--debug"):
281 conf_values["DEBUG"]="1"
282 conf_values["VERBOSE"]="1"
284 if o in ("-c", "--config"):
287 if o in ("-C", "--cli"):
289 x=sys.argv.index(o)+1
290 while x < len(sys.argv):
291 mycmdline.append(sys.argv[x])
294 if o in ("-f", "--file"):
298 if o in ("-F", "--fetchonly"):
299 conf_values["FETCH"]="1"
301 if o in ("-v", "--verbose"):
302 conf_values["VERBOSE"]="1"
304 if o in ("-s", "--snapshot"):
305 if len(sys.argv) < 3:
306 print "!!! catalyst: missing snapshot identifier\n"
311 mycmdline.append("target=snapshot")
312 mycmdline.append("version_stamp="+a)
314 if o in ("-p", "--purge"):
315 conf_values["PURGE"] = "1"
317 if o in ("-P", "--purgeonly"):
318 conf_values["PURGEONLY"] = "1"
320 if o in ("-T", "--purgetmponly"):
321 conf_values["PURGETMPONLY"] = "1"
323 if o in ("-a", "--clear-autoresume"):
324 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
337 # from catalyst_support
338 if "digests" in conf_values:
339 for i in conf_values["digests"].split():
340 if i not in hash_map:
342 print i+" is not a valid digest entry"
343 print "Valid digest entries:"
344 print hash_map.keys()
346 print "Catalyst aborting...."
348 if find_binary(hash_map[i][1]) == None:
351 print "\tThe "+hash_map[i][1]+\
352 " binary was not found. It needs to be in your system path"
354 print "Catalyst aborting...."
356 if "hash_function" in conf_values:
357 if conf_values["hash_function"] not in hash_map:
359 print conf_values["hash_function"]+\
360 " is not a valid hash_function entry"
361 print "Valid hash_function entries:"
362 print hash_map.keys()
364 print "Catalyst aborting...."
366 if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
368 print "hash_function="+conf_values["hash_function"]
369 print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
370 " binary was not found. It needs to be in your system path"
372 print "Catalyst aborting...."
375 # import the rest of the catalyst modules
376 targetmap=import_modules()
381 spec = modules.catalyst.config.SpecParser(myspecfile)
382 addlargs.update(spec.get_values())
386 cmdline = modules.catalyst.config.ConfigParser()
387 cmdline.parse_lines(mycmdline)
388 addlargs.update(cmdline.get_values())
389 except CatalystError:
390 print "!!! catalyst: Could not parse commandline, exiting."
393 if "target" not in addlargs:
394 raise CatalystError, "Required value \"target\" not specified."
396 # everything is setup, so the build is a go
398 build_target(addlargs, targetmap)
400 except CatalystError:
402 print "Catalyst aborting...."
404 except KeyboardInterrupt:
405 print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )"
407 print "Catalyst aborting...."
410 print "Catalyst aborting...."
413 print "Catalyst aborting...."