mips.py: remove unnecessary generic_multilib class
[catalyst.git] / modules / livecd_stage2_target.py
1
2 """
3 Builder class for a LiveCD stage2 build.
4 """
5
6 import os,string,types,stat,shutil
7 from catalyst_support import *
8 from generic_stage_target import *
9
10 class livecd_stage2_target(generic_stage_target):
11         def __init__(self,spec,addlargs):
12                 self.required_values=["boot/kernel"]
13                 
14                 self.valid_values=[]
15                 
16                 self.valid_values.extend(self.required_values)
17                 self.valid_values.extend(["livecd/cdtar","livecd/empty","livecd/rm",\
18                         "livecd/unmerge","livecd/iso","livecd/gk_mainargs","livecd/type",\
19                         "livecd/readme","livecd/motd","livecd/overlay",\
20                         "livecd/modblacklist","livecd/splash_theme","livecd/rcadd",\
21                         "livecd/rcdel","livecd/fsscript","livecd/xinitrc",\
22                         "livecd/root_overlay","livecd/users","portage_overlay",\
23                         "livecd/fstype","livecd/fsops","livecd/linuxrc","livecd/bootargs",\
24                         "gamecd/conf","livecd/xdm","livecd/xsession","livecd/volid"])
25                 
26                 generic_stage_target.__init__(self,spec,addlargs)
27                 if not self.settings.has_key("livecd/type"):
28                         self.settings["livecd/type"] = "generic-livecd"
29
30                 file_locate(self.settings, ["cdtar","controller_file"])
31         
32         def set_source_path(self):
33                 self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2")
34                 if os.path.isfile(self.settings["source_path"]):
35                         self.settings["source_path_hash"]=generate_hash(self.settings["source_path"])
36                 else:
37                         self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/")
38                 if not os.path.exists(self.settings["source_path"]):
39                         raise CatalystError,"Source Path: "+self.settings["source_path"]+" does not exist."
40         
41         def set_spec_prefix(self):
42             self.settings["spec_prefix"]="livecd"
43
44         def set_target_path(self):
45                 self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
46                 if self.settings.has_key("AUTORESUME") \
47                         and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
48                                 print "Resume point detected, skipping target path setup operation..."
49                 else:
50                         # first clean up any existing target stuff
51                         if os.path.isdir(self.settings["target_path"]):
52                                 cmd("rm -rf "+self.settings["target_path"],
53                                 "Could not remove existing directory: "+self.settings["target_path"],env=self.env)
54                                 touch(self.settings["autoresume_path"]+"setup_target_path")
55                         if not os.path.exists(self.settings["target_path"]):
56                                 os.makedirs(self.settings["target_path"])
57
58         def run_local(self):
59                 # what modules do we want to blacklist?
60                 if self.settings.has_key("livecd/modblacklist"):
61                         try:
62                                 myf=open(self.settings["chroot_path"]+"/etc/modprobe.d/blacklist.conf","a")
63                         except:
64                                 self.unbind()
65                                 raise CatalystError,"Couldn't open "+self.settings["chroot_path"]+"/etc/modprobe.d/blacklist.conf."
66                         
67                         myf.write("\n#Added by Catalyst:")
68                         for x in self.settings["livecd/modblacklist"]:
69                                 myf.write("\nblacklist "+x)
70                         myf.close()
71         
72         def unpack(self):
73                 unpack=True
74                 display_msg=None
75
76                 clst_unpack_hash=read_from_clst(self.settings["autoresume_path"]+"unpack")
77
78                 if os.path.isdir(self.settings["source_path"]):
79                         unpack_cmd="rsync -a --delete "+self.settings["source_path"]+" "+self.settings["chroot_path"]
80                         display_msg="\nStarting rsync from "+self.settings["source_path"]+"\nto "+\
81                                 self.settings["chroot_path"]+" (This may take some time) ...\n"
82                         error_msg="Rsync of "+self.settings["source_path"]+" to "+self.settings["chroot_path"]+" failed."
83                         invalid_snapshot=False
84
85                 if self.settings.has_key("AUTORESUME"):
86                         if os.path.isdir(self.settings["source_path"]) and \
87                                 os.path.exists(self.settings["autoresume_path"]+"unpack"):
88                                 print "Resume point detected, skipping unpack operation..."
89                                 unpack=False
90                         elif self.settings.has_key("source_path_hash"):
91                                 if self.settings["source_path_hash"] != clst_unpack_hash:
92                                         invalid_snapshot=True
93
94                 if unpack:
95                         self.mount_safety_check()
96                         if invalid_snapshot:
97                                 print "No Valid Resume point detected, cleaning up  ..."
98                                 #os.remove(self.settings["autoresume_path"]+"dir_setup")
99                                 self.clear_autoresume()
100                                 self.clear_chroot()
101                                 #self.dir_setup()
102
103                         if not os.path.exists(self.settings["chroot_path"]):
104                                 os.makedirs(self.settings["chroot_path"])
105
106                         if not os.path.exists(self.settings["chroot_path"]+"/tmp"):
107                                 os.makedirs(self.settings["chroot_path"]+"/tmp",1777)
108
109                         if self.settings.has_key("PKGCACHE"):
110                                 if not os.path.exists(self.settings["pkgcache_path"]):
111                                         os.makedirs(self.settings["pkgcache_path"],0755)
112
113                         if not display_msg:
114                                 raise CatalystError,"Could not find appropriate source. Please check the 'source_subpath' setting in the spec file."
115
116                         print display_msg
117                         cmd(unpack_cmd,error_msg,env=self.env)
118
119                         if self.settings.has_key("source_path_hash"):
120                                 myf=open(self.settings["autoresume_path"]+"unpack","w")
121                                 myf.write(self.settings["source_path_hash"])
122                                 myf.close()
123                         else:
124                                 touch(self.settings["autoresume_path"]+"unpack")
125
126         def set_action_sequence(self):
127                 self.settings["action_sequence"]=["unpack","unpack_snapshot",\
128                                 "config_profile_link","setup_confdir","portage_overlay",\
129                                 "bind","chroot_setup","setup_environment","run_local",\
130                                 "build_kernel"]
131                 if not self.settings.has_key("FETCH"):
132                         self.settings["action_sequence"] += ["bootloader","preclean",\
133                                 "livecd_update","root_overlay","fsscript","rcupdate","unmerge",\
134                                 "unbind","remove","empty","target_setup",\
135                                 "setup_overlay","create_iso"]
136                 self.settings["action_sequence"].append("clear_autoresume")
137
138 def register(foo):
139         foo.update({"livecd-stage2":livecd_stage2_target})
140         return foo