2 # Copyright 1999-2004 Gentoo Technologies, Inc.
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.38 2004/06/18 18:06:21 zhen Exp $
6 import os,sys,imp,string
9 print "Usage: catalyst [-f file] [variable=value ...]"
10 print " -h --help print this usage and exit"
11 print " -v --version display version information"
12 print " -f --file read specified file for build instructions"
13 print " variable=value specify a variable/value pair"
16 print "Gentoo catalyst, version "+version
17 print "Copyright 2003-2004 Gentoo Technologies, Inc."
18 print "Distributed under the GNU General Public License version 2"
22 if len(sys.argv)==1 or sys.argv[1] in ["-h","--help"]:
25 elif sys.argv[1] in ["-v","--version"]:
29 #non-root callers can't go any further than here.
30 print "catalyst: This script requires root privileges to operate."
35 myconffile="/etc/catalyst/catalyst.conf"
36 if os.environ.has_key("clst_conf"):
37 if not os.path.exists(os.environ["clst_conf"]):
38 print "catalyst: Unable to find config file specified in env var 'clst_conf'"
40 myconffile=os.environ["clst_conf"]
42 if os.path.exists(myconffile):
44 execfile(myconffile,myconf,myconf)
46 print "catalyst: Unable to parse "+myconffile+" config file (syntax error)"
49 confdefaults={ "storedir":"/var/tmp/catalyst","sharedir":"/usr/share/catalyst","distdir":"/usr/portage/distfiles",
50 "portdir":"/usr/portage","options":""}
52 for x in confdefaults.keys():
54 print "Setting",x,"to config file value \""+myconf[x]+"\""
57 print "Setting",x,"to default value \""+confdefaults[x]+"\""
58 myspec[x]=confdefaults[x]
60 #This allows plugins (and this code) to import modules in the /modules dir
61 sys.path.append(myspec["sharedir"]+"/modules")
64 from catalyst_support import *
65 for x in required_build_targets:
67 fh=open(myspec["sharedir"]+"/modules/"+x+".py")
68 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
71 msg("Can't find "+x+".py plugin in "+myspec.settings["sharedir"]+"/modules/")
73 for x in valid_build_targets:
75 fh=open(myspec["sharedir"]+"/modules/"+x+".py")
76 module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
77 module.register(targetmap)
80 msg("Can't find "+x+".py plugin in "+myspec.settings["sharedir"]+"/modules/")
83 print "catalyst: python modules not found in "+myspec["sharedir"]+"/modules; exiting."
86 if "ccache" in string.split(myspec["options"]):
87 print "Compiler cache support enabled."
90 if "pkgcache" in string.split(myspec["options"]):
91 print "Package cache support enabled."
92 myspec["PKGCACHE"]="1"
94 if "distcc" in string.split(myspec["options"]):
95 print "Distcc support enabled."
98 if "autoresume" in string.split(myspec["options"]):
99 print "Autoresuming support enabled."
100 myspec["AUTORESUME"]="1"
102 if myconf.has_key("envscript"):
103 print "Envscript support enabled."
104 myspec["ENVSCRIPT"]=myconf["envscript"]
106 if sys.argv[1] in ["-f", "--file" ]:
108 addlargs=read_spec(sys.argv[2])
111 unparsedargs=sys.argv[3:]
114 unparsedargs=sys.argv[1:]
116 arg_parse(myspec,addlargs,unparsedargs)
117 if not targetmap.has_key(myspec["target"]):
118 raise CatalystError,"Target \""+myspec["target"]+"\" not available."
119 mytarget=targetmap[myspec["target"]](myspec,addlargs)
122 except CatalystError: