fix for module import path
[catalyst.git] / catalyst
1 #!/usr/bin/python
2
3 import os,sys,imp,string
4
5 def usage():
6         print "usage: meep!"
7
8 if len(sys.argv)==1 or sys.argv[1] in ["-h","--help"]:
9         usage()
10         sys.exit(1)
11
12 import targets
13 targetmap={}
14 targets.register(targetmap)
15
16 if os.getuid()!=0:
17         #non-root callers can't go any further than here. 
18         die("This script requires root privileges to operate.") 
19
20 myspec={}
21 myconf={}
22 if os.path.exists("/etc/catalyst.conf"):
23         try:
24                 execfile("/etc/catalyst.conf",myconf,myconf)
25         except:
26                 print "catalyst: Unable to /etc/catalyst.conf config file (syntax error)"
27                 sys.exit(1)
28
29 confdefaults={ "storedir":"/var/tmp/catalyst","sharedir":"/usr/share/catalyst","distdir":"/usr/portage/distfiles",
30 "portdir":"/usr/portage","options":"ccache"}
31
32 for x in confdefaults.keys():
33         if myconf.has_key(x):
34                 print "Setting",x,"to config file value \""+myconf[x]+"\""
35                 myspec[x]=myconf[x]
36         else:
37                 print "Setting",x,"to default value \""+confdefaults[x]+"\""
38                 myspec[x]=confdefaults[x]
39
40 #This allows plugins (and this code) to import modules in the /modules dir
41 sys.path.append(myspec["sharedir"]+"/modules")
42 try:
43         from catalyst_support import *
44 except ImportError:
45         print "catalyst: catalyst_support module not found in "+myspec["sharedir"]+"/modules; exiting."
46         sys.exit(1)
47
48 if "ccache" in string.split(myspec["options"]):
49         print "Compiler cache support enabled."
50         myspec["CCACHE"]="1"
51 if "pkgcache" in string.split(myspec["options"]):
52         print "Package cache support enabled."
53         myspec["PKGCACHE"]="1"
54 #determine target, call target constructor and hand it the rest of the arguments
55
56 try:
57         addlargs={}
58         arg_parse(myspec,addlargs)
59         if not targetmap.has_key(myspec["target"]):
60                 raise CatalystError,"Target \""+myspec["target"]+"\" not available."
61         mytarget=targetmap[myspec["target"]](myspec,addlargs)
62         
63         mytarget.run()
64 except CatalystError:
65         sys.exit(1)
66 # Examples:
67 # ./catalyst subarch=pentium4 version_stamp=20031016 target=stage3 rel_type=default rel_version=1.4 snapshot=20031016 source_subpath=default-x86-1.4/stage2-pentium4-20031016
68 # ./catalyst target=snapshot version_stamp=20031028