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 -a --clear-autoresume clear autoresume flags
29 -c --config use specified configuration file
30 -C --cli catalyst commandline (MUST BE LAST OPTION)
31 -d --debug enable debugging
32 -f --file read specfile
33 -F --fetchonly fetch files only
34 -h --help print this help message
35 -p --purge clear tmp dirs,package cache, autoresume flags
36 -P --purgeonly clear tmp dirs,package cache, autoresume flags and exit
37 -T --purgetmponly clear tmp dirs and autoresume flags and exit
38 -s --snapshot generate a release snapshot
39 -V --version display version information
40 -v --verbose verbose output
44 Using the commandline option (-C, --cli) to build a Portage snapshot:
45 catalyst -C target=snapshot version_stamp=my_date
47 Using the snapshot option (-s, --snapshot) to build a release snapshot:
50 Using the specfile option (-f, --file) to build a stage target:
51 catalyst -f stage1-specfile.spec
56 print "Catalyst, version "+__version__
57 print "Copyright 2003-2008 Gentoo Foundation"
58 print "Copyright 2008-2012 various authors"
59 print "Distributed under the GNU General Public License version 2.1\n"
61 def parse_config(myconfig):
62 # search a couple of different areas for the main config file
67 "distdir": "/usr/portage/distfiles",
68 "hash_function": "crc32",
70 "packagedir": "/usr/portage/packages",
71 "portdir": "/usr/portage",
72 "repo_name": "portage",
73 "sharedir": "/usr/share/catalyst",
74 "snapshot_name": "portage-",
75 "snapshot_cache": "/var/tmp/catalyst/snapshot_cache",
76 "storedir": "/var/tmp/catalyst",
79 # first, try the one passed (presumably from the cmdline)
81 if os.path.exists(myconfig):
82 print "Using command line specified Catalyst configuration file, "+myconfig
86 print "!!! catalyst: Could not use specified configuration file "+\
90 # next, try the default location
91 elif os.path.exists("/etc/catalyst/catalyst.conf"):
92 print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf"
93 config_file="/etc/catalyst/catalyst.conf"
95 # can't find a config file (we are screwed), so bail out
97 print "!!! catalyst: Could not find a suitable configuration file"
100 # now, try and parse the config file "config_file"
102 # execfile(config_file, myconf, myconf)
103 myconfig = modules.catalyst.config.ConfigParser(config_file)
104 myconf.update(myconfig.get_values())
107 print "!!! catalyst: Unable to parse configuration file, "+myconfig
110 # now, load up the values into conf_values so that we can use them
111 for x in confdefaults.keys():
113 print "Setting",x,"to config file value \""+myconf[x]+"\""
114 conf_values[x]=myconf[x]
116 print "Setting",x,"to default value \""+confdefaults[x]+"\""
117 conf_values[x]=confdefaults[x]
119 # parse out the rest of the options from the config file
120 if "autoresume" in string.split(conf_values["options"]):
121 print "Autoresuming support enabled."
122 conf_values["AUTORESUME"]="1"
124 if "bindist" in string.split(conf_values["options"]):
125 print "Binary redistribution enabled"
126 conf_values["BINDIST"]="1"
128 print "Bindist is not enabled in catalyst.conf"
129 print "Binary redistribution of generated stages/isos may be prohibited by law."
130 print "Please see the use description for bindist on any package you are including."
132 if "ccache" in string.split(conf_values["options"]):
133 print "Compiler cache support enabled."
134 conf_values["CCACHE"]="1"
136 if "clear-autoresume" in string.split(conf_values["options"]):
137 print "Cleaning autoresume flags support enabled."
138 conf_values["CLEAR_AUTORESUME"]="1"
140 if "distcc" in string.split(conf_values["options"]):
141 print "Distcc support enabled."
142 conf_values["DISTCC"]="1"
144 if "icecream" in string.split(conf_values["options"]):
145 print "Icecream compiler cluster support enabled."
146 conf_values["ICECREAM"]="1"
148 if "kerncache" in string.split(conf_values["options"]):
149 print "Kernel cache support enabled."
150 conf_values["KERNCACHE"]="1"
152 if "pkgcache" in string.split(conf_values["options"]):
153 print "Package cache support enabled."
154 conf_values["PKGCACHE"]="1"
156 if "preserve_libs" in string.split(conf_values["options"]):
157 print "Preserving libs during unmerge."
158 conf_values["PRESERVE_LIBS"]="1"
160 if "purge" in string.split(conf_values["options"]):
161 print "Purge support enabled."
162 conf_values["PURGE"]="1"
164 if "seedcache" in string.split(conf_values["options"]):
165 print "Seed cache support enabled."
166 conf_values["SEEDCACHE"]="1"
168 if "snapcache" in string.split(conf_values["options"]):
169 print "Snapshot cache support enabled."
170 conf_values["SNAPCACHE"]="1"
172 if "digests" in myconf:
173 conf_values["digests"]=myconf["digests"]
174 if "contents" in myconf:
175 conf_values["contents"]=myconf["contents"]
177 if "envscript" in myconf:
178 print "Envscript support enabled."
179 conf_values["ENVSCRIPT"]=myconf["envscript"]
181 if "var_tmpfs_portage" in myconf:
182 conf_values["var_tmpfs_portage"]=myconf["var_tmpfs_portage"];
184 if "port_logdir" in myconf:
185 conf_values["port_logdir"]=myconf["port_logdir"];
187 def import_modules():
188 # import catalyst's own modules (i.e. catalyst_support and the arch modules)
192 for x in required_build_targets:
194 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
195 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
199 raise CatalystError,"Can't find "+x+".py plugin in "+\
200 conf_values["sharedir"]+"/modules/"
202 for x in valid_build_targets:
204 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
205 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
206 module.register(targetmap)
210 raise CatalystError,"Can't find "+x+".py plugin in "+\
211 conf_values["sharedir"]+"/modules/"
214 print "!!! catalyst: Python modules not found in "+\
215 conf_values["sharedir"]+"/modules; exiting."
220 def build_target(addlargs, targetmap):
222 if addlargs["target"] not in targetmap:
223 raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
225 mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
230 modules.catalyst.util.print_traceback()
231 print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
234 if __name__ == "__main__":
239 # catalyst cannot be run as a normal user due to chroots, mounts, etc
240 print "!!! catalyst: This script requires root privileges to operate"
243 # we need some options in order to work correctly
244 if len(sys.argv) < 2:
248 # parse out the command line arguments
250 opts,args = getopt.getopt(sys.argv[1:], "apPThvdc:C:f:FVs:", ["purge", "purgeonly", "purgetmponly", "help", "version", "debug",\
251 "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
253 except getopt.GetoptError:
257 # defaults for commandline opts
266 # check preconditions
268 print "!!! catalyst: please specify one of either -f or -C\n"
274 if o in ("-h", "--help"):
278 if o in ("-V", "--version"):
279 print "Catalyst version "+__version__
282 if o in ("-d", "--debug"):
283 conf_values["DEBUG"]="1"
284 conf_values["VERBOSE"]="1"
286 if o in ("-c", "--config"):
289 if o in ("-C", "--cli"):
291 x=sys.argv.index(o)+1
292 while x < len(sys.argv):
293 mycmdline.append(sys.argv[x])
296 if o in ("-f", "--file"):
300 if o in ("-F", "--fetchonly"):
301 conf_values["FETCH"]="1"
303 if o in ("-v", "--verbose"):
304 conf_values["VERBOSE"]="1"
306 if o in ("-s", "--snapshot"):
307 if len(sys.argv) < 3:
308 print "!!! catalyst: missing snapshot identifier\n"
313 mycmdline.append("target=snapshot")
314 mycmdline.append("version_stamp="+a)
316 if o in ("-p", "--purge"):
317 conf_values["PURGE"] = "1"
319 if o in ("-P", "--purgeonly"):
320 conf_values["PURGEONLY"] = "1"
322 if o in ("-T", "--purgetmponly"):
323 conf_values["PURGETMPONLY"] = "1"
325 if o in ("-a", "--clear-autoresume"):
326 conf_values["CLEAR_AUTORESUME"] = "1"
329 print "!!! catalyst: please specify one of either -f or -C\n"
333 # import configuration file and import our main module using those settings
334 parse_config(myconfig)
335 sys.path.append(conf_values["sharedir"]+"/modules")
336 from catalyst_support import *
338 # Start checking that digests are valid now that the hash_map was imported
339 # from catalyst_support
340 if "digests" in conf_values:
341 for i in conf_values["digests"].split():
342 if i not in hash_map:
344 print i+" is not a valid digest entry"
345 print "Valid digest entries:"
346 print hash_map.keys()
348 print "Catalyst aborting...."
350 if find_binary(hash_map[i][1]) == None:
353 print "\tThe "+hash_map[i][1]+\
354 " binary was not found. It needs to be in your system path"
356 print "Catalyst aborting...."
358 if "hash_function" in conf_values:
359 if conf_values["hash_function"] not in hash_map:
361 print conf_values["hash_function"]+\
362 " is not a valid hash_function entry"
363 print "Valid hash_function entries:"
364 print hash_map.keys()
366 print "Catalyst aborting...."
368 if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
370 print "hash_function="+conf_values["hash_function"]
371 print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
372 " binary was not found. It needs to be in your system path"
374 print "Catalyst aborting...."
377 # import the rest of the catalyst modules
378 targetmap=import_modules()
383 spec = modules.catalyst.config.SpecParser(myspecfile)
384 addlargs.update(spec.get_values())
388 cmdline = modules.catalyst.config.ConfigParser()
389 cmdline.parse_lines(mycmdline)
390 addlargs.update(cmdline.get_values())
391 except CatalystError:
392 print "!!! catalyst: Could not parse commandline, exiting."
395 if "target" not in addlargs:
396 raise CatalystError, "Required value \"target\" not specified."
398 # everything is setup, so the build is a go
400 build_target(addlargs, targetmap)
402 except CatalystError:
404 print "Catalyst aborting...."
406 except KeyboardInterrupt:
407 print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )"
409 print "Catalyst aborting...."
412 print "Catalyst aborting...."
415 print "Catalyst aborting...."