3 # Maintained in full by:
4 # Andrew Gaffney <agaffney@gentoo.org>
5 # Chris Gianelloni <wolf31o2@gentoo.org>
9 # This assumes that our modules are in a sub-dir named "modules" in the
10 # directory that the main catalyst binary is in
11 __selfpath__ = os.path.abspath(os.path.dirname(__file__))
12 sys.path.append(__selfpath__ + "/modules")
14 import catalyst.config
16 import catalyst.target
17 from catalyst.support import *
19 __maintainer__="Chris Gianelloni <wolf31o2@gentoo.org>"
25 print "Usage catalyst [options] [-C variable=value...] [ -s identifier]"
26 print " -a --clear-autoresume clear autoresume flags"
27 print " -c --config use specified configuration file"
28 print " -C --cli catalyst commandline (MUST BE LAST OPTION)"
29 print " -d --debug enable debugging"
30 print " -f --file read specfile"
31 print " -F --fetchonly fetch files only"
32 print " -h --help print this help message"
33 print " -p --purge clear tmp dirs,package cache and autoresume flags"
34 print " -P --purgeonly clear tmp dirs,package cache and autoresume flags and exit"
35 print " -s --snapshot generate a release snapshot"
36 print " -V --version display version information"
37 print " -v --verbose verbose output"
39 print "Usage examples:"
41 print "Using the commandline option (-C, --cli) to build a Portage snapshot:"
42 print "catalyst -C target=snapshot version_stamp=my_date"
44 print "Using the snapshot option (-s, --snapshot) to build a release snapshot:"
45 print "catalyst -s 20071121"
47 print "Using the specfile option (-f, --file) to build a stage target:"
48 print "catalyst -f stage1-specfile.spec"
51 print "Catalyst, version "+__version__
52 print "Copyright 2003-2008 Gentoo Foundation"
53 print "Copyright 2008 various authors"
54 print "Distributed under the GNU General Public License version 2.1\n"
56 def parse_config(myconfig):
57 # search a couple of different areas for the main config file
61 confdefaults={ "storedir":"/var/tmp/catalyst",\
62 "sharedir":"/usr/share/catalyst","distdir":"/usr/portage/distfiles",\
63 "portdir":"/usr/portage","options":"",\
64 "snapshot_cache":"/var/tmp/catalyst/snapshot_cache",\
65 "hash_function":"crc32"}
67 # first, try the one passed (presumably from the cmdline)
69 if os.path.exists(myconfig):
70 print "Using command line specified Catalyst configuration file, "+myconfig
74 print "!!! catalyst: Could not use specified configuration file "+\
78 # next, try the default location
79 elif os.path.exists("/etc/catalyst/catalyst.conf"):
80 print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf"
81 config_file="/etc/catalyst/catalyst.conf"
83 # can't find a config file (we are screwed), so bail out
85 print "!!! catalyst: Could not find a suitable configuration file"
88 # now, try and parse the config file "config_file"
90 # execfile(config_file, myconf, myconf)
91 myconfig = catalyst.config.ConfigParser(config_file)
92 myconf.update(myconfig.get_values())
95 print "!!! catalyst: Unable to parse configuration file, "+myconfig
98 # now, load up the values into conf_values so that we can use them
99 for x in confdefaults.keys():
101 print "Setting",x,"to config file value \""+myconf[x]+"\""
102 conf_values[x]=myconf[x]
104 print "Setting",x,"to default value \""+confdefaults[x]+"\""
105 conf_values[x]=confdefaults[x]
108 ("autoresume", "AUTORESUME", "Autoresuming support enabled."),
109 ("ccache", "CCACHE", "Compiler cache support enabled."),
110 ("clear-autoresume", "CLEAR_AUTORESUME", "Cleaning autoresume flags support enabled"),
111 # ("compress", "COMPRESS", "Compression enabled."),
112 ("distcc", "DISTCC", "Distcc support enabled."),
113 ("icecream", "ICECREAM", "Icecream compiler cluster support enabled."),
114 ("kerncache", "KERNCACHE", "Kernel cache support enabled."),
115 ("pkgcache", "PKGCACHE", "Package cache support enabled."),
116 ("purge", "PURGE", "Purge support enabled."),
117 ("seedcache", "SEEDCACHE", "Seed cache support enabled."),
118 ("snapcache", "SNAPCACHE", "Snapshot cache support enabled."),
119 ("metadata_overlay", "METADATA_OVERLAY", "Use of metadata_overlay module for portage enabled."),
120 # ("tarball", "TARBALL", "Tarball creation enabled.")
123 split_options = conf_values["options"].split()
125 # parse out the rest of the options from the config file
127 if x[0] in split_options:
129 conf_values[x[1]] = "1"
131 if "digests" in myconf:
132 conf_values["digests"]=myconf["digests"]
133 if "contents" in myconf:
134 conf_values["contents"]=myconf["contents"]
136 if "envscript" in myconf:
137 print "Envscript support enabled."
138 conf_values["ENVSCRIPT"]=myconf["envscript"]
140 def build_target(addlargs, targetmap):
142 if not addlargs["target"] in targetmap:
143 raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
145 mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
150 catalyst.util.print_traceback()
151 print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
155 def verify_digest_and_hash_functions():
156 # Start checking that digests are valid now that the hash_map was imported from catalyst_support
157 if "digests" in conf_values:
158 for i in conf_values["digests"].split():
159 if not i in hash_map:
161 print i+" is not a valid digest entry"
162 print "Valid digest entries:"
163 print hash_map.keys()
165 print "Catalyst aborting...."
167 if find_binary(hash_map[i][1]) == None:
170 print "\tThe "+hash_map[i][1]+\
171 " binary was not found. It needs to be in your system path"
173 print "Catalyst aborting...."
176 if "hash_function" in conf_values:
177 if not conf_values["hash_function"] in hash_map:
179 print conf_values["hash_function"]+" is not a valid hash_function entry"
180 print "Valid hash_function entries:"
181 print hash_map.keys()
183 print "Catalyst aborting...."
185 if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
187 print "hash_function="+conf_values["hash_function"]
188 print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
189 " binary was not found. It needs to be in your system path"
191 print "Catalyst aborting...."
194 if __name__ == "__main__":
199 # catalyst cannot be run as a normal user due to chroots, mounts, etc
200 print "!!! catalyst: This script requires root privileges to operate"
203 # parse out the command line arguments
205 opts,args = getopt.getopt(sys.argv[1:], "apPhvdc:C:f:FVs:", ["purge", "purgeonly", "help", "version", "debug",\
206 "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
208 except getopt.GetoptError:
212 # defaults for commandline opts
221 # check preconditions
223 print "!!! catalyst: please specify one of either -f or -C\n"
229 if o in ("-h", "--help"):
233 if o in ("-V", "--version"):
234 print "Catalyst version "+__version__
237 if o in ("-d", "--debug"):
238 conf_values["DEBUG"]="1"
239 conf_values["VERBOSE"]="1"
241 if o in ("-c", "--config"):
244 if o in ("-C", "--cli"):
246 x=sys.argv.index(o)+1
247 while x < len(sys.argv):
248 mycmdline.append(sys.argv[x])
251 if o in ("-f", "--file"):
255 if o in ("-F", "--fetchonly"):
256 conf_values["FETCH"]="1"
258 if o in ("-v", "--verbose"):
259 conf_values["VERBOSE"]="1"
261 if o in ("-s", "--snapshot"):
262 if len(sys.argv) < 3:
263 print "!!! catalyst: missing snapshot identifier\n"
268 mycmdline.append("target=snapshot")
269 mycmdline.append("version_stamp="+a)
271 if o in ("-p", "--purge"):
272 conf_values["PURGE"] = "1"
274 if o in ("-P", "--purgeonly"):
275 conf_values["PURGEONLY"] = "1"
277 if o in ("-a", "--clear-autoresume"):
278 conf_values["CLEAR_AUTORESUME"] = "1"
281 print "!!! catalyst: please specify one of either -f or -C\n"
285 parse_config(myconfig)
287 verify_digest_and_hash_functions()
289 targetmap = catalyst.target.build_target_map()
294 spec = catalyst.config.SpecParser(myspecfile)
295 addlargs.update(spec.get_values())
299 cmdline = catalyst.config.ConfigParser()
300 cmdline.parse_lines(mycmdline)
301 addlargs.update(cmdline.get_values())
302 except CatalystError:
303 print "!!! catalyst: Could not parse commandline, exiting."
306 if not "target" in addlargs:
307 raise CatalystError, "Required value \"target\" not specified."
309 # everything is setup, so the build is a go
311 build_target(addlargs, targetmap)
313 except CatalystError:
315 print "Catalyst aborting...."
318 except KeyboardInterrupt:
319 print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )"
321 print "Catalyst aborting...."
325 print "Catalyst aborting...."
329 print "Catalyst aborting...."
334 # print "\nproblem with command line or spec file ( Key Error )"
335 # print "Key: "+str(sys.exc_value)+" was not found"
336 # print "Catalyst aborting...."
338 #except UnboundLocalError:
340 # print "UnboundLocalError: "+str(sys.exc_value)+" was not found"
343 # print "Catalyst aborting...."