3 # Maintained in full by:
4 # Andrew Gaffney <agaffney@gentoo.org>
5 # Chris Gianelloni <wolf31o2@wolf31o2.org>
10 # This assumes that our modules are in a sub-dir named "modules" in the
11 # directory that the main catalyst binary is in
12 __selfpath__ = os.path.abspath(os.path.dirname(__file__))
13 sys.path.append(__selfpath__ + "/modules")
16 from catalyst.output import *
17 from catalyst.error import *
18 from catalyst.hash import hash_map
20 __maintainer__="Chris Gianelloni <wolf31o2@wolf31o2.org>"
24 config = catalyst.config.config()
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 " -s --snapshot generate a release snapshot"
38 print " -V --version display version information"
39 print " -v --verbose verbose output"
41 print "Usage examples:"
43 print "Using the commandline option (-C, --cli) to build a Portage snapshot:"
44 print "catalyst -C target=snapshot version_stamp=my_date"
46 print "Using the snapshot option (-s, --snapshot) to build a release snapshot:"
47 print "catalyst -s 20071121"
49 print "Using the specfile option (-f, --file) to build a stage target:"
50 print "catalyst -f stage1-specfile.spec"
53 msg("Catalyst, version " + __version__)
54 msg("Copyright 2003-2008 Gentoo Foundation")
55 msg("Copyright 2008 various authors")
56 msg("Distributed under the GNU General Public License version 2.1")
59 # search a couple of different areas for the main config file
63 "storedir": "/var/tmp/catalyst",
64 "sharedir": "/usr/share/catalyst",
65 "distdir": "/usr/portage/distfiles",
66 "portdir": "/usr/portage",
68 "snapshot_cache": "/var/tmp/catalyst/snapshot_cache",
69 "hash_function": "crc32"
72 # first, try the one passed (presumably from the cmdline)
73 if "config_file" in conf_values:
74 if os.path.exists(conf_values["config_file"]):
75 msg("Using command line specified Catalyst configuration file, " + conf_values["config_file"])
77 die("specified configuration file " + conf_values["config_file"] + " does not exist")
79 # next, try the default location
80 elif os.path.exists("/etc/catalyst/catalyst.conf"):
81 msg("Using default Catalyst configuration file, /etc/catalyst/catalyst.conf")
82 conf_values["config_file"] = "/etc/catalyst/catalyst.conf"
84 # can't find a config file (we are screwed), so bail out
86 die("Could not find a suitable configuration file")
88 # Load the default config values into myconf
89 for x in confdefaults:
90 msg("Setting " + x + " to default value '" + confdefaults[x] + "'")
91 myconf[x] = confdefaults[x]
93 # now, try and parse the config file "config_file"
95 myconfig = catalyst.config.ConfigParser(conf_values["config_file"])
96 myconf.update(myconfig.get_values())
99 die("Unable to parse configuration file, " + conf_values["config_file"])
101 # now, load up the values into conf_values so that we can use them
102 for x in confdefaults.keys():
104 msg("Setting " + x + " to config file value '" + myconf[x] + "'")
105 conf_values[x] = myconf[x]
107 msg("Setting " + x + " to default value '" + confdefaults[x] + "'")
108 conf_values[x] = confdefaults[x]
111 ("autoresume", "AUTORESUME", "Autoresuming support enabled."),
112 ("ccache", "CCACHE", "Compiler cache support enabled."),
113 ("clear-autoresume", "CLEAR_AUTORESUME", "Cleaning autoresume flags support enabled"),
114 # ("compress", "COMPRESS", "Compression enabled."),
115 ("distcc", "DISTCC", "Distcc support enabled."),
116 ("icecream", "ICECREAM", "Icecream compiler cluster support enabled."),
117 ("kerncache", "KERNCACHE", "Kernel cache support enabled."),
118 ("pkgcache", "PKGCACHE", "Package cache support enabled."),
119 ("purge", "PURGE", "Purge support enabled."),
120 ("seedcache", "SEEDCACHE", "Seed cache support enabled."),
121 ("snapcache", "SNAPCACHE", "Snapshot cache support enabled."),
122 # ("tarball", "TARBALL", "Tarball creation enabled.")
125 split_options = conf_values["options"].split()
127 # parse out the rest of the options from the config file
129 if x[0] in split_options:
131 conf_values[x[1]] = "1"
133 if "digests" in myconf:
134 conf_values["digests"] = myconf["digests"]
136 if "contents" in myconf:
137 conf_values["contents"] = myconf["contents"]
139 if "envscript" in myconf:
140 msg("Envscript support enabled.")
141 conf_values["ENVSCRIPT"] = myconf["envscript"]
143 def verify_digest_and_hash_functions():
144 # Start checking that digests are valid now that the hash_map was imported from catalyst_support
145 if "digests" in conf_values:
146 for i in conf_values["digests"].split():
147 if not i in hash_map:
149 msg(i + " is not a valid digest entry")
150 msg("Valid digest entries:")
151 msg("\n".join(hash_map.keys()))
153 msg("Catalyst aborting....")
155 if catalyst.util.find_binary(hash_map[i][1]) == None:
158 msg("\tThe " + hash_map[i][1] + \
159 " binary was not found. It needs to be in your system path")
161 msg("Catalyst aborting....")
164 if "hash_function" in conf_values:
165 if not conf_values["hash_function"] in hash_map:
167 msg(conf_values["hash_function"] + " is not a valid hash_function entry")
168 msg("Valid hash_function entries:")
169 msg("\n".join(hash_map.keys()))
171 msg("Catalyst aborting....")
173 if catalyst.util.find_binary(hash_map[conf_values["hash_function"]][1]) == None:
175 msg("hash_function=" + conf_values["hash_function"])
176 msg("\tThe " + hash_map[conf_values["hash_function"]][1] + \
177 " binary was not found. It needs to be in your system path")
179 msg("Catalyst aborting....")
182 def parse_commandline():
183 # parse out the command line arguments
185 opts,args = getopt.getopt(sys.argv[1:], "apPhvdc:C:f:FVs:", ["purge", "purgeonly", "help", "version", "debug",\
186 "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="])
188 except getopt.GetoptError:
192 # defaults for commandline opts
193 conf_values["command_line"] = []
195 # check preconditions
197 warn("please specify one of either -f or -C\n")
203 if o in ("-h", "--help"):
207 if o in ("-V", "--version"):
211 if o in ("-d", "--debug"):
212 conf_values["DEBUG"]="1"
213 conf_values["VERBOSE"]="1"
215 if o in ("-c", "--config"):
216 conf_values["config_file"] = a
218 if o in ("-C", "--cli"):
220 x = sys.argv.index(o) + 1
221 while x < len(sys.argv):
222 conf_values["command_line"].append(sys.argv[x])
225 if o in ("-f", "--file"):
227 conf_values["spec_file"] = a
229 if o in ("-F", "--fetchonly"):
230 conf_values["FETCH"] = "1"
232 if o in ("-v", "--verbose"):
233 conf_values["VERBOSE"] = "1"
235 if o in ("-s", "--snapshot"):
236 if len(sys.argv) < 3:
237 warn("missing snapshot identifier")
242 conf_values["command_line"].append("target=snapshot")
243 conf_values["command_line"].append("version_stamp="+a)
245 if o in ("-p", "--purge"):
246 conf_values["PURGE"] = "1"
248 if o in ("-P", "--purgeonly"):
249 conf_values["PURGEONLY"] = "1"
251 if o in ("-a", "--clear-autoresume"):
252 conf_values["CLEAR_AUTORESUME"] = "1"
255 warn("please specify one of either -f or -C")
259 if __name__ == "__main__":
264 # catalyst cannot be run as a normal user due to chroots, mounts, etc
265 die("This script requires root privileges to operate", 2)
271 verify_digest_and_hash_functions()
273 targetmap = catalyst.target.build_target_map()
274 spec = catalyst.config.Spec()
276 if "spec_file" in conf_values:
277 specparser = catalyst.config.SpecParser(conf_values["spec_file"])
278 spec_values = specparser.get_values()
279 spec.parse_values(spec_values)
281 if "command_line" in conf_values:
283 cmdline = catalyst.config.ConfigParser()
284 cmdline.parse_lines(conf_values["command_line"])
285 cmdline_values = cmdline.get_values()
286 spec.parse_values(cmdline_values)
287 except CatalystError:
288 die("Could not parse commandline, exiting.")
290 config.set_spec(spec)
291 config.set_conf(conf_values)
292 config.set_targetmap(targetmap)
294 # everything is setup, so the build is a go
296 catalyst.target.build_targets()
298 except CatalystError:
300 msg("Catalyst aborting....")
303 except KeyboardInterrupt:
305 msg("Catalyst build aborted due to user interrupt ( Ctrl-C )")
307 msg("Catalyst aborting....")
311 msg("Catalyst aborting....")
315 msg("Catalyst aborting....")
320 # print "\nproblem with command line or spec file ( Key Error )"
321 # print "Key: "+str(sys.exc_value)+" was not found"
322 # print "Catalyst aborting...."
324 #except UnboundLocalError:
326 # print "UnboundLocalError: "+str(sys.exc_value)+" was not found"
329 # print "Catalyst aborting...."