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