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