Add catalyst.spawn import where needed and move more spawn-related stuff from catalys...
[catalyst.git] / modules / catalyst / target / netboot.py
1
2 """
3 Builder class for a netboot build.
4 """
5
6 import os,string,types
7 from catalyst.support import *
8 from generic_stage import *
9 import catalyst.util
10 from catalyst.error import *
11 from catalyst.spawn import *
12
13 class netboot_target(generic_stage_target):
14         def __init__(self,spec,addlargs):
15                 self.valid_values = [
16                         "netboot/kernel/sources",
17                         "netboot/kernel/config",
18                         "netboot/kernel/prebuilt",
19
20                         "netboot/busybox_config",
21
22                         "netboot/extra_files",
23                         "netboot/packages"
24                 ]
25                 self.required_values=[]
26
27                 try:
28                         if "netboot/packages" in addlargs:
29                                 if type(addlargs["netboot/packages"]) == types.StringType:
30                                         loopy=[addlargs["netboot/packages"]]
31                                 else:
32                                         loopy=addlargs["netboot/packages"]
33
34                 #       for x in loopy:
35                 #               self.required_values.append("netboot/packages/"+x+"/files")
36                 except:
37                         raise CatalystError,"configuration error in netboot/packages."
38
39
40
41
42                 generic_stage_target.__init__(self,spec,addlargs)
43                 self.set_build_kernel_vars(addlargs)
44                 if "netboot/busybox_config" in addlargs:
45                         file_locate(self.settings, ["netboot/busybox_config"])
46
47                 # Custom Kernel Tarball --- use that instead ...
48
49                 # unless the user wants specific CFLAGS/CXXFLAGS, let's use -Os
50
51                 for envvar in "CFLAGS", "CXXFLAGS":
52                         if not envvar in os.environ and not envvar in addlargs:
53                                 self.settings[envvar] = "-Os -pipe"
54
55
56         def set_root_path(self):
57                 # ROOT= variable for emerges
58                 self.settings["root_path"]=catalyst.util.normpath("/tmp/image")
59                 print "netboot root path is "+self.settings["root_path"]
60
61 #       def build_packages(self):
62 #               # build packages
63 #               if "netboot/packages" in self.settings:
64 #                       mypack = catalyst.util.list_bashify(self.settings["netboot/packages"])
65 #               try:
66 #                       cmd("/bin/bash "+self.settings["controller_file"]+" packages "+mypack,env=self.env)
67 #               except CatalystError:
68 #                       self.unbind()
69 #                       raise CatalystError,"netboot build aborting due to error."
70
71         def build_busybox(self):
72                 # build busybox
73                 if "netboot/busybox_config" in self.settings:
74                         mycmd = self.settings["netboot/busybox_config"]
75                 else:
76                         mycmd = ""
77                 try:
78                         cmd("/bin/bash "+self.settings["controller_file"]+" busybox "+ mycmd,env=self.env)
79                 except CatalystError:
80                         self.unbind()
81                         raise CatalystError,"netboot build aborting due to error."
82
83
84         def copy_files_to_image(self):
85                 # create image
86                 myfiles=[]
87                 if "netboot/packages" in self.settings:
88                         if type(self.settings["netboot/packages"]) == types.StringType:
89                                 loopy=[self.settings["netboot/packages"]]
90                         else:
91                                 loopy=self.settings["netboot/packages"]
92
93                 for x in loopy:
94                         if "netboot/packages/"+x+"/files" in self.settings:
95                             if type(self.settings["netboot/packages/"+x+"/files"]) == types.ListType:
96                                     myfiles.extend(self.settings["netboot/packages/"+x+"/files"])
97                             else:
98                                     myfiles.append(self.settings["netboot/packages/"+x+"/files"])
99
100                 if "netboot/extra_files" in self.settings:
101                         if type(self.settings["netboot/extra_files"]) == types.ListType:
102                                 myfiles.extend(self.settings["netboot/extra_files"])
103                         else:
104                                 myfiles.append(self.settings["netboot/extra_files"])
105
106                 try:
107                         cmd("/bin/bash "+self.settings["controller_file"]+\
108                                 " image " + catalyst.util.list_bashify(myfiles),env=self.env)
109                 except CatalystError:
110                         self.unbind()
111                         raise CatalystError,"netboot build aborting due to error."
112
113
114         def create_netboot_files(self):
115                 # finish it all up
116                 try:
117                         cmd("/bin/bash "+self.settings["controller_file"]+" finish",env=self.env)
118                 except CatalystError:
119                         self.unbind()
120                         raise CatalystError,"netboot build aborting due to error."
121
122                 # end
123                 print "netboot: build finished !"
124
125
126         def set_action_sequence(self):
127             self.settings["action_sequence"]=["unpack","unpack_snapshot",
128                                         "config_profile_link","setup_confdir","bind","chroot_setup",\
129                                                 "setup_environment","build_packages","build_busybox",\
130                                                 "build_kernel","copy_files_to_image",\
131                                                 "clean","create_netboot_files","unbind","clear_autoresume"]
132
133 __target_map = {"netboot":netboot_target}