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",
69 "icecream": "/var/cache/icecream",
70 "local_overlay": "/usr/local/portage",
72 "packagedir": "/usr/portage/packages",
73 "portdir": "/usr/portage",
74 "repo_name": "portage",
75 "sharedir": "/usr/share/catalyst",
76 "snapshot_name": "portage-",
77 "snapshot_cache": "/var/tmp/catalyst/snapshot_cache",
78 "storedir": "/var/tmp/catalyst",
81 # first, try the one passed (presumably from the cmdline)
83 if os.path.exists(myconfig):
84 print "Using command line specified Catalyst configuration file, "+myconfig
88 print "!!! catalyst: Could not use specified configuration file "+\
92 # next, try the default location
93 elif os.path.exists("/etc/catalyst/catalyst.conf"):
94 print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf"
95 config_file="/etc/catalyst/catalyst.conf"
97 # can't find a config file (we are screwed), so bail out
99 print "!!! catalyst: Could not find a suitable configuration file"
102 # now, try and parse the config file "config_file"
104 # execfile(config_file, myconf, myconf)
105 myconfig = modules.catalyst.config.ConfigParser(config_file)
106 myconf.update(myconfig.get_values())
109 print "!!! catalyst: Unable to parse configuration file, "+myconfig
112 # now, load up the values into conf_values so that we can use them
113 for x in confdefaults.keys():
115 print "Setting",x,"to config file value \""+myconf[x]+"\""
116 conf_values[x]=myconf[x]
118 print "Setting",x,"to default value \""+confdefaults[x]+"\""
119 conf_values[x]=confdefaults[x]
121 # parse out the rest of the options from the config file
122 if "autoresume" in string.split(conf_values["options"]):
123 print "Autoresuming support enabled."
124 conf_values["AUTORESUME"]="1"
126 if "bindist" in string.split(conf_values["options"]):
127 print "Binary redistribution enabled"
128 conf_values["BINDIST"]="1"
130 print "Bindist is not enabled in catalyst.conf"
131 print "Binary redistribution of generated stages/isos may be prohibited by law."
132 print "Please see the use description for bindist on any package you are including."
134 if "ccache" in string.split(conf_values["options"]):
135 print "Compiler cache support enabled."
136 conf_values["CCACHE"]="1"
138 if "clear-autoresume" in string.split(conf_values["options"]):
139 print "Cleaning autoresume flags support enabled."
140 conf_values["CLEAR_AUTORESUME"]="1"
142 if "distcc" in string.split(conf_values["options"]):
143 print "Distcc support enabled."
144 conf_values["DISTCC"]="1"
146 if "icecream" in string.split(conf_values["options"]):
147 print "Icecream compiler cluster support enabled."
148 conf_values["ICECREAM"]="1"
150 if "kerncache" in string.split(conf_values["options"]):
151 print "Kernel cache support enabled."
152 conf_values["KERNCACHE"]="1"
154 if "pkgcache" in string.split(conf_values["options"]):
155 print "Package cache support enabled."
156 conf_values["PKGCACHE"]="1"
158 if "preserve_libs" in string.split(conf_values["options"]):
159 print "Preserving libs during unmerge."
160 conf_values["PRESERVE_LIBS"]="1"
162 if "purge" in string.split(conf_values["options"]):
163 print "Purge support enabled."
164 conf_values["PURGE"]="1"
166 if "seedcache" in string.split(conf_values["options"]):
167 print "Seed cache support enabled."
168 conf_values["SEEDCACHE"]="1"
170 if "snapcache" in string.split(conf_values["options"]):
171 print "Snapshot cache support enabled."
172 conf_values["SNAPCACHE"]="1"
174 if "digests" in myconf:
175 conf_values["digests"]=myconf["digests"]
176 if "contents" in myconf:
177 conf_values["contents"]=myconf["contents"]
179 if "envscript" in myconf:
180 print "Envscript support enabled."
181 conf_values["ENVSCRIPT"]=myconf["envscript"]
183 if "var_tmpfs_portage" in myconf:
184 conf_values["var_tmpfs_portage"]=myconf["var_tmpfs_portage"];
186 if "port_logdir" in myconf:
187 conf_values["port_logdir"]=myconf["port_logdir"];
189 def import_modules():
190 # import catalyst's own modules (i.e. catalyst_support and the arch modules)
194 for x in required_build_targets:
196 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
197 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
201 raise CatalystError,"Can't find "+x+".py plugin in "+\
202 conf_values["sharedir"]+"/modules/"
204 for x in valid_build_targets:
206 fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
207 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
208 module.register(targetmap)
212 raise CatalystError,"Can't find "+x+".py plugin in "+\
213 conf_values["sharedir"]+"/modules/"
216 print "!!! catalyst: Python modules not found in "+\
217 conf_values["sharedir"]+"/modules; exiting."
222 def build_target(addlargs, targetmap):
224 if addlargs["target"] not in targetmap:
225 raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
227 mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
232 modules.catalyst.util.print_traceback()
233 print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
236 if __name__ == "__main__":
241 # catalyst cannot be run as a normal user due to chroots, mounts, etc
242 print "!!! catalyst: This script requires root privileges to operate"
245 # we need some options in order to work correctly
246 if len(sys.argv) < 2:
250 # parse out the command line arguments
252 opts,args = getopt.getopt(sys.argv[1:], "apPThvdc:C:f:FVs:", ["purge", "purgeonly", "purgetmponly", "help", "version", "debug",\
253 "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
255 except getopt.GetoptError:
259 # defaults for commandline opts
268 # check preconditions
270 print "!!! catalyst: please specify one of either -f or -C\n"
276 if o in ("-h", "--help"):
280 if o in ("-V", "--version"):
281 print "Catalyst version "+__version__
284 if o in ("-d", "--debug"):
285 conf_values["DEBUG"]="1"
286 conf_values["VERBOSE"]="1"
288 if o in ("-c", "--config"):
291 if o in ("-C", "--cli"):
293 x=sys.argv.index(o)+1
294 while x < len(sys.argv):
295 mycmdline.append(sys.argv[x])
298 if o in ("-f", "--file"):
302 if o in ("-F", "--fetchonly"):
303 conf_values["FETCH"]="1"
305 if o in ("-v", "--verbose"):
306 conf_values["VERBOSE"]="1"
308 if o in ("-s", "--snapshot"):
309 if len(sys.argv) < 3:
310 print "!!! catalyst: missing snapshot identifier\n"
315 mycmdline.append("target=snapshot")
316 mycmdline.append("version_stamp="+a)
318 if o in ("-p", "--purge"):
319 conf_values["PURGE"] = "1"
321 if o in ("-P", "--purgeonly"):
322 conf_values["PURGEONLY"] = "1"
324 if o in ("-T", "--purgetmponly"):
325 conf_values["PURGETMPONLY"] = "1"
327 if o in ("-a", "--clear-autoresume"):
328 conf_values["CLEAR_AUTORESUME"] = "1"
331 print "!!! catalyst: please specify one of either -f or -C\n"
335 # import configuration file and import our main module using those settings
336 parse_config(myconfig)
337 sys.path.append(conf_values["sharedir"]+"/modules")
338 from catalyst_support import *
340 # Start checking that digests are valid now that the hash_map was imported
341 # from catalyst_support
342 if "digests" in conf_values:
343 for i in conf_values["digests"].split():
344 if i not in hash_map:
346 print i+" is not a valid digest entry"
347 print "Valid digest entries:"
348 print hash_map.keys()
350 print "Catalyst aborting...."
352 if find_binary(hash_map[i][1]) == None:
355 print "\tThe "+hash_map[i][1]+\
356 " binary was not found. It needs to be in your system path"
358 print "Catalyst aborting...."
360 if "hash_function" in conf_values:
361 if conf_values["hash_function"] not in hash_map:
363 print conf_values["hash_function"]+\
364 " is not a valid hash_function entry"
365 print "Valid hash_function entries:"
366 print hash_map.keys()
368 print "Catalyst aborting...."
370 if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
372 print "hash_function="+conf_values["hash_function"]
373 print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
374 " binary was not found. It needs to be in your system path"
376 print "Catalyst aborting...."
379 # import the rest of the catalyst modules
380 targetmap=import_modules()
385 spec = modules.catalyst.config.SpecParser(myspecfile)
386 addlargs.update(spec.get_values())
390 cmdline = modules.catalyst.config.ConfigParser()
391 cmdline.parse_lines(mycmdline)
392 addlargs.update(cmdline.get_values())
393 except CatalystError:
394 print "!!! catalyst: Could not parse commandline, exiting."
397 if "target" not in addlargs:
398 raise CatalystError, "Required value \"target\" not specified."
400 # everything is setup, so the build is a go
402 build_target(addlargs, targetmap)
404 except CatalystError:
406 print "Catalyst aborting...."
408 except KeyboardInterrupt:
409 print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )"
411 print "Catalyst aborting...."
414 print "Catalyst aborting...."
417 print "Catalyst aborting...."