Gentoo Archives: gentoo-catalyst

From: Brian Dolbec <dolsen@g.o>
To: gentoo-catalyst@l.g.o
Cc: Brian Dolbec <dolsen@g.o>
Subject: [gentoo-catalyst] [PATCH 3/4] rename the modules subpkg to targets, it better reflects what it contains
Date: Sat, 14 Dec 2013 03:21:04
Message-Id: 1386991211-9296-4-git-send-email-dolsen@gentoo.org
In Reply to: [gentoo-catalyst] rewrite-on-master patches, round-2 by Brian Dolbec
1 ---
2 catalyst/main.py | 6 +-
3 catalyst/modules/__init__.py | 1 -
4 catalyst/modules/embedded_target.py | 51 -
5 catalyst/modules/generic_stage_target.py | 1691 ------------------------------
6 catalyst/modules/generic_target.py | 11 -
7 catalyst/modules/grp_target.py | 118 ---
8 catalyst/modules/livecd_stage1_target.py | 75 --
9 catalyst/modules/livecd_stage2_target.py | 146 ---
10 catalyst/modules/netboot2_target.py | 166 ---
11 catalyst/modules/netboot_target.py | 128 ---
12 catalyst/modules/snapshot_target.py | 91 --
13 catalyst/modules/stage1_target.py | 96 --
14 catalyst/modules/stage2_target.py | 62 --
15 catalyst/modules/stage3_target.py | 31 -
16 catalyst/modules/stage4_target.py | 43 -
17 catalyst/modules/tinderbox_target.py | 44 -
18 catalyst/targets/__init__.py | 1 +
19 catalyst/targets/embedded_target.py | 51 +
20 catalyst/targets/generic_stage_target.py | 1691 ++++++++++++++++++++++++++++++
21 catalyst/targets/generic_target.py | 11 +
22 catalyst/targets/grp_target.py | 118 +++
23 catalyst/targets/livecd_stage1_target.py | 75 ++
24 catalyst/targets/livecd_stage2_target.py | 146 +++
25 catalyst/targets/netboot2_target.py | 166 +++
26 catalyst/targets/netboot_target.py | 128 +++
27 catalyst/targets/snapshot_target.py | 91 ++
28 catalyst/targets/stage1_target.py | 96 ++
29 catalyst/targets/stage2_target.py | 62 ++
30 catalyst/targets/stage3_target.py | 31 +
31 catalyst/targets/stage4_target.py | 43 +
32 catalyst/targets/tinderbox_target.py | 44 +
33 31 files changed, 2757 insertions(+), 2757 deletions(-)
34 delete mode 100644 catalyst/modules/__init__.py
35 delete mode 100644 catalyst/modules/embedded_target.py
36 delete mode 100644 catalyst/modules/generic_stage_target.py
37 delete mode 100644 catalyst/modules/generic_target.py
38 delete mode 100644 catalyst/modules/grp_target.py
39 delete mode 100644 catalyst/modules/livecd_stage1_target.py
40 delete mode 100644 catalyst/modules/livecd_stage2_target.py
41 delete mode 100644 catalyst/modules/netboot2_target.py
42 delete mode 100644 catalyst/modules/netboot_target.py
43 delete mode 100644 catalyst/modules/snapshot_target.py
44 delete mode 100644 catalyst/modules/stage1_target.py
45 delete mode 100644 catalyst/modules/stage2_target.py
46 delete mode 100644 catalyst/modules/stage3_target.py
47 delete mode 100644 catalyst/modules/stage4_target.py
48 delete mode 100644 catalyst/modules/tinderbox_target.py
49 create mode 100644 catalyst/targets/__init__.py
50 create mode 100644 catalyst/targets/embedded_target.py
51 create mode 100644 catalyst/targets/generic_stage_target.py
52 create mode 100644 catalyst/targets/generic_target.py
53 create mode 100644 catalyst/targets/grp_target.py
54 create mode 100644 catalyst/targets/livecd_stage1_target.py
55 create mode 100644 catalyst/targets/livecd_stage2_target.py
56 create mode 100644 catalyst/targets/netboot2_target.py
57 create mode 100644 catalyst/targets/netboot_target.py
58 create mode 100644 catalyst/targets/snapshot_target.py
59 create mode 100644 catalyst/targets/stage1_target.py
60 create mode 100644 catalyst/targets/stage2_target.py
61 create mode 100644 catalyst/targets/stage3_target.py
62 create mode 100644 catalyst/targets/stage4_target.py
63 create mode 100644 catalyst/targets/tinderbox_target.py
64
65 diff --git a/catalyst/main.py b/catalyst/main.py
66 index 90ee722..28afc59 100644
67 --- a/catalyst/main.py
68 +++ b/catalyst/main.py
69 @@ -201,11 +201,11 @@ def import_modules():
70 targetmap={}
71
72 try:
73 - module_dir = __selfpath__ + "/modules/"
74 + module_dir = __selfpath__ + "/targets/"
75 for x in required_build_targets:
76 try:
77 fh=open(module_dir + x + ".py")
78 - module=imp.load_module(x, fh,"modules/" + x + ".py",
79 + module=imp.load_module(x, fh,"targets/" + x + ".py",
80 (".py", "r", imp.PY_SOURCE))
81 fh.close()
82
83 @@ -215,7 +215,7 @@ def import_modules():
84 for x in valid_build_targets:
85 try:
86 fh=open(module_dir + x + ".py")
87 - module=imp.load_module(x, fh, "modules/" + x + ".py",
88 + module=imp.load_module(x, fh, "targets/" + x + ".py",
89 (".py", "r", imp.PY_SOURCE))
90 module.register(targetmap)
91 fh.close()
92 diff --git a/catalyst/modules/__init__.py b/catalyst/modules/__init__.py
93 deleted file mode 100644
94 index 8b13789..0000000
95 --- a/catalyst/modules/__init__.py
96 +++ /dev/null
97 @@ -1 +0,0 @@
98 -
99 diff --git a/catalyst/modules/embedded_target.py b/catalyst/modules/embedded_target.py
100 deleted file mode 100644
101 index 7cee7a6..0000000
102 --- a/catalyst/modules/embedded_target.py
103 +++ /dev/null
104 @@ -1,51 +0,0 @@
105 -"""
106 -Enbedded target, similar to the stage2 target, builds upon a stage2 tarball.
107 -
108 -A stage2 tarball is unpacked, but instead
109 -of building a stage3, it emerges @system into another directory
110 -inside the stage2 system. This way, we do not have to emerge GCC/portage
111 -into the staged system.
112 -It may sound complicated but basically it runs
113 -ROOT=/tmp/submerge emerge --something foo bar .
114 -"""
115 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
116 -
117 -import os,string,imp,types,shutil
118 -from catalyst.support import *
119 -from generic_stage_target import *
120 -from stat import *
121 -
122 -class embedded_target(generic_stage_target):
123 - """
124 - Builder class for embedded target
125 - """
126 - def __init__(self,spec,addlargs):
127 - self.required_values=[]
128 - self.valid_values=[]
129 - self.valid_values.extend(["embedded/empty","embedded/rm","embedded/unmerge","embedded/fs-prepare","embedded/fs-finish","embedded/mergeroot","embedded/packages","embedded/fs-type","embedded/runscript","boot/kernel","embedded/linuxrc"])
130 - self.valid_values.extend(["embedded/use"])
131 - if "embedded/fs-type" in addlargs:
132 - self.valid_values.append("embedded/fs-ops")
133 -
134 - generic_stage_target.__init__(self,spec,addlargs)
135 - self.set_build_kernel_vars(addlargs)
136 -
137 - def set_action_sequence(self):
138 - self.settings["action_sequence"]=["dir_setup","unpack","unpack_snapshot",\
139 - "config_profile_link","setup_confdir",\
140 - "portage_overlay","bind","chroot_setup",\
141 - "setup_environment","build_kernel","build_packages",\
142 - "bootloader","root_overlay","fsscript","unmerge",\
143 - "unbind","remove","empty","clean","capture","clear_autoresume"]
144 -
145 - def set_stage_path(self):
146 - self.settings["stage_path"]=normpath(self.settings["chroot_path"]+"/tmp/mergeroot")
147 - print "embedded stage path is "+self.settings["stage_path"]
148 -
149 - def set_root_path(self):
150 - self.settings["root_path"]=normpath("/tmp/mergeroot")
151 - print "embedded root path is "+self.settings["root_path"]
152 -
153 -def register(foo):
154 - foo.update({"embedded":embedded_target})
155 - return foo
156 diff --git a/catalyst/modules/generic_stage_target.py b/catalyst/modules/generic_stage_target.py
157 deleted file mode 100644
158 index 5200d8a..0000000
159 --- a/catalyst/modules/generic_stage_target.py
160 +++ /dev/null
161 @@ -1,1691 +0,0 @@
162 -import os,string,imp,types,shutil
163 -from catalyst.support import *
164 -from generic_target import *
165 -from stat import *
166 -from catalyst.lock import LockDir
167 -
168 -class generic_stage_target(generic_target):
169 - """
170 - This class does all of the chroot setup, copying of files, etc. It is
171 - the driver class for pretty much everything that Catalyst does.
172 - """
173 - def __init__(self,myspec,addlargs):
174 - self.required_values.extend(["version_stamp","target","subarch",\
175 - "rel_type","profile","snapshot","source_subpath"])
176 -
177 - self.valid_values.extend(["version_stamp","target","subarch",\
178 - "rel_type","profile","snapshot","source_subpath","portage_confdir",\
179 - "cflags","cxxflags","ldflags","cbuild","hostuse","portage_overlay",\
180 - "distcc_hosts","makeopts","pkgcache_path","kerncache_path"])
181 -
182 - self.set_valid_build_kernel_vars(addlargs)
183 - generic_target.__init__(self,myspec,addlargs)
184 -
185 - """
186 - The semantics of subarchmap and machinemap changed a bit in 2.0.3 to
187 - work better with vapier's CBUILD stuff. I've removed the "monolithic"
188 - machinemap from this file and split up its contents amongst the
189 - various arch/foo.py files.
190 -
191 - When register() is called on each module in the arch/ dir, it now
192 - returns a tuple instead of acting on the subarchmap dict that is
193 - passed to it. The tuple contains the values that were previously
194 - added to subarchmap as well as a new list of CHOSTs that go along
195 - with that arch. This allows us to build machinemap on the fly based
196 - on the keys in subarchmap and the values of the 2nd list returned
197 - (tmpmachinemap).
198 -
199 - Also, after talking with vapier. I have a slightly better idea of what
200 - certain variables are used for and what they should be set to. Neither
201 - 'buildarch' or 'hostarch' are used directly, so their value doesn't
202 - really matter. They are just compared to determine if we are
203 - cross-compiling. Because of this, they are just set to the name of the
204 - module in arch/ that the subarch is part of to make things simpler.
205 - The entire build process is still based off of 'subarch' like it was
206 - previously. -agaffney
207 - """
208 -
209 - self.archmap = {}
210 - self.subarchmap = {}
211 - machinemap = {}
212 - arch_dir = self.settings["PythonDir"] + "/arch/"
213 - for x in [x[:-3] for x in os.listdir(arch_dir) if x.endswith(".py")]:
214 - try:
215 - fh=open(arch_dir + x + ".py")
216 - """
217 - This next line loads the plugin as a module and assigns it to
218 - archmap[x]
219 - """
220 - self.archmap[x]=imp.load_module(x,fh,"../arch/" + x + ".py",
221 - (".py", "r", imp.PY_SOURCE))
222 - """
223 - This next line registers all the subarches supported in the
224 - plugin
225 - """
226 - tmpsubarchmap, tmpmachinemap = self.archmap[x].register()
227 - self.subarchmap.update(tmpsubarchmap)
228 - for machine in tmpmachinemap:
229 - machinemap[machine] = x
230 - for subarch in tmpsubarchmap:
231 - machinemap[subarch] = x
232 - fh.close()
233 - except IOError:
234 - """
235 - This message should probably change a bit, since everything in
236 - the dir should load just fine. If it doesn't, it's probably a
237 - syntax error in the module
238 - """
239 - msg("Can't find/load " + x + ".py plugin in " + arch_dir)
240 -
241 - if "chost" in self.settings:
242 - hostmachine = self.settings["chost"].split("-")[0]
243 - if hostmachine not in machinemap:
244 - raise CatalystError, "Unknown host machine type "+hostmachine
245 - self.settings["hostarch"]=machinemap[hostmachine]
246 - else:
247 - hostmachine = self.settings["subarch"]
248 - if hostmachine in machinemap:
249 - hostmachine = machinemap[hostmachine]
250 - self.settings["hostarch"]=hostmachine
251 - if "cbuild" in self.settings:
252 - buildmachine = self.settings["cbuild"].split("-")[0]
253 - else:
254 - buildmachine = os.uname()[4]
255 - if buildmachine not in machinemap:
256 - raise CatalystError, "Unknown build machine type "+buildmachine
257 - self.settings["buildarch"]=machinemap[buildmachine]
258 - self.settings["crosscompile"]=(self.settings["hostarch"]!=\
259 - self.settings["buildarch"])
260 -
261 - """ Call arch constructor, pass our settings """
262 - try:
263 - self.arch=self.subarchmap[self.settings["subarch"]](self.settings)
264 - except KeyError:
265 - print "Invalid subarch: "+self.settings["subarch"]
266 - print "Choose one of the following:",
267 - for x in self.subarchmap:
268 - print x,
269 - print
270 - sys.exit(2)
271 -
272 - print "Using target:",self.settings["target"]
273 - """ Print a nice informational message """
274 - if self.settings["buildarch"]==self.settings["hostarch"]:
275 - print "Building natively for",self.settings["hostarch"]
276 - elif self.settings["crosscompile"]:
277 - print "Cross-compiling on",self.settings["buildarch"],\
278 - "for different machine type",self.settings["hostarch"]
279 - else:
280 - print "Building on",self.settings["buildarch"],\
281 - "for alternate personality type",self.settings["hostarch"]
282 -
283 - """ This must be set first as other set_ options depend on this """
284 - self.set_spec_prefix()
285 -
286 - """ Define all of our core variables """
287 - self.set_target_profile()
288 - self.set_target_subpath()
289 - self.set_source_subpath()
290 -
291 - """ Set paths """
292 - self.set_snapshot_path()
293 - self.set_root_path()
294 - self.set_source_path()
295 - self.set_snapcache_path()
296 - self.set_chroot_path()
297 - self.set_autoresume_path()
298 - self.set_dest_path()
299 - self.set_stage_path()
300 - self.set_target_path()
301 -
302 - self.set_controller_file()
303 - self.set_action_sequence()
304 - self.set_use()
305 - self.set_cleanables()
306 - self.set_iso_volume_id()
307 - self.set_build_kernel_vars()
308 - self.set_fsscript()
309 - self.set_install_mask()
310 - self.set_rcadd()
311 - self.set_rcdel()
312 - self.set_cdtar()
313 - self.set_fstype()
314 - self.set_fsops()
315 - self.set_iso()
316 - self.set_packages()
317 - self.set_rm()
318 - self.set_linuxrc()
319 - self.set_busybox_config()
320 - self.set_overlay()
321 - self.set_portage_overlay()
322 - self.set_root_overlay()
323 -
324 - """
325 - This next line checks to make sure that the specified variables exist
326 - on disk.
327 - """
328 - #pdb.set_trace()
329 - file_locate(self.settings,["source_path","snapshot_path","distdir"],\
330 - expand=0)
331 - """ If we are using portage_confdir, check that as well. """
332 - if "portage_confdir" in self.settings:
333 - file_locate(self.settings,["portage_confdir"],expand=0)
334 -
335 - """ Setup our mount points """
336 - if "SNAPCACHE" in self.settings:
337 - self.mounts=["/proc","/dev","/usr/portage","/usr/portage/distfiles","/var/tmp/portage"]
338 - self.mountmap={"/proc":"/proc","/dev":"/dev","/dev/pts":"/dev/pts",\
339 - "/usr/portage":self.settings["snapshot_cache_path"]+"/portage",\
340 - "/usr/portage/distfiles":self.settings["distdir"],"/var/tmp/portage":"tmpfs"}
341 - else:
342 - self.mounts=["proc","dev", "distdir", "port_tmpdir"]
343 - self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
344 - "distdir":self.settings["distdir"], "port_tmpdir":"tmpfs"}
345 - if os.uname()[0] == "Linux":
346 - self.mounts.append("pts")
347 -
348 - self.set_mounts()
349 -
350 - """
351 - Configure any user specified options (either in catalyst.conf or on
352 - the command line).
353 - """
354 - if "PKGCACHE" in self.settings:
355 - self.set_pkgcache_path()
356 - print "Location of the package cache is "+\
357 - self.settings["pkgcache_path"]
358 - self.mounts.append("packagedir")
359 - self.mountmap["packagedir"] = self.settings["pkgcache_path"]
360 -
361 - if "KERNCACHE" in self.settings:
362 - self.set_kerncache_path()
363 - print "Location of the kerncache is "+\
364 - self.settings["kerncache_path"]
365 - self.mounts.append("kerncache")
366 - self.mountmap["kerncache"]=self.settings["kerncache_path"]
367 -
368 - if "CCACHE" in self.settings:
369 - if "CCACHE_DIR" in os.environ:
370 - ccdir=os.environ["CCACHE_DIR"]
371 - del os.environ["CCACHE_DIR"]
372 - else:
373 - ccdir="/root/.ccache"
374 - if not os.path.isdir(ccdir):
375 - raise CatalystError,\
376 - "Compiler cache support can't be enabled (can't find "+\
377 - ccdir+")"
378 - self.mounts.append("ccache")
379 - self.mountmap["ccache"]=ccdir
380 - """ for the chroot: """
381 - self.env["CCACHE_DIR"]="/var/tmp/ccache"
382 -
383 - if "ICECREAM" in self.settings:
384 - self.mounts.append("/var/cache/icecream")
385 - self.mountmap["/var/cache/icecream"]="/var/cache/icecream"
386 - self.env["PATH"]="/usr/lib/icecc/bin:"+self.env["PATH"]
387 -
388 - if "port_logdir" in self.settings:
389 - self.mounts.append("/var/log/portage")
390 - self.mountmap["/var/log/portage"]=self.settings["port_logdir"]
391 - self.env["PORT_LOGDIR"]="/var/log/portage"
392 - self.env["PORT_LOGDIR_CLEAN"]='find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete'
393 -
394 - def override_cbuild(self):
395 - if "CBUILD" in self.makeconf:
396 - self.settings["CBUILD"]=self.makeconf["CBUILD"]
397 -
398 - def override_chost(self):
399 - if "CHOST" in self.makeconf:
400 - self.settings["CHOST"]=self.makeconf["CHOST"]
401 -
402 - def override_cflags(self):
403 - if "CFLAGS" in self.makeconf:
404 - self.settings["CFLAGS"]=self.makeconf["CFLAGS"]
405 -
406 - def override_cxxflags(self):
407 - if "CXXFLAGS" in self.makeconf:
408 - self.settings["CXXFLAGS"]=self.makeconf["CXXFLAGS"]
409 -
410 - def override_ldflags(self):
411 - if "LDFLAGS" in self.makeconf:
412 - self.settings["LDFLAGS"]=self.makeconf["LDFLAGS"]
413 -
414 - def set_install_mask(self):
415 - if "install_mask" in self.settings:
416 - if type(self.settings["install_mask"])!=types.StringType:
417 - self.settings["install_mask"]=\
418 - string.join(self.settings["install_mask"])
419 -
420 - def set_spec_prefix(self):
421 - self.settings["spec_prefix"]=self.settings["target"]
422 -
423 - def set_target_profile(self):
424 - self.settings["target_profile"]=self.settings["profile"]
425 -
426 - def set_target_subpath(self):
427 - self.settings["target_subpath"]=self.settings["rel_type"]+"/"+\
428 - self.settings["target"]+"-"+self.settings["subarch"]+"-"+\
429 - self.settings["version_stamp"]
430 -
431 - def set_source_subpath(self):
432 - if type(self.settings["source_subpath"])!=types.StringType:
433 - raise CatalystError,\
434 - "source_subpath should have been a string. Perhaps you have something wrong in your spec file?"
435 -
436 - def set_pkgcache_path(self):
437 - if "pkgcache_path" in self.settings:
438 - if type(self.settings["pkgcache_path"])!=types.StringType:
439 - self.settings["pkgcache_path"]=\
440 - normpath(string.join(self.settings["pkgcache_path"]))
441 - else:
442 - self.settings["pkgcache_path"]=\
443 - normpath(self.settings["storedir"]+"/packages/"+\
444 - self.settings["target_subpath"]+"/")
445 -
446 - def set_kerncache_path(self):
447 - if "kerncache_path" in self.settings:
448 - if type(self.settings["kerncache_path"])!=types.StringType:
449 - self.settings["kerncache_path"]=\
450 - normpath(string.join(self.settings["kerncache_path"]))
451 - else:
452 - self.settings["kerncache_path"]=normpath(self.settings["storedir"]+\
453 - "/kerncache/"+self.settings["target_subpath"]+"/")
454 -
455 - def set_target_path(self):
456 - self.settings["target_path"]=normpath(self.settings["storedir"]+\
457 - "/builds/"+self.settings["target_subpath"]+".tar.bz2")
458 - if "AUTORESUME" in self.settings\
459 - and os.path.exists(self.settings["autoresume_path"]+\
460 - "setup_target_path"):
461 - print \
462 - "Resume point detected, skipping target path setup operation..."
463 - else:
464 - """ First clean up any existing target stuff """
465 - # XXX WTF are we removing the old tarball before we start building the
466 - # XXX new one? If the build fails, you don't want to be left with
467 - # XXX nothing at all
468 -# if os.path.isfile(self.settings["target_path"]):
469 -# cmd("rm -f "+self.settings["target_path"],\
470 -# "Could not remove existing file: "\
471 -# +self.settings["target_path"],env=self.env)
472 - touch(self.settings["autoresume_path"]+"setup_target_path")
473 -
474 - if not os.path.exists(self.settings["storedir"]+"/builds/"):
475 - os.makedirs(self.settings["storedir"]+"/builds/")
476 -
477 - def set_fsscript(self):
478 - if self.settings["spec_prefix"]+"/fsscript" in self.settings:
479 - self.settings["fsscript"]=\
480 - self.settings[self.settings["spec_prefix"]+"/fsscript"]
481 - del self.settings[self.settings["spec_prefix"]+"/fsscript"]
482 -
483 - def set_rcadd(self):
484 - if self.settings["spec_prefix"]+"/rcadd" in self.settings:
485 - self.settings["rcadd"]=\
486 - self.settings[self.settings["spec_prefix"]+"/rcadd"]
487 - del self.settings[self.settings["spec_prefix"]+"/rcadd"]
488 -
489 - def set_rcdel(self):
490 - if self.settings["spec_prefix"]+"/rcdel" in self.settings:
491 - self.settings["rcdel"]=\
492 - self.settings[self.settings["spec_prefix"]+"/rcdel"]
493 - del self.settings[self.settings["spec_prefix"]+"/rcdel"]
494 -
495 - def set_cdtar(self):
496 - if self.settings["spec_prefix"]+"/cdtar" in self.settings:
497 - self.settings["cdtar"]=\
498 - normpath(self.settings[self.settings["spec_prefix"]+"/cdtar"])
499 - del self.settings[self.settings["spec_prefix"]+"/cdtar"]
500 -
501 - def set_iso(self):
502 - if self.settings["spec_prefix"]+"/iso" in self.settings:
503 - if self.settings[self.settings["spec_prefix"]+"/iso"].startswith('/'):
504 - self.settings["iso"]=\
505 - normpath(self.settings[self.settings["spec_prefix"]+"/iso"])
506 - else:
507 - # This automatically prepends the build dir to the ISO output path
508 - # if it doesn't start with a /
509 - self.settings["iso"] = normpath(self.settings["storedir"] + \
510 - "/builds/" + self.settings["rel_type"] + "/" + \
511 - self.settings[self.settings["spec_prefix"]+"/iso"])
512 - del self.settings[self.settings["spec_prefix"]+"/iso"]
513 -
514 - def set_fstype(self):
515 - if self.settings["spec_prefix"]+"/fstype" in self.settings:
516 - self.settings["fstype"]=\
517 - self.settings[self.settings["spec_prefix"]+"/fstype"]
518 - del self.settings[self.settings["spec_prefix"]+"/fstype"]
519 -
520 - if "fstype" not in self.settings:
521 - self.settings["fstype"]="normal"
522 - for x in self.valid_values:
523 - if x == self.settings["spec_prefix"]+"/fstype":
524 - print "\n"+self.settings["spec_prefix"]+\
525 - "/fstype is being set to the default of \"normal\"\n"
526 -
527 - def set_fsops(self):
528 - if "fstype" in self.settings:
529 - self.valid_values.append("fsops")
530 - if self.settings["spec_prefix"]+"/fsops" in self.settings:
531 - self.settings["fsops"]=\
532 - self.settings[self.settings["spec_prefix"]+"/fsops"]
533 - del self.settings[self.settings["spec_prefix"]+"/fsops"]
534 -
535 - def set_source_path(self):
536 - if "SEEDCACHE" in self.settings\
537 - and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+\
538 - self.settings["source_subpath"]+"/")):
539 - self.settings["source_path"]=normpath(self.settings["storedir"]+\
540 - "/tmp/"+self.settings["source_subpath"]+"/")
541 - else:
542 - self.settings["source_path"]=normpath(self.settings["storedir"]+\
543 - "/builds/"+self.settings["source_subpath"]+".tar.bz2")
544 - if os.path.isfile(self.settings["source_path"]):
545 - # XXX: Is this even necessary if the previous check passes?
546 - if os.path.exists(self.settings["source_path"]):
547 - self.settings["source_path_hash"]=\
548 - generate_hash(self.settings["source_path"],\
549 - hash_function=self.settings["hash_function"],\
550 - verbose=False)
551 - print "Source path set to "+self.settings["source_path"]
552 - if os.path.isdir(self.settings["source_path"]):
553 - print "\tIf this is not desired, remove this directory or turn off"
554 - print "\tseedcache in the options of catalyst.conf the source path"
555 - print "\twill then be "+\
556 - normpath(self.settings["storedir"]+"/builds/"+\
557 - self.settings["source_subpath"]+".tar.bz2\n")
558 -
559 - def set_dest_path(self):
560 - if "root_path" in self.settings:
561 - self.settings["destpath"]=normpath(self.settings["chroot_path"]+\
562 - self.settings["root_path"])
563 - else:
564 - self.settings["destpath"]=normpath(self.settings["chroot_path"])
565 -
566 - def set_cleanables(self):
567 - self.settings["cleanables"]=["/etc/resolv.conf","/var/tmp/*","/tmp/*",\
568 - "/root/*", self.settings["portdir"]]
569 -
570 - def set_snapshot_path(self):
571 - self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
572 - "/snapshots/" + self.settings["snapshot_name"] +
573 - self.settings["snapshot"]+".tar.xz")
574 -
575 - if os.path.exists(self.settings["snapshot_path"]):
576 - self.settings["snapshot_path_hash"]=\
577 - generate_hash(self.settings["snapshot_path"],\
578 - hash_function=self.settings["hash_function"],verbose=False)
579 - else:
580 - self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
581 - "/snapshots/" + self.settings["snapshot_name"] +
582 - self.settings["snapshot"]+".tar.bz2")
583 -
584 - if os.path.exists(self.settings["snapshot_path"]):
585 - self.settings["snapshot_path_hash"]=\
586 - generate_hash(self.settings["snapshot_path"],\
587 - hash_function=self.settings["hash_function"],verbose=False)
588 -
589 - def set_snapcache_path(self):
590 - if "SNAPCACHE" in self.settings:
591 - self.settings["snapshot_cache_path"]=\
592 - normpath(self.settings["snapshot_cache"]+"/"+\
593 - self.settings["snapshot"]+"/")
594 - self.snapcache_lock=\
595 - LockDir(self.settings["snapshot_cache_path"])
596 - print "Caching snapshot to "+self.settings["snapshot_cache_path"]
597 -
598 - def set_chroot_path(self):
599 - """
600 - NOTE: the trailing slash is very important!
601 - Things *will* break without it!
602 - """
603 - self.settings["chroot_path"]=normpath(self.settings["storedir"]+\
604 - "/tmp/"+self.settings["target_subpath"]+"/")
605 - self.chroot_lock=LockDir(self.settings["chroot_path"])
606 -
607 - def set_autoresume_path(self):
608 - self.settings["autoresume_path"]=normpath(self.settings["storedir"]+\
609 - "/tmp/"+self.settings["rel_type"]+"/"+".autoresume-"+\
610 - self.settings["target"]+"-"+self.settings["subarch"]+"-"+\
611 - self.settings["version_stamp"]+"/")
612 - if "AUTORESUME" in self.settings:
613 - print "The autoresume path is " + self.settings["autoresume_path"]
614 - if not os.path.exists(self.settings["autoresume_path"]):
615 - os.makedirs(self.settings["autoresume_path"],0755)
616 -
617 - def set_controller_file(self):
618 - self.settings["controller_file"]=normpath(self.settings["sharedir"]+\
619 - "/targets/"+self.settings["target"]+"/"+self.settings["target"]+\
620 - "-controller.sh")
621 -
622 - def set_iso_volume_id(self):
623 - if self.settings["spec_prefix"]+"/volid" in self.settings:
624 - self.settings["iso_volume_id"]=\
625 - self.settings[self.settings["spec_prefix"]+"/volid"]
626 - if len(self.settings["iso_volume_id"])>32:
627 - raise CatalystError,\
628 - "ISO volume ID must not exceed 32 characters."
629 - else:
630 - self.settings["iso_volume_id"]="catalyst "+self.settings["snapshot"]
631 -
632 - def set_action_sequence(self):
633 - """ Default action sequence for run method """
634 - self.settings["action_sequence"]=["unpack","unpack_snapshot",\
635 - "setup_confdir","portage_overlay",\
636 - "base_dirs","bind","chroot_setup","setup_environment",\
637 - "run_local","preclean","unbind","clean"]
638 -# if "TARBALL" in self.settings or \
639 -# "FETCH" not in self.settings:
640 - if "FETCH" not in self.settings:
641 - self.settings["action_sequence"].append("capture")
642 - self.settings["action_sequence"].append("clear_autoresume")
643 -
644 - def set_use(self):
645 - if self.settings["spec_prefix"]+"/use" in self.settings:
646 - self.settings["use"]=\
647 - self.settings[self.settings["spec_prefix"]+"/use"]
648 - del self.settings[self.settings["spec_prefix"]+"/use"]
649 - if "use" not in self.settings:
650 - self.settings["use"]=""
651 - if type(self.settings["use"])==types.StringType:
652 - self.settings["use"]=self.settings["use"].split()
653 -
654 - # Force bindist when options ask for it
655 - if "BINDIST" in self.settings:
656 - self.settings["use"].append("bindist")
657 -
658 - def set_stage_path(self):
659 - self.settings["stage_path"]=normpath(self.settings["chroot_path"])
660 -
661 - def set_mounts(self):
662 - pass
663 -
664 - def set_packages(self):
665 - pass
666 -
667 - def set_rm(self):
668 - if self.settings["spec_prefix"]+"/rm" in self.settings:
669 - if type(self.settings[self.settings["spec_prefix"]+\
670 - "/rm"])==types.StringType:
671 - self.settings[self.settings["spec_prefix"]+"/rm"]=\
672 - self.settings[self.settings["spec_prefix"]+"/rm"].split()
673 -
674 - def set_linuxrc(self):
675 - if self.settings["spec_prefix"]+"/linuxrc" in self.settings:
676 - if type(self.settings[self.settings["spec_prefix"]+\
677 - "/linuxrc"])==types.StringType:
678 - self.settings["linuxrc"]=\
679 - self.settings[self.settings["spec_prefix"]+"/linuxrc"]
680 - del self.settings[self.settings["spec_prefix"]+"/linuxrc"]
681 -
682 - def set_busybox_config(self):
683 - if self.settings["spec_prefix"]+"/busybox_config" in self.settings:
684 - if type(self.settings[self.settings["spec_prefix"]+\
685 - "/busybox_config"])==types.StringType:
686 - self.settings["busybox_config"]=\
687 - self.settings[self.settings["spec_prefix"]+"/busybox_config"]
688 - del self.settings[self.settings["spec_prefix"]+"/busybox_config"]
689 -
690 - def set_portage_overlay(self):
691 - if "portage_overlay" in self.settings:
692 - if type(self.settings["portage_overlay"])==types.StringType:
693 - self.settings["portage_overlay"]=\
694 - self.settings["portage_overlay"].split()
695 - print "portage_overlay directories are set to: \""+\
696 - string.join(self.settings["portage_overlay"])+"\""
697 -
698 - def set_overlay(self):
699 - if self.settings["spec_prefix"]+"/overlay" in self.settings:
700 - if type(self.settings[self.settings["spec_prefix"]+\
701 - "/overlay"])==types.StringType:
702 - self.settings[self.settings["spec_prefix"]+"/overlay"]=\
703 - self.settings[self.settings["spec_prefix"]+\
704 - "/overlay"].split()
705 -
706 - def set_root_overlay(self):
707 - if self.settings["spec_prefix"]+"/root_overlay" in self.settings:
708 - if type(self.settings[self.settings["spec_prefix"]+\
709 - "/root_overlay"])==types.StringType:
710 - self.settings[self.settings["spec_prefix"]+"/root_overlay"]=\
711 - self.settings[self.settings["spec_prefix"]+\
712 - "/root_overlay"].split()
713 -
714 - def set_root_path(self):
715 - """ ROOT= variable for emerges """
716 - self.settings["root_path"]="/"
717 -
718 - def set_valid_build_kernel_vars(self,addlargs):
719 - if "boot/kernel" in addlargs:
720 - if type(addlargs["boot/kernel"])==types.StringType:
721 - loopy=[addlargs["boot/kernel"]]
722 - else:
723 - loopy=addlargs["boot/kernel"]
724 -
725 - for x in loopy:
726 - self.valid_values.append("boot/kernel/"+x+"/aliases")
727 - self.valid_values.append("boot/kernel/"+x+"/config")
728 - self.valid_values.append("boot/kernel/"+x+"/console")
729 - self.valid_values.append("boot/kernel/"+x+"/extraversion")
730 - self.valid_values.append("boot/kernel/"+x+"/gk_action")
731 - self.valid_values.append("boot/kernel/"+x+"/gk_kernargs")
732 - self.valid_values.append("boot/kernel/"+x+"/initramfs_overlay")
733 - self.valid_values.append("boot/kernel/"+x+"/machine_type")
734 - self.valid_values.append("boot/kernel/"+x+"/sources")
735 - self.valid_values.append("boot/kernel/"+x+"/softlevel")
736 - self.valid_values.append("boot/kernel/"+x+"/use")
737 - self.valid_values.append("boot/kernel/"+x+"/packages")
738 - if "boot/kernel/"+x+"/packages" in addlargs:
739 - if type(addlargs["boot/kernel/"+x+\
740 - "/packages"])==types.StringType:
741 - addlargs["boot/kernel/"+x+"/packages"]=\
742 - [addlargs["boot/kernel/"+x+"/packages"]]
743 -
744 - def set_build_kernel_vars(self):
745 - if self.settings["spec_prefix"]+"/gk_mainargs" in self.settings:
746 - self.settings["gk_mainargs"]=\
747 - self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
748 - del self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
749 -
750 - def kill_chroot_pids(self):
751 - print "Checking for processes running in chroot and killing them."
752 -
753 - """
754 - Force environment variables to be exported so script can see them
755 - """
756 - self.setup_environment()
757 -
758 - if os.path.exists(self.settings["sharedir"]+\
759 - "/targets/support/kill-chroot-pids.sh"):
760 - cmd("/bin/bash "+self.settings["sharedir"]+\
761 - "/targets/support/kill-chroot-pids.sh",\
762 - "kill-chroot-pids script failed.",env=self.env)
763 -
764 - def mount_safety_check(self):
765 - mypath=self.settings["chroot_path"]
766 -
767 - """
768 - Check and verify that none of our paths in mypath are mounted. We don't
769 - want to clean up with things still mounted, and this allows us to check.
770 - Returns 1 on ok, 0 on "something is still mounted" case.
771 - """
772 -
773 - if not os.path.exists(mypath):
774 - return
775 -
776 - for x in self.mounts:
777 - if not os.path.exists(mypath + self.mountmap[x]):
778 - continue
779 -
780 - if ismount(mypath +self.mountmap[x]):
781 - """ Something is still mounted "" """
782 - try:
783 - print self.mountmap[x] + " is still mounted; performing auto-bind-umount...",
784 - """ Try to umount stuff ourselves """
785 - self.unbind()
786 - if ismount(mypath + self.mountmap[x]):
787 - raise CatalystError, "Auto-unbind failed for " + self.mountmap[x]
788 - else:
789 - print "Auto-unbind successful..."
790 - except CatalystError:
791 - raise CatalystError, "Unable to auto-unbind " + self.mountmap[x]
792 -
793 - def unpack(self):
794 - unpack=True
795 -
796 - clst_unpack_hash=read_from_clst(self.settings["autoresume_path"]+\
797 - "unpack")
798 -
799 - if "SEEDCACHE" in self.settings:
800 - if os.path.isdir(self.settings["source_path"]):
801 - """ SEEDCACHE Is a directory, use rsync """
802 - unpack_cmd="rsync -a --delete "+self.settings["source_path"]+\
803 - " "+self.settings["chroot_path"]
804 - display_msg="\nStarting rsync from "+\
805 - self.settings["source_path"]+"\nto "+\
806 - self.settings["chroot_path"]+\
807 - " (This may take some time) ...\n"
808 - error_msg="Rsync of "+self.settings["source_path"]+" to "+\
809 - self.settings["chroot_path"]+" failed."
810 - else:
811 - """ SEEDCACHE is a not a directory, try untar'ing """
812 - print "Referenced SEEDCACHE does not appear to be a directory, trying to untar..."
813 - display_msg="\nStarting tar extract from "+\
814 - self.settings["source_path"]+"\nto "+\
815 - self.settings["chroot_path"]+\
816 - " (This may take some time) ...\n"
817 - if "bz2" == self.settings["chroot_path"][-3:]:
818 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
819 - self.settings["chroot_path"]
820 - else:
821 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
822 - self.settings["chroot_path"]
823 - error_msg="Tarball extraction of "+\
824 - self.settings["source_path"]+" to "+\
825 - self.settings["chroot_path"]+" failed."
826 - else:
827 - """ No SEEDCACHE, use tar """
828 - display_msg="\nStarting tar extract from "+\
829 - self.settings["source_path"]+"\nto "+\
830 - self.settings["chroot_path"]+\
831 - " (This may take some time) ...\n"
832 - if "bz2" == self.settings["chroot_path"][-3:]:
833 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
834 - self.settings["chroot_path"]
835 - else:
836 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
837 - self.settings["chroot_path"]
838 - error_msg="Tarball extraction of "+self.settings["source_path"]+\
839 - " to "+self.settings["chroot_path"]+" failed."
840 -
841 - if "AUTORESUME" in self.settings:
842 - if os.path.isdir(self.settings["source_path"]) \
843 - and os.path.exists(self.settings["autoresume_path"]+"unpack"):
844 - """ Autoresume is valid, SEEDCACHE is valid """
845 - unpack=False
846 - invalid_snapshot=False
847 -
848 - elif os.path.isfile(self.settings["source_path"]) \
849 - and self.settings["source_path_hash"]==clst_unpack_hash:
850 - """ Autoresume is valid, tarball is valid """
851 - unpack=False
852 - invalid_snapshot=True
853 -
854 - elif os.path.isdir(self.settings["source_path"]) \
855 - and not os.path.exists(self.settings["autoresume_path"]+\
856 - "unpack"):
857 - """ Autoresume is invalid, SEEDCACHE """
858 - unpack=True
859 - invalid_snapshot=False
860 -
861 - elif os.path.isfile(self.settings["source_path"]) \
862 - and self.settings["source_path_hash"]!=clst_unpack_hash:
863 - """ Autoresume is invalid, tarball """
864 - unpack=True
865 - invalid_snapshot=True
866 - else:
867 - """ No autoresume, SEEDCACHE """
868 - if "SEEDCACHE" in self.settings:
869 - """ SEEDCACHE so let's run rsync and let it clean up """
870 - if os.path.isdir(self.settings["source_path"]):
871 - unpack=True
872 - invalid_snapshot=False
873 - elif os.path.isfile(self.settings["source_path"]):
874 - """ Tarball so unpack and remove anything already there """
875 - unpack=True
876 - invalid_snapshot=True
877 - """ No autoresume, no SEEDCACHE """
878 - else:
879 - """ Tarball so unpack and remove anything already there """
880 - if os.path.isfile(self.settings["source_path"]):
881 - unpack=True
882 - invalid_snapshot=True
883 - elif os.path.isdir(self.settings["source_path"]):
884 - """ We should never reach this, so something is very wrong """
885 - raise CatalystError,\
886 - "source path is a dir but seedcache is not enabled"
887 -
888 - if unpack:
889 - self.mount_safety_check()
890 -
891 - if invalid_snapshot:
892 - if "AUTORESUME" in self.settings:
893 - print "No Valid Resume point detected, cleaning up..."
894 -
895 - self.clear_autoresume()
896 - self.clear_chroot()
897 -
898 - if not os.path.exists(self.settings["chroot_path"]):
899 - os.makedirs(self.settings["chroot_path"])
900 -
901 - if not os.path.exists(self.settings["chroot_path"]+"/tmp"):
902 - os.makedirs(self.settings["chroot_path"]+"/tmp",1777)
903 -
904 - if "PKGCACHE" in self.settings:
905 - if not os.path.exists(self.settings["pkgcache_path"]):
906 - os.makedirs(self.settings["pkgcache_path"],0755)
907 -
908 - if "KERNCACHE" in self.settings:
909 - if not os.path.exists(self.settings["kerncache_path"]):
910 - os.makedirs(self.settings["kerncache_path"],0755)
911 -
912 - print display_msg
913 - cmd(unpack_cmd,error_msg,env=self.env)
914 -
915 - if "source_path_hash" in self.settings:
916 - myf=open(self.settings["autoresume_path"]+"unpack","w")
917 - myf.write(self.settings["source_path_hash"])
918 - myf.close()
919 - else:
920 - touch(self.settings["autoresume_path"]+"unpack")
921 - else:
922 - print "Resume point detected, skipping unpack operation..."
923 -
924 - def unpack_snapshot(self):
925 - unpack=True
926 - snapshot_hash=read_from_clst(self.settings["autoresume_path"]+\
927 - "unpack_portage")
928 -
929 - if "SNAPCACHE" in self.settings:
930 - snapshot_cache_hash=\
931 - read_from_clst(self.settings["snapshot_cache_path"]+\
932 - "catalyst-hash")
933 - destdir=self.settings["snapshot_cache_path"]
934 - if "bz2" == self.settings["chroot_path"][-3:]:
935 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["snapshot_path"]+" -C "+destdir
936 - else:
937 - unpack_cmd="tar xpf "+self.settings["snapshot_path"]+" -C "+destdir
938 - unpack_errmsg="Error unpacking snapshot"
939 - cleanup_msg="Cleaning up invalid snapshot cache at \n\t"+\
940 - self.settings["snapshot_cache_path"]+\
941 - " (This can take a long time)..."
942 - cleanup_errmsg="Error removing existing snapshot cache directory."
943 - self.snapshot_lock_object=self.snapcache_lock
944 -
945 - if self.settings["snapshot_path_hash"]==snapshot_cache_hash:
946 - print "Valid snapshot cache, skipping unpack of portage tree..."
947 - unpack=False
948 - else:
949 - destdir=normpath(self.settings["chroot_path"] + self.settings["portdir"])
950 - cleanup_errmsg="Error removing existing snapshot directory."
951 - cleanup_msg=\
952 - "Cleaning up existing portage tree (This can take a long time)..."
953 - if "bz2" == self.settings["chroot_path"][-3:]:
954 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["snapshot_path"]+" -C "+\
955 - self.settings["chroot_path"]+"/usr"
956 - else:
957 - unpack_cmd="tar xpf "+self.settings["snapshot_path"]+" -C "+\
958 - self.settings["chroot_path"]+"/usr"
959 - unpack_errmsg="Error unpacking snapshot"
960 -
961 - if "AUTORESUME" in self.settings \
962 - and os.path.exists(self.settings["chroot_path"]+\
963 - self.settings["portdir"]) \
964 - and os.path.exists(self.settings["autoresume_path"]\
965 - +"unpack_portage") \
966 - and self.settings["snapshot_path_hash"] == snapshot_hash:
967 - print \
968 - "Valid Resume point detected, skipping unpack of portage tree..."
969 - unpack=False
970 -
971 - if unpack:
972 - if "SNAPCACHE" in self.settings:
973 - self.snapshot_lock_object.write_lock()
974 - if os.path.exists(destdir):
975 - print cleanup_msg
976 - cleanup_cmd="rm -rf "+destdir
977 - cmd(cleanup_cmd,cleanup_errmsg,env=self.env)
978 - if not os.path.exists(destdir):
979 - os.makedirs(destdir,0755)
980 -
981 - print "Unpacking portage tree (This can take a long time) ..."
982 - cmd(unpack_cmd,unpack_errmsg,env=self.env)
983 -
984 - if "SNAPCACHE" in self.settings:
985 - myf=open(self.settings["snapshot_cache_path"]+"catalyst-hash","w")
986 - myf.write(self.settings["snapshot_path_hash"])
987 - myf.close()
988 - else:
989 - print "Setting snapshot autoresume point"
990 - myf=open(self.settings["autoresume_path"]+"unpack_portage","w")
991 - myf.write(self.settings["snapshot_path_hash"])
992 - myf.close()
993 -
994 - if "SNAPCACHE" in self.settings:
995 - self.snapshot_lock_object.unlock()
996 -
997 - def config_profile_link(self):
998 - if "AUTORESUME" in self.settings \
999 - and os.path.exists(self.settings["autoresume_path"]+\
1000 - "config_profile_link"):
1001 - print \
1002 - "Resume point detected, skipping config_profile_link operation..."
1003 - else:
1004 - # TODO: zmedico and I discussed making this a directory and pushing
1005 - # in a parent file, as well as other user-specified configuration.
1006 - print "Configuring profile link..."
1007 - cmd("rm -f "+self.settings["chroot_path"]+"/etc/portage/make.profile",\
1008 - "Error zapping profile link",env=self.env)
1009 - cmd("mkdir -p "+self.settings["chroot_path"]+"/etc/portage/")
1010 - cmd("ln -sf ../.." + self.settings["portdir"] + "/profiles/"+\
1011 - self.settings["target_profile"]+" "+\
1012 - self.settings["chroot_path"]+"/etc/portage/make.profile",\
1013 - "Error creating profile link",env=self.env)
1014 - touch(self.settings["autoresume_path"]+"config_profile_link")
1015 -
1016 - def setup_confdir(self):
1017 - if "AUTORESUME" in self.settings \
1018 - and os.path.exists(self.settings["autoresume_path"]+\
1019 - "setup_confdir"):
1020 - print "Resume point detected, skipping setup_confdir operation..."
1021 - else:
1022 - if "portage_confdir" in self.settings:
1023 - print "Configuring /etc/portage..."
1024 - cmd("rsync -a "+self.settings["portage_confdir"]+"/ "+\
1025 - self.settings["chroot_path"]+"/etc/portage/",\
1026 - "Error copying /etc/portage",env=self.env)
1027 - touch(self.settings["autoresume_path"]+"setup_confdir")
1028 -
1029 - def portage_overlay(self):
1030 - """ We copy the contents of our overlays to /usr/local/portage """
1031 - if "portage_overlay" in self.settings:
1032 - for x in self.settings["portage_overlay"]:
1033 - if os.path.exists(x):
1034 - print "Copying overlay dir " +x
1035 - cmd("mkdir -p "+self.settings["chroot_path"]+\
1036 - self.settings["local_overlay"],\
1037 - "Could not make portage_overlay dir",env=self.env)
1038 - cmd("cp -R "+x+"/* "+self.settings["chroot_path"]+\
1039 - self.settings["local_overlay"],\
1040 - "Could not copy portage_overlay",env=self.env)
1041 -
1042 - def root_overlay(self):
1043 - """ Copy over the root_overlay """
1044 - if self.settings["spec_prefix"]+"/root_overlay" in self.settings:
1045 - for x in self.settings[self.settings["spec_prefix"]+\
1046 - "/root_overlay"]:
1047 - if os.path.exists(x):
1048 - print "Copying root_overlay: "+x
1049 - cmd("rsync -a "+x+"/ "+\
1050 - self.settings["chroot_path"],\
1051 - self.settings["spec_prefix"]+"/root_overlay: "+x+\
1052 - " copy failed.",env=self.env)
1053 -
1054 - def base_dirs(self):
1055 - pass
1056 -
1057 - def bind(self):
1058 - for x in self.mounts:
1059 - if not os.path.exists(self.settings["chroot_path"] + self.mountmap[x]):
1060 - os.makedirs(self.settings["chroot_path"]+x,0755)
1061 -
1062 - if not os.path.exists(self.mountmap[x]):
1063 - if not self.mountmap[x] == "tmpfs":
1064 - os.makedirs(self.mountmap[x],0755)
1065 -
1066 - src=self.mountmap[x]
1067 - if "SNAPCACHE" in self.settings and x == "/usr/portage":
1068 - self.snapshot_lock_object.read_lock()
1069 - if os.uname()[0] == "FreeBSD":
1070 - if src == "/dev":
1071 - retval=os.system("mount -t devfs none " +
1072 - self.settings["chroot_path"] + src)
1073 - else:
1074 - retval=os.system("mount_nullfs " + src + " " +
1075 - self.settings["chroot_path"] + src)
1076 - else:
1077 - if src == "tmpfs":
1078 - if "var_tmpfs_portage" in self.settings:
1079 - retval=os.system("mount -t tmpfs -o size="+\
1080 - self.settings["var_tmpfs_portage"]+"G "+src+" "+\
1081 - self.settings["chroot_path"]+x)
1082 - else:
1083 - retval=os.system("mount --bind " + src + " " +
1084 - self.settings["chroot_path"] + src)
1085 - if retval!=0:
1086 - self.unbind()
1087 - raise CatalystError,"Couldn't bind mount " + src
1088 -
1089 - def unbind(self):
1090 - ouch=0
1091 - mypath=self.settings["chroot_path"]
1092 - myrevmounts=self.mounts[:]
1093 - myrevmounts.reverse()
1094 - """ Unmount in reverse order for nested bind-mounts """
1095 - for x in myrevmounts:
1096 - if not os.path.exists(mypath + self.mountmap[x]):
1097 - continue
1098 -
1099 - if not ismount(mypath + self.mountmap[x]):
1100 - continue
1101 -
1102 - retval=os.system("umount "+\
1103 - os.path.join(mypath, self.mountmap[x].lstrip(os.path.sep)))
1104 -
1105 - if retval!=0:
1106 - warn("First attempt to unmount: " + mypath +
1107 - self.mountmap[x] +" failed.")
1108 - warn("Killing any pids still running in the chroot")
1109 -
1110 - self.kill_chroot_pids()
1111 -
1112 - retval2=os.system("umount " + mypath + self.mountmap[x])
1113 - if retval2!=0:
1114 - ouch=1
1115 - warn("Couldn't umount bind mount: " + mypath + self.mountmap[x])
1116 -
1117 - if "SNAPCACHE" in self.settings and x == "/usr/portage":
1118 - try:
1119 - """
1120 - It's possible the snapshot lock object isn't created yet.
1121 - This is because mount safety check calls unbind before the
1122 - target is fully initialized
1123 - """
1124 - self.snapshot_lock_object.unlock()
1125 - except:
1126 - pass
1127 - if ouch:
1128 - """
1129 - if any bind mounts really failed, then we need to raise
1130 - this to potentially prevent an upcoming bash stage cleanup script
1131 - from wiping our bind mounts.
1132 - """
1133 - raise CatalystError,\
1134 - "Couldn't umount one or more bind-mounts; aborting for safety."
1135 -
1136 - def chroot_setup(self):
1137 - self.makeconf=read_makeconf(self.settings["chroot_path"]+\
1138 - "/etc/portage/make.conf")
1139 - self.override_cbuild()
1140 - self.override_chost()
1141 - self.override_cflags()
1142 - self.override_cxxflags()
1143 - self.override_ldflags()
1144 - if "AUTORESUME" in self.settings \
1145 - and os.path.exists(self.settings["autoresume_path"]+"chroot_setup"):
1146 - print "Resume point detected, skipping chroot_setup operation..."
1147 - else:
1148 - print "Setting up chroot..."
1149 -
1150 - #self.makeconf=read_makeconf(self.settings["chroot_path"]+"/etc/portage/make.conf")
1151 -
1152 - cmd("cp /etc/resolv.conf "+self.settings["chroot_path"]+"/etc",\
1153 - "Could not copy resolv.conf into place.",env=self.env)
1154 -
1155 - """ Copy over the envscript, if applicable """
1156 - if "ENVSCRIPT" in self.settings:
1157 - if not os.path.exists(self.settings["ENVSCRIPT"]):
1158 - raise CatalystError,\
1159 - "Can't find envscript "+self.settings["ENVSCRIPT"]
1160 -
1161 - print "\nWarning!!!!"
1162 - print "\tOverriding certain env variables may cause catastrophic failure."
1163 - print "\tIf your build fails look here first as the possible problem."
1164 - print "\tCatalyst assumes you know what you are doing when setting"
1165 - print "\t\tthese variables."
1166 - print "\tCatalyst Maintainers use VERY minimal envscripts if used at all"
1167 - print "\tYou have been warned\n"
1168 -
1169 - cmd("cp "+self.settings["ENVSCRIPT"]+" "+\
1170 - self.settings["chroot_path"]+"/tmp/envscript",\
1171 - "Could not copy envscript into place.",env=self.env)
1172 -
1173 - """
1174 - Copy over /etc/hosts from the host in case there are any
1175 - specialties in there
1176 - """
1177 - if os.path.exists(self.settings["chroot_path"]+"/etc/hosts"):
1178 - cmd("mv "+self.settings["chroot_path"]+"/etc/hosts "+\
1179 - self.settings["chroot_path"]+"/etc/hosts.catalyst",\
1180 - "Could not backup /etc/hosts",env=self.env)
1181 - cmd("cp /etc/hosts "+self.settings["chroot_path"]+"/etc/hosts",\
1182 - "Could not copy /etc/hosts",env=self.env)
1183 -
1184 - """ Modify and write out make.conf (for the chroot) """
1185 - cmd("rm -f "+self.settings["chroot_path"]+"/etc/portage/make.conf",\
1186 - "Could not remove "+self.settings["chroot_path"]+\
1187 - "/etc/portage/make.conf",env=self.env)
1188 - myf=open(self.settings["chroot_path"]+"/etc/portage/make.conf","w")
1189 - myf.write("# These settings were set by the catalyst build script that automatically\n# built this stage.\n")
1190 - myf.write("# Please consult /usr/share/portage/config/make.conf.example for a more\n# detailed example.\n")
1191 - if "CFLAGS" in self.settings:
1192 - myf.write('CFLAGS="'+self.settings["CFLAGS"]+'"\n')
1193 - if "CXXFLAGS" in self.settings:
1194 - if self.settings["CXXFLAGS"]!=self.settings["CFLAGS"]:
1195 - myf.write('CXXFLAGS="'+self.settings["CXXFLAGS"]+'"\n')
1196 - else:
1197 - myf.write('CXXFLAGS="${CFLAGS}"\n')
1198 - else:
1199 - myf.write('CXXFLAGS="${CFLAGS}"\n')
1200 -
1201 - if "LDFLAGS" in self.settings:
1202 - myf.write("# LDFLAGS is unsupported. USE AT YOUR OWN RISK!\n")
1203 - myf.write('LDFLAGS="'+self.settings["LDFLAGS"]+'"\n')
1204 - if "CBUILD" in self.settings:
1205 - myf.write("# This should not be changed unless you know exactly what you are doing. You\n# should probably be using a different stage, instead.\n")
1206 - myf.write('CBUILD="'+self.settings["CBUILD"]+'"\n')
1207 -
1208 - myf.write("# WARNING: Changing your CHOST is not something that should be done lightly.\n# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.\n")
1209 - myf.write('CHOST="'+self.settings["CHOST"]+'"\n')
1210 -
1211 - """ Figure out what our USE vars are for building """
1212 - myusevars=[]
1213 - if "HOSTUSE" in self.settings:
1214 - myusevars.extend(self.settings["HOSTUSE"])
1215 -
1216 - if "use" in self.settings:
1217 - myusevars.extend(self.settings["use"])
1218 -
1219 - if myusevars:
1220 - myf.write("# These are the USE flags that were used in addition to what is provided by the\n# profile used for building.\n")
1221 - myusevars = sorted(set(myusevars))
1222 - myf.write('USE="'+string.join(myusevars)+'"\n')
1223 - if '-*' in myusevars:
1224 - print "\nWarning!!! "
1225 - print "\tThe use of -* in "+self.settings["spec_prefix"]+\
1226 - "/use will cause portage to ignore"
1227 - print "\tpackage.use in the profile and portage_confdir. You've been warned!"
1228 -
1229 - myf.write('PORTDIR="%s"\n' % self.settings['portdir'])
1230 - myf.write('DISTDIR="%s"\n' % self.settings['distdir'])
1231 - myf.write('PKGDIR="%s"\n' % self.settings['packagedir'])
1232 -
1233 - """ Setup the portage overlay """
1234 - if "portage_overlay" in self.settings:
1235 - myf.write('PORTDIR_OVERLAY="/usr/local/portage"\n')
1236 -
1237 - myf.close()
1238 - cmd("cp "+self.settings["chroot_path"]+"/etc/portage/make.conf "+\
1239 - self.settings["chroot_path"]+"/etc/portage/make.conf.catalyst",\
1240 - "Could not backup /etc/portage/make.conf",env=self.env)
1241 - touch(self.settings["autoresume_path"]+"chroot_setup")
1242 -
1243 - def fsscript(self):
1244 - if "AUTORESUME" in self.settings \
1245 - and os.path.exists(self.settings["autoresume_path"]+"fsscript"):
1246 - print "Resume point detected, skipping fsscript operation..."
1247 - else:
1248 - if "fsscript" in self.settings:
1249 - if os.path.exists(self.settings["controller_file"]):
1250 - cmd("/bin/bash "+self.settings["controller_file"]+\
1251 - " fsscript","fsscript script failed.",env=self.env)
1252 - touch(self.settings["autoresume_path"]+"fsscript")
1253 -
1254 - def rcupdate(self):
1255 - if "AUTORESUME" in self.settings \
1256 - and os.path.exists(self.settings["autoresume_path"]+"rcupdate"):
1257 - print "Resume point detected, skipping rcupdate operation..."
1258 - else:
1259 - if os.path.exists(self.settings["controller_file"]):
1260 - cmd("/bin/bash "+self.settings["controller_file"]+" rc-update",\
1261 - "rc-update script failed.",env=self.env)
1262 - touch(self.settings["autoresume_path"]+"rcupdate")
1263 -
1264 - def clean(self):
1265 - if "AUTORESUME" in self.settings \
1266 - and os.path.exists(self.settings["autoresume_path"]+"clean"):
1267 - print "Resume point detected, skipping clean operation..."
1268 - else:
1269 - for x in self.settings["cleanables"]:
1270 - print "Cleaning chroot: "+x+"... "
1271 - cmd("rm -rf "+self.settings["destpath"]+x,"Couldn't clean "+\
1272 - x,env=self.env)
1273 -
1274 - """ Put /etc/hosts back into place """
1275 - if os.path.exists(self.settings["chroot_path"]+"/etc/hosts.catalyst"):
1276 - cmd("mv -f "+self.settings["chroot_path"]+"/etc/hosts.catalyst "+\
1277 - self.settings["chroot_path"]+"/etc/hosts",\
1278 - "Could not replace /etc/hosts",env=self.env)
1279 -
1280 - """ Remove our overlay """
1281 - if os.path.exists(self.settings["chroot_path"] + self.settings["local_overlay"]):
1282 - cmd("rm -rf " + self.settings["chroot_path"] + self.settings["local_overlay"],
1283 - "Could not remove " + self.settings["local_overlay"], env=self.env)
1284 - cmd("sed -i '/^PORTDIR_OVERLAY/d' "+self.settings["chroot_path"]+\
1285 - "/etc/portage/make.conf",\
1286 - "Could not remove PORTDIR_OVERLAY from make.conf",env=self.env)
1287 -
1288 - """ Clean up old and obsoleted files in /etc """
1289 - if os.path.exists(self.settings["stage_path"]+"/etc"):
1290 - cmd("find "+self.settings["stage_path"]+\
1291 - "/etc -maxdepth 1 -name \"*-\" | xargs rm -f",\
1292 - "Could not remove stray files in /etc",env=self.env)
1293 -
1294 - if os.path.exists(self.settings["controller_file"]):
1295 - cmd("/bin/bash "+self.settings["controller_file"]+" clean",\
1296 - "clean script failed.",env=self.env)
1297 - touch(self.settings["autoresume_path"]+"clean")
1298 -
1299 - def empty(self):
1300 - if "AUTORESUME" in self.settings \
1301 - and os.path.exists(self.settings["autoresume_path"]+"empty"):
1302 - print "Resume point detected, skipping empty operation..."
1303 - else:
1304 - if self.settings["spec_prefix"]+"/empty" in self.settings:
1305 - if type(self.settings[self.settings["spec_prefix"]+\
1306 - "/empty"])==types.StringType:
1307 - self.settings[self.settings["spec_prefix"]+"/empty"]=\
1308 - self.settings[self.settings["spec_prefix"]+\
1309 - "/empty"].split()
1310 - for x in self.settings[self.settings["spec_prefix"]+"/empty"]:
1311 - myemp=self.settings["destpath"]+x
1312 - if not os.path.isdir(myemp) or os.path.islink(myemp):
1313 - print x,"not a directory or does not exist, skipping 'empty' operation."
1314 - continue
1315 - print "Emptying directory",x
1316 - """
1317 - stat the dir, delete the dir, recreate the dir and set
1318 - the proper perms and ownership
1319 - """
1320 - mystat=os.stat(myemp)
1321 - shutil.rmtree(myemp)
1322 - os.makedirs(myemp,0755)
1323 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
1324 - os.chmod(myemp,mystat[ST_MODE])
1325 - touch(self.settings["autoresume_path"]+"empty")
1326 -
1327 - def remove(self):
1328 - if "AUTORESUME" in self.settings \
1329 - and os.path.exists(self.settings["autoresume_path"]+"remove"):
1330 - print "Resume point detected, skipping remove operation..."
1331 - else:
1332 - if self.settings["spec_prefix"]+"/rm" in self.settings:
1333 - for x in self.settings[self.settings["spec_prefix"]+"/rm"]:
1334 - """
1335 - We're going to shell out for all these cleaning
1336 - operations, so we get easy glob handling.
1337 - """
1338 - print "livecd: removing "+x
1339 - os.system("rm -rf "+self.settings["chroot_path"]+x)
1340 - try:
1341 - if os.path.exists(self.settings["controller_file"]):
1342 - cmd("/bin/bash "+self.settings["controller_file"]+\
1343 - " clean","Clean failed.",env=self.env)
1344 - touch(self.settings["autoresume_path"]+"remove")
1345 - except:
1346 - self.unbind()
1347 - raise
1348 -
1349 - def preclean(self):
1350 - if "AUTORESUME" in self.settings \
1351 - and os.path.exists(self.settings["autoresume_path"]+"preclean"):
1352 - print "Resume point detected, skipping preclean operation..."
1353 - else:
1354 - try:
1355 - if os.path.exists(self.settings["controller_file"]):
1356 - cmd("/bin/bash "+self.settings["controller_file"]+\
1357 - " preclean","preclean script failed.",env=self.env)
1358 - touch(self.settings["autoresume_path"]+"preclean")
1359 -
1360 - except:
1361 - self.unbind()
1362 - raise CatalystError, "Build failed, could not execute preclean"
1363 -
1364 - def capture(self):
1365 - if "AUTORESUME" in self.settings \
1366 - and os.path.exists(self.settings["autoresume_path"]+"capture"):
1367 - print "Resume point detected, skipping capture operation..."
1368 - else:
1369 - """ Capture target in a tarball """
1370 - mypath=self.settings["target_path"].split("/")
1371 - """ Remove filename from path """
1372 - mypath=string.join(mypath[:-1],"/")
1373 -
1374 - """ Now make sure path exists """
1375 - if not os.path.exists(mypath):
1376 - os.makedirs(mypath)
1377 -
1378 - print "Creating stage tarball..."
1379 -
1380 - cmd("tar -I lbzip2 -cpf "+self.settings["target_path"]+" -C "+\
1381 - self.settings["stage_path"]+" .",\
1382 - "Couldn't create stage tarball",env=self.env)
1383 -
1384 - self.gen_contents_file(self.settings["target_path"])
1385 - self.gen_digest_file(self.settings["target_path"])
1386 -
1387 - touch(self.settings["autoresume_path"]+"capture")
1388 -
1389 - def run_local(self):
1390 - if "AUTORESUME" in self.settings \
1391 - and os.path.exists(self.settings["autoresume_path"]+"run_local"):
1392 - print "Resume point detected, skipping run_local operation..."
1393 - else:
1394 - try:
1395 - if os.path.exists(self.settings["controller_file"]):
1396 - cmd("/bin/bash "+self.settings["controller_file"]+" run",\
1397 - "run script failed.",env=self.env)
1398 - touch(self.settings["autoresume_path"]+"run_local")
1399 -
1400 - except CatalystError:
1401 - self.unbind()
1402 - raise CatalystError,"Stage build aborting due to error."
1403 -
1404 - def setup_environment(self):
1405 - """
1406 - Modify the current environment. This is an ugly hack that should be
1407 - fixed. We need this to use the os.system() call since we can't
1408 - specify our own environ
1409 - """
1410 - for x in self.settings.keys():
1411 - """ Sanitize var names by doing "s|/-.|_|g" """
1412 - varname="clst_"+string.replace(x,"/","_")
1413 - varname=string.replace(varname,"-","_")
1414 - varname=string.replace(varname,".","_")
1415 - if type(self.settings[x])==types.StringType:
1416 - """ Prefix to prevent namespace clashes """
1417 - #os.environ[varname]=self.settings[x]
1418 - self.env[varname]=self.settings[x]
1419 - elif type(self.settings[x])==types.ListType:
1420 - #os.environ[varname]=string.join(self.settings[x])
1421 - self.env[varname]=string.join(self.settings[x])
1422 - elif type(self.settings[x])==types.BooleanType:
1423 - if self.settings[x]:
1424 - self.env[varname]="true"
1425 - else:
1426 - self.env[varname]="false"
1427 - if "makeopts" in self.settings:
1428 - self.env["MAKEOPTS"]=self.settings["makeopts"]
1429 -
1430 - def run(self):
1431 - self.chroot_lock.write_lock()
1432 -
1433 - """ Kill any pids in the chroot "" """
1434 - self.kill_chroot_pids()
1435 -
1436 - """ Check for mounts right away and abort if we cannot unmount them """
1437 - self.mount_safety_check()
1438 -
1439 - if "CLEAR_AUTORESUME" in self.settings:
1440 - self.clear_autoresume()
1441 -
1442 - if "PURGETMPONLY" in self.settings:
1443 - self.purge()
1444 - return
1445 -
1446 - if "PURGEONLY" in self.settings:
1447 - self.purge()
1448 - return
1449 -
1450 - if "PURGE" in self.settings:
1451 - self.purge()
1452 -
1453 - for x in self.settings["action_sequence"]:
1454 - print "--- Running action sequence: "+x
1455 - sys.stdout.flush()
1456 - try:
1457 - apply(getattr(self,x))
1458 - except:
1459 - self.mount_safety_check()
1460 - raise
1461 -
1462 - self.chroot_lock.unlock()
1463 -
1464 - def unmerge(self):
1465 - if "AUTORESUME" in self.settings \
1466 - and os.path.exists(self.settings["autoresume_path"]+"unmerge"):
1467 - print "Resume point detected, skipping unmerge operation..."
1468 - else:
1469 - if self.settings["spec_prefix"]+"/unmerge" in self.settings:
1470 - if type(self.settings[self.settings["spec_prefix"]+\
1471 - "/unmerge"])==types.StringType:
1472 - self.settings[self.settings["spec_prefix"]+"/unmerge"]=\
1473 - [self.settings[self.settings["spec_prefix"]+"/unmerge"]]
1474 - myunmerge=\
1475 - self.settings[self.settings["spec_prefix"]+"/unmerge"][:]
1476 -
1477 - for x in range(0,len(myunmerge)):
1478 - """
1479 - Surround args with quotes for passing to bash, allows
1480 - things like "<" to remain intact
1481 - """
1482 - myunmerge[x]="'"+myunmerge[x]+"'"
1483 - myunmerge=string.join(myunmerge)
1484 -
1485 - """ Before cleaning, unmerge stuff """
1486 - try:
1487 - cmd("/bin/bash "+self.settings["controller_file"]+\
1488 - " unmerge "+ myunmerge,"Unmerge script failed.",\
1489 - env=self.env)
1490 - print "unmerge shell script"
1491 - except CatalystError:
1492 - self.unbind()
1493 - raise
1494 - touch(self.settings["autoresume_path"]+"unmerge")
1495 -
1496 - def target_setup(self):
1497 - if "AUTORESUME" in self.settings \
1498 - and os.path.exists(self.settings["autoresume_path"]+"target_setup"):
1499 - print "Resume point detected, skipping target_setup operation..."
1500 - else:
1501 - print "Setting up filesystems per filesystem type"
1502 - cmd("/bin/bash "+self.settings["controller_file"]+\
1503 - " target_image_setup "+ self.settings["target_path"],\
1504 - "target_image_setup script failed.",env=self.env)
1505 - touch(self.settings["autoresume_path"]+"target_setup")
1506 -
1507 - def setup_overlay(self):
1508 - if "AUTORESUME" in self.settings \
1509 - and os.path.exists(self.settings["autoresume_path"]+"setup_overlay"):
1510 - print "Resume point detected, skipping setup_overlay operation..."
1511 - else:
1512 - if self.settings["spec_prefix"]+"/overlay" in self.settings:
1513 - for x in self.settings[self.settings["spec_prefix"]+"/overlay"]:
1514 - if os.path.exists(x):
1515 - cmd("rsync -a "+x+"/ "+\
1516 - self.settings["target_path"],\
1517 - self.settings["spec_prefix"]+"overlay: "+x+\
1518 - " copy failed.",env=self.env)
1519 - touch(self.settings["autoresume_path"]+"setup_overlay")
1520 -
1521 - def create_iso(self):
1522 - if "AUTORESUME" in self.settings \
1523 - and os.path.exists(self.settings["autoresume_path"]+"create_iso"):
1524 - print "Resume point detected, skipping create_iso operation..."
1525 - else:
1526 - """ Create the ISO """
1527 - if "iso" in self.settings:
1528 - cmd("/bin/bash "+self.settings["controller_file"]+" iso "+\
1529 - self.settings["iso"],"ISO creation script failed.",\
1530 - env=self.env)
1531 - self.gen_contents_file(self.settings["iso"])
1532 - self.gen_digest_file(self.settings["iso"])
1533 - touch(self.settings["autoresume_path"]+"create_iso")
1534 - else:
1535 - print "WARNING: livecd/iso was not defined."
1536 - print "An ISO Image will not be created."
1537 -
1538 - def build_packages(self):
1539 - if "AUTORESUME" in self.settings \
1540 - and os.path.exists(self.settings["autoresume_path"]+\
1541 - "build_packages"):
1542 - print "Resume point detected, skipping build_packages operation..."
1543 - else:
1544 - if self.settings["spec_prefix"]+"/packages" in self.settings:
1545 - if "AUTORESUME" in self.settings \
1546 - and os.path.exists(self.settings["autoresume_path"]+\
1547 - "build_packages"):
1548 - print "Resume point detected, skipping build_packages operation..."
1549 - else:
1550 - mypack=\
1551 - list_bashify(self.settings[self.settings["spec_prefix"]\
1552 - +"/packages"])
1553 - try:
1554 - cmd("/bin/bash "+self.settings["controller_file"]+\
1555 - " build_packages "+mypack,\
1556 - "Error in attempt to build packages",env=self.env)
1557 - touch(self.settings["autoresume_path"]+"build_packages")
1558 - except CatalystError:
1559 - self.unbind()
1560 - raise CatalystError,self.settings["spec_prefix"]+\
1561 - "build aborting due to error."
1562 -
1563 - def build_kernel(self):
1564 - "Build all configured kernels"
1565 - if "AUTORESUME" in self.settings \
1566 - and os.path.exists(self.settings["autoresume_path"]+"build_kernel"):
1567 - print "Resume point detected, skipping build_kernel operation..."
1568 - else:
1569 - if "boot/kernel" in self.settings:
1570 - try:
1571 - mynames=self.settings["boot/kernel"]
1572 - if type(mynames)==types.StringType:
1573 - mynames=[mynames]
1574 - """
1575 - Execute the script that sets up the kernel build environment
1576 - """
1577 - cmd("/bin/bash "+self.settings["controller_file"]+\
1578 - " pre-kmerge ","Runscript pre-kmerge failed",\
1579 - env=self.env)
1580 - for kname in mynames:
1581 - self._build_kernel(kname=kname)
1582 - touch(self.settings["autoresume_path"]+"build_kernel")
1583 - except CatalystError:
1584 - self.unbind()
1585 - raise CatalystError,\
1586 - "build aborting due to kernel build error."
1587 -
1588 - def _build_kernel(self, kname):
1589 - "Build a single configured kernel by name"
1590 - if "AUTORESUME" in self.settings \
1591 - and os.path.exists(self.settings["autoresume_path"]\
1592 - +"build_kernel_"+kname):
1593 - print "Resume point detected, skipping build_kernel for "+kname+" operation..."
1594 - return
1595 - self._copy_kernel_config(kname=kname)
1596 -
1597 - """
1598 - If we need to pass special options to the bootloader
1599 - for this kernel put them into the environment
1600 - """
1601 - if "boot/kernel/"+kname+"/kernelopts" in self.settings:
1602 - myopts=self.settings["boot/kernel/"+kname+\
1603 - "/kernelopts"]
1604 -
1605 - if type(myopts) != types.StringType:
1606 - myopts = string.join(myopts)
1607 - self.env[kname+"_kernelopts"]=myopts
1608 -
1609 - else:
1610 - self.env[kname+"_kernelopts"]=""
1611 -
1612 - if "boot/kernel/"+kname+"/extraversion" not in self.settings:
1613 - self.settings["boot/kernel/"+kname+\
1614 - "/extraversion"]=""
1615 -
1616 - self.env["clst_kextraversion"]=\
1617 - self.settings["boot/kernel/"+kname+\
1618 - "/extraversion"]
1619 -
1620 - self._copy_initramfs_overlay(kname=kname)
1621 -
1622 - """ Execute the script that builds the kernel """
1623 - cmd("/bin/bash "+self.settings["controller_file"]+\
1624 - " kernel "+kname,\
1625 - "Runscript kernel build failed",env=self.env)
1626 -
1627 - if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings:
1628 - if os.path.exists(self.settings["chroot_path"]+\
1629 - "/tmp/initramfs_overlay/"):
1630 - print "Cleaning up temporary overlay dir"
1631 - cmd("rm -R "+self.settings["chroot_path"]+\
1632 - "/tmp/initramfs_overlay/",env=self.env)
1633 -
1634 - touch(self.settings["autoresume_path"]+\
1635 - "build_kernel_"+kname)
1636 -
1637 - """
1638 - Execute the script that cleans up the kernel build
1639 - environment
1640 - """
1641 - cmd("/bin/bash "+self.settings["controller_file"]+\
1642 - " post-kmerge ",
1643 - "Runscript post-kmerge failed",env=self.env)
1644 -
1645 - def _copy_kernel_config(self, kname):
1646 - if "boot/kernel/"+kname+"/config" in self.settings:
1647 - if not os.path.exists(self.settings["boot/kernel/"+kname+"/config"]):
1648 - self.unbind()
1649 - raise CatalystError,\
1650 - "Can't find kernel config: "+\
1651 - self.settings["boot/kernel/"+kname+\
1652 - "/config"]
1653 -
1654 - try:
1655 - cmd("cp "+self.settings["boot/kernel/"+kname+\
1656 - "/config"]+" "+\
1657 - self.settings["chroot_path"]+"/var/tmp/"+\
1658 - kname+".config",\
1659 - "Couldn't copy kernel config: "+\
1660 - self.settings["boot/kernel/"+kname+\
1661 - "/config"],env=self.env)
1662 -
1663 - except CatalystError:
1664 - self.unbind()
1665 -
1666 - def _copy_initramfs_overlay(self, kname):
1667 - if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings:
1668 - if os.path.exists(self.settings["boot/kernel/"+\
1669 - kname+"/initramfs_overlay"]):
1670 - print "Copying initramfs_overlay dir "+\
1671 - self.settings["boot/kernel/"+kname+\
1672 - "/initramfs_overlay"]
1673 -
1674 - cmd("mkdir -p "+\
1675 - self.settings["chroot_path"]+\
1676 - "/tmp/initramfs_overlay/"+\
1677 - self.settings["boot/kernel/"+kname+\
1678 - "/initramfs_overlay"],env=self.env)
1679 -
1680 - cmd("cp -R "+self.settings["boot/kernel/"+\
1681 - kname+"/initramfs_overlay"]+"/* "+\
1682 - self.settings["chroot_path"]+\
1683 - "/tmp/initramfs_overlay/"+\
1684 - self.settings["boot/kernel/"+kname+\
1685 - "/initramfs_overlay"],env=self.env)
1686 -
1687 - def bootloader(self):
1688 - if "AUTORESUME" in self.settings \
1689 - and os.path.exists(self.settings["autoresume_path"]+"bootloader"):
1690 - print "Resume point detected, skipping bootloader operation..."
1691 - else:
1692 - try:
1693 - cmd("/bin/bash "+self.settings["controller_file"]+\
1694 - " bootloader " + self.settings["target_path"],\
1695 - "Bootloader script failed.",env=self.env)
1696 - touch(self.settings["autoresume_path"]+"bootloader")
1697 - except CatalystError:
1698 - self.unbind()
1699 - raise CatalystError,"Script aborting due to error."
1700 -
1701 - def livecd_update(self):
1702 - if "AUTORESUME" in self.settings \
1703 - and os.path.exists(self.settings["autoresume_path"]+\
1704 - "livecd_update"):
1705 - print "Resume point detected, skipping build_packages operation..."
1706 - else:
1707 - try:
1708 - cmd("/bin/bash "+self.settings["controller_file"]+\
1709 - " livecd-update","livecd-update failed.",env=self.env)
1710 - touch(self.settings["autoresume_path"]+"livecd_update")
1711 -
1712 - except CatalystError:
1713 - self.unbind()
1714 - raise CatalystError,"build aborting due to livecd_update error."
1715 -
1716 - def clear_chroot(self):
1717 - myemp=self.settings["chroot_path"]
1718 - if os.path.isdir(myemp):
1719 - print "Emptying directory",myemp
1720 - """
1721 - stat the dir, delete the dir, recreate the dir and set
1722 - the proper perms and ownership
1723 - """
1724 - mystat=os.stat(myemp)
1725 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
1726 - """ There's no easy way to change flags recursively in python """
1727 - if os.uname()[0] == "FreeBSD":
1728 - os.system("chflags -R noschg "+myemp)
1729 - shutil.rmtree(myemp)
1730 - os.makedirs(myemp,0755)
1731 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
1732 - os.chmod(myemp,mystat[ST_MODE])
1733 -
1734 - def clear_packages(self):
1735 - if "PKGCACHE" in self.settings:
1736 - print "purging the pkgcache ..."
1737 -
1738 - myemp=self.settings["pkgcache_path"]
1739 - if os.path.isdir(myemp):
1740 - print "Emptying directory",myemp
1741 - """
1742 - stat the dir, delete the dir, recreate the dir and set
1743 - the proper perms and ownership
1744 - """
1745 - mystat=os.stat(myemp)
1746 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
1747 - shutil.rmtree(myemp)
1748 - os.makedirs(myemp,0755)
1749 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
1750 - os.chmod(myemp,mystat[ST_MODE])
1751 -
1752 - def clear_kerncache(self):
1753 - if "KERNCACHE" in self.settings:
1754 - print "purging the kerncache ..."
1755 -
1756 - myemp=self.settings["kerncache_path"]
1757 - if os.path.isdir(myemp):
1758 - print "Emptying directory",myemp
1759 - """
1760 - stat the dir, delete the dir, recreate the dir and set
1761 - the proper perms and ownership
1762 - """
1763 - mystat=os.stat(myemp)
1764 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
1765 - shutil.rmtree(myemp)
1766 - os.makedirs(myemp,0755)
1767 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
1768 - os.chmod(myemp,mystat[ST_MODE])
1769 -
1770 - def clear_autoresume(self):
1771 - """ Clean resume points since they are no longer needed """
1772 - if "AUTORESUME" in self.settings:
1773 - print "Removing AutoResume Points: ..."
1774 - myemp=self.settings["autoresume_path"]
1775 - if os.path.isdir(myemp):
1776 - if "AUTORESUME" in self.settings:
1777 - print "Emptying directory",myemp
1778 - """
1779 - stat the dir, delete the dir, recreate the dir and set
1780 - the proper perms and ownership
1781 - """
1782 - mystat=os.stat(myemp)
1783 - if os.uname()[0] == "FreeBSD":
1784 - cmd("chflags -R noschg "+myemp,\
1785 - "Could not remove immutable flag for file "\
1786 - +myemp)
1787 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env-self.env)
1788 - shutil.rmtree(myemp)
1789 - os.makedirs(myemp,0755)
1790 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
1791 - os.chmod(myemp,mystat[ST_MODE])
1792 -
1793 - def gen_contents_file(self,file):
1794 - if os.path.exists(file+".CONTENTS"):
1795 - os.remove(file+".CONTENTS")
1796 - if "contents" in self.settings:
1797 - if os.path.exists(file):
1798 - myf=open(file+".CONTENTS","w")
1799 - keys={}
1800 - for i in self.settings["contents"].split():
1801 - keys[i]=1
1802 - array=keys.keys()
1803 - array.sort()
1804 - for j in array:
1805 - contents=generate_contents(file,contents_function=j,\
1806 - verbose="VERBOSE" in self.settings)
1807 - if contents:
1808 - myf.write(contents)
1809 - myf.close()
1810 -
1811 - def gen_digest_file(self,file):
1812 - if os.path.exists(file+".DIGESTS"):
1813 - os.remove(file+".DIGESTS")
1814 - if "digests" in self.settings:
1815 - if os.path.exists(file):
1816 - myf=open(file+".DIGESTS","w")
1817 - keys={}
1818 - for i in self.settings["digests"].split():
1819 - keys[i]=1
1820 - array=keys.keys()
1821 - array.sort()
1822 - for f in [file, file+'.CONTENTS']:
1823 - if os.path.exists(f):
1824 - if "all" in array:
1825 - for k in hash_map.keys():
1826 - hash=generate_hash(f,hash_function=k,verbose=\
1827 - "VERBOSE" in self.settings)
1828 - myf.write(hash)
1829 - else:
1830 - for j in array:
1831 - hash=generate_hash(f,hash_function=j,verbose=\
1832 - "VERBOSE" in self.settings)
1833 - myf.write(hash)
1834 - myf.close()
1835 -
1836 - def purge(self):
1837 - countdown(10,"Purging Caches ...")
1838 - if any(k in self.settings for k in ("PURGE","PURGEONLY","PURGETMPONLY")):
1839 - print "clearing autoresume ..."
1840 - self.clear_autoresume()
1841 -
1842 - print "clearing chroot ..."
1843 - self.clear_chroot()
1844 -
1845 - if "PURGETMPONLY" not in self.settings:
1846 - print "clearing package cache ..."
1847 - self.clear_packages()
1848 -
1849 - print "clearing kerncache ..."
1850 - self.clear_kerncache()
1851 -
1852 -# vim: ts=4 sw=4 sta et sts=4 ai
1853 diff --git a/catalyst/modules/generic_target.py b/catalyst/modules/generic_target.py
1854 deleted file mode 100644
1855 index de51994..0000000
1856 --- a/catalyst/modules/generic_target.py
1857 +++ /dev/null
1858 @@ -1,11 +0,0 @@
1859 -from catalyst.support import *
1860 -
1861 -class generic_target:
1862 - """
1863 - The toplevel class for generic_stage_target. This is about as generic as we get.
1864 - """
1865 - def __init__(self,myspec,addlargs):
1866 - addl_arg_parse(myspec,addlargs,self.required_values,self.valid_values)
1867 - self.settings=myspec
1868 - self.env={}
1869 - self.env["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin"
1870 diff --git a/catalyst/modules/grp_target.py b/catalyst/modules/grp_target.py
1871 deleted file mode 100644
1872 index 8e70042..0000000
1873 --- a/catalyst/modules/grp_target.py
1874 +++ /dev/null
1875 @@ -1,118 +0,0 @@
1876 -"""
1877 -Gentoo Reference Platform (GRP) target
1878 -"""
1879 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
1880 -
1881 -import os,types,glob
1882 -from catalyst.support import *
1883 -from generic_stage_target import *
1884 -
1885 -class grp_target(generic_stage_target):
1886 - """
1887 - The builder class for GRP (Gentoo Reference Platform) builds.
1888 - """
1889 - def __init__(self,spec,addlargs):
1890 - self.required_values=["version_stamp","target","subarch",\
1891 - "rel_type","profile","snapshot","source_subpath"]
1892 -
1893 - self.valid_values=self.required_values[:]
1894 - self.valid_values.extend(["grp/use"])
1895 - if "grp" not in addlargs:
1896 - raise CatalystError,"Required value \"grp\" not specified in spec."
1897 -
1898 - self.required_values.extend(["grp"])
1899 - if type(addlargs["grp"])==types.StringType:
1900 - addlargs["grp"]=[addlargs["grp"]]
1901 -
1902 - if "grp/use" in addlargs:
1903 - if type(addlargs["grp/use"])==types.StringType:
1904 - addlargs["grp/use"]=[addlargs["grp/use"]]
1905 -
1906 - for x in addlargs["grp"]:
1907 - self.required_values.append("grp/"+x+"/packages")
1908 - self.required_values.append("grp/"+x+"/type")
1909 -
1910 - generic_stage_target.__init__(self,spec,addlargs)
1911 -
1912 - def set_target_path(self):
1913 - self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
1914 - if "AUTORESUME" in self.settings \
1915 - and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
1916 - print "Resume point detected, skipping target path setup operation..."
1917 - else:
1918 - # first clean up any existing target stuff
1919 - #if os.path.isdir(self.settings["target_path"]):
1920 - #cmd("rm -rf "+self.settings["target_path"],
1921 - #"Could not remove existing directory: "+self.settings["target_path"],env=self.env)
1922 - if not os.path.exists(self.settings["target_path"]):
1923 - os.makedirs(self.settings["target_path"])
1924 -
1925 - touch(self.settings["autoresume_path"]+"setup_target_path")
1926 -
1927 - def run_local(self):
1928 - for pkgset in self.settings["grp"]:
1929 - # example call: "grp.sh run pkgset cd1 xmms vim sys-apps/gleep"
1930 - mypackages=list_bashify(self.settings["grp/"+pkgset+"/packages"])
1931 - try:
1932 - cmd("/bin/bash "+self.settings["controller_file"]+" run "+self.settings["grp/"+pkgset+"/type"]\
1933 - +" "+pkgset+" "+mypackages,env=self.env)
1934 -
1935 - except CatalystError:
1936 - self.unbind()
1937 - raise CatalystError,"GRP build aborting due to error."
1938 -
1939 - def set_use(self):
1940 - generic_stage_target.set_use(self)
1941 - if "BINDIST" in self.settings:
1942 - if "use" in self.settings:
1943 - self.settings["use"].append("bindist")
1944 - else:
1945 - self.settings["use"]=["bindist"]
1946 -
1947 - def set_mounts(self):
1948 - self.mounts.append("/tmp/grp")
1949 - self.mountmap["/tmp/grp"]=self.settings["target_path"]
1950 -
1951 - def generate_digests(self):
1952 - for pkgset in self.settings["grp"]:
1953 - if self.settings["grp/"+pkgset+"/type"] == "pkgset":
1954 - destdir=normpath(self.settings["target_path"]+"/"+pkgset+"/All")
1955 - print "Digesting files in the pkgset....."
1956 - digests=glob.glob(destdir+'/*.DIGESTS')
1957 - for i in digests:
1958 - if os.path.exists(i):
1959 - os.remove(i)
1960 -
1961 - files=os.listdir(destdir)
1962 - #ignore files starting with '.' using list comprehension
1963 - files=[filename for filename in files if filename[0] != '.']
1964 - for i in files:
1965 - if os.path.isfile(normpath(destdir+"/"+i)):
1966 - self.gen_contents_file(normpath(destdir+"/"+i))
1967 - self.gen_digest_file(normpath(destdir+"/"+i))
1968 - else:
1969 - destdir=normpath(self.settings["target_path"]+"/"+pkgset)
1970 - print "Digesting files in the srcset....."
1971 -
1972 - digests=glob.glob(destdir+'/*.DIGESTS')
1973 - for i in digests:
1974 - if os.path.exists(i):
1975 - os.remove(i)
1976 -
1977 - files=os.listdir(destdir)
1978 - #ignore files starting with '.' using list comprehension
1979 - files=[filename for filename in files if filename[0] != '.']
1980 - for i in files:
1981 - if os.path.isfile(normpath(destdir+"/"+i)):
1982 - #self.gen_contents_file(normpath(destdir+"/"+i))
1983 - self.gen_digest_file(normpath(destdir+"/"+i))
1984 -
1985 - def set_action_sequence(self):
1986 - self.settings["action_sequence"]=["unpack","unpack_snapshot",\
1987 - "config_profile_link","setup_confdir","portage_overlay","bind","chroot_setup",\
1988 - "setup_environment","run_local","unbind",\
1989 - "generate_digests","clear_autoresume"]
1990 -
1991 -def register(foo):
1992 - foo.update({"grp":grp_target})
1993 - return foo
1994 diff --git a/catalyst/modules/livecd_stage1_target.py b/catalyst/modules/livecd_stage1_target.py
1995 deleted file mode 100644
1996 index ac846ec..0000000
1997 --- a/catalyst/modules/livecd_stage1_target.py
1998 +++ /dev/null
1999 @@ -1,75 +0,0 @@
2000 -"""
2001 -LiveCD stage1 target
2002 -"""
2003 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2004 -
2005 -from catalyst.support import *
2006 -from generic_stage_target import *
2007 -
2008 -class livecd_stage1_target(generic_stage_target):
2009 - """
2010 - Builder class for LiveCD stage1.
2011 - """
2012 - def __init__(self,spec,addlargs):
2013 - self.required_values=["livecd/packages"]
2014 - self.valid_values=self.required_values[:]
2015 -
2016 - self.valid_values.extend(["livecd/use"])
2017 - generic_stage_target.__init__(self,spec,addlargs)
2018 -
2019 - def set_action_sequence(self):
2020 - self.settings["action_sequence"]=["unpack","unpack_snapshot",\
2021 - "config_profile_link","setup_confdir","portage_overlay",\
2022 - "bind","chroot_setup","setup_environment","build_packages",\
2023 - "unbind", "clean","clear_autoresume"]
2024 -
2025 - def set_target_path(self):
2026 - self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"])
2027 - if "AUTORESUME" in self.settings \
2028 - and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
2029 - print "Resume point detected, skipping target path setup operation..."
2030 - else:
2031 - # first clean up any existing target stuff
2032 - if os.path.exists(self.settings["target_path"]):
2033 - cmd("rm -rf "+self.settings["target_path"],\
2034 - "Could not remove existing directory: "+self.settings["target_path"],env=self.env)
2035 - touch(self.settings["autoresume_path"]+"setup_target_path")
2036 -
2037 - if not os.path.exists(self.settings["target_path"]):
2038 - os.makedirs(self.settings["target_path"])
2039 -
2040 - def set_target_path(self):
2041 - pass
2042 -
2043 - def set_spec_prefix(self):
2044 - self.settings["spec_prefix"]="livecd"
2045 -
2046 - def set_use(self):
2047 - generic_stage_target.set_use(self)
2048 - if "use" in self.settings:
2049 - self.settings["use"].append("livecd")
2050 - if "BINDIST" in self.settings:
2051 - self.settings["use"].append("bindist")
2052 - else:
2053 - self.settings["use"]=["livecd"]
2054 - if "BINDIST" in self.settings:
2055 - self.settings["use"].append("bindist")
2056 -
2057 - def set_packages(self):
2058 - generic_stage_target.set_packages(self)
2059 - if self.settings["spec_prefix"]+"/packages" in self.settings:
2060 - if type(self.settings[self.settings["spec_prefix"]+"/packages"]) == types.StringType:
2061 - self.settings[self.settings["spec_prefix"]+"/packages"] = \
2062 - self.settings[self.settings["spec_prefix"]+"/packages"].split()
2063 - self.settings[self.settings["spec_prefix"]+"/packages"].append("app-misc/livecd-tools")
2064 -
2065 - def set_pkgcache_path(self):
2066 - if "pkgcache_path" in self.settings:
2067 - if type(self.settings["pkgcache_path"]) != types.StringType:
2068 - self.settings["pkgcache_path"]=normpath(string.join(self.settings["pkgcache_path"]))
2069 - else:
2070 - generic_stage_target.set_pkgcache_path(self)
2071 -
2072 -def register(foo):
2073 - foo.update({"livecd-stage1":livecd_stage1_target})
2074 - return foo
2075 diff --git a/catalyst/modules/livecd_stage2_target.py b/catalyst/modules/livecd_stage2_target.py
2076 deleted file mode 100644
2077 index 1bfd820..0000000
2078 --- a/catalyst/modules/livecd_stage2_target.py
2079 +++ /dev/null
2080 @@ -1,146 +0,0 @@
2081 -"""
2082 -LiveCD stage2 target, builds upon previous LiveCD stage1 tarball
2083 -"""
2084 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2085 -
2086 -import os,string,types,stat,shutil
2087 -from catalyst.support import *
2088 -from generic_stage_target import *
2089 -
2090 -class livecd_stage2_target(generic_stage_target):
2091 - """
2092 - Builder class for a LiveCD stage2 build.
2093 - """
2094 - def __init__(self,spec,addlargs):
2095 - self.required_values=["boot/kernel"]
2096 -
2097 - self.valid_values=[]
2098 -
2099 - self.valid_values.extend(self.required_values)
2100 - self.valid_values.extend(["livecd/cdtar","livecd/empty","livecd/rm",\
2101 - "livecd/unmerge","livecd/iso","livecd/gk_mainargs","livecd/type",\
2102 - "livecd/readme","livecd/motd","livecd/overlay",\
2103 - "livecd/modblacklist","livecd/splash_theme","livecd/rcadd",\
2104 - "livecd/rcdel","livecd/fsscript","livecd/xinitrc",\
2105 - "livecd/root_overlay","livecd/users","portage_overlay",\
2106 - "livecd/fstype","livecd/fsops","livecd/linuxrc","livecd/bootargs",\
2107 - "gamecd/conf","livecd/xdm","livecd/xsession","livecd/volid"])
2108 -
2109 - generic_stage_target.__init__(self,spec,addlargs)
2110 - if "livecd/type" not in self.settings:
2111 - self.settings["livecd/type"] = "generic-livecd"
2112 -
2113 - file_locate(self.settings, ["cdtar","controller_file"])
2114 -
2115 - def set_source_path(self):
2116 - self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2")
2117 - if os.path.isfile(self.settings["source_path"]):
2118 - self.settings["source_path_hash"]=generate_hash(self.settings["source_path"])
2119 - else:
2120 - self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/")
2121 - if not os.path.exists(self.settings["source_path"]):
2122 - raise CatalystError,"Source Path: "+self.settings["source_path"]+" does not exist."
2123 -
2124 - def set_spec_prefix(self):
2125 - self.settings["spec_prefix"]="livecd"
2126 -
2127 - def set_target_path(self):
2128 - self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
2129 - if "AUTORESUME" in self.settings \
2130 - and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
2131 - print "Resume point detected, skipping target path setup operation..."
2132 - else:
2133 - # first clean up any existing target stuff
2134 - if os.path.isdir(self.settings["target_path"]):
2135 - cmd("rm -rf "+self.settings["target_path"],
2136 - "Could not remove existing directory: "+self.settings["target_path"],env=self.env)
2137 - touch(self.settings["autoresume_path"]+"setup_target_path")
2138 - if not os.path.exists(self.settings["target_path"]):
2139 - os.makedirs(self.settings["target_path"])
2140 -
2141 - def run_local(self):
2142 - # what modules do we want to blacklist?
2143 - if "livecd/modblacklist" in self.settings:
2144 - try:
2145 - myf=open(self.settings["chroot_path"]+"/etc/modprobe.d/blacklist.conf","a")
2146 - except:
2147 - self.unbind()
2148 - raise CatalystError,"Couldn't open "+self.settings["chroot_path"]+"/etc/modprobe.d/blacklist.conf."
2149 -
2150 - myf.write("\n#Added by Catalyst:")
2151 - # workaround until config.py is using configparser
2152 - if isinstance(self.settings["livecd/modblacklist"], str):
2153 - self.settings["livecd/modblacklist"] = self.settings["livecd/modblacklist"].split()
2154 - for x in self.settings["livecd/modblacklist"]:
2155 - myf.write("\nblacklist "+x)
2156 - myf.close()
2157 -
2158 - def unpack(self):
2159 - unpack=True
2160 - display_msg=None
2161 -
2162 - clst_unpack_hash=read_from_clst(self.settings["autoresume_path"]+"unpack")
2163 -
2164 - if os.path.isdir(self.settings["source_path"]):
2165 - unpack_cmd="rsync -a --delete "+self.settings["source_path"]+" "+self.settings["chroot_path"]
2166 - display_msg="\nStarting rsync from "+self.settings["source_path"]+"\nto "+\
2167 - self.settings["chroot_path"]+" (This may take some time) ...\n"
2168 - error_msg="Rsync of "+self.settings["source_path"]+" to "+self.settings["chroot_path"]+" failed."
2169 - invalid_snapshot=False
2170 -
2171 - if "AUTORESUME" in self.settings:
2172 - if os.path.isdir(self.settings["source_path"]) and \
2173 - os.path.exists(self.settings["autoresume_path"]+"unpack"):
2174 - print "Resume point detected, skipping unpack operation..."
2175 - unpack=False
2176 - elif "source_path_hash" in self.settings:
2177 - if self.settings["source_path_hash"] != clst_unpack_hash:
2178 - invalid_snapshot=True
2179 -
2180 - if unpack:
2181 - self.mount_safety_check()
2182 - if invalid_snapshot:
2183 - print "No Valid Resume point detected, cleaning up ..."
2184 - #os.remove(self.settings["autoresume_path"]+"dir_setup")
2185 - self.clear_autoresume()
2186 - self.clear_chroot()
2187 - #self.dir_setup()
2188 -
2189 - if not os.path.exists(self.settings["chroot_path"]):
2190 - os.makedirs(self.settings["chroot_path"])
2191 -
2192 - if not os.path.exists(self.settings["chroot_path"]+"/tmp"):
2193 - os.makedirs(self.settings["chroot_path"]+"/tmp",1777)
2194 -
2195 - if "PKGCACHE" in self.settings:
2196 - if not os.path.exists(self.settings["pkgcache_path"]):
2197 - os.makedirs(self.settings["pkgcache_path"],0755)
2198 -
2199 - if not display_msg:
2200 - raise CatalystError,"Could not find appropriate source. Please check the 'source_subpath' setting in the spec file."
2201 -
2202 - print display_msg
2203 - cmd(unpack_cmd,error_msg,env=self.env)
2204 -
2205 - if "source_path_hash" in self.settings:
2206 - myf=open(self.settings["autoresume_path"]+"unpack","w")
2207 - myf.write(self.settings["source_path_hash"])
2208 - myf.close()
2209 - else:
2210 - touch(self.settings["autoresume_path"]+"unpack")
2211 -
2212 - def set_action_sequence(self):
2213 - self.settings["action_sequence"]=["unpack","unpack_snapshot",\
2214 - "config_profile_link","setup_confdir","portage_overlay",\
2215 - "bind","chroot_setup","setup_environment","run_local",\
2216 - "build_kernel"]
2217 - if "FETCH" not in self.settings:
2218 - self.settings["action_sequence"] += ["bootloader","preclean",\
2219 - "livecd_update","root_overlay","fsscript","rcupdate","unmerge",\
2220 - "unbind","remove","empty","target_setup",\
2221 - "setup_overlay","create_iso"]
2222 - self.settings["action_sequence"].append("clear_autoresume")
2223 -
2224 -def register(foo):
2225 - foo.update({"livecd-stage2":livecd_stage2_target})
2226 - return foo
2227 diff --git a/catalyst/modules/netboot2_target.py b/catalyst/modules/netboot2_target.py
2228 deleted file mode 100644
2229 index 2b3cd20..0000000
2230 --- a/catalyst/modules/netboot2_target.py
2231 +++ /dev/null
2232 @@ -1,166 +0,0 @@
2233 -"""
2234 -netboot target, version 2
2235 -"""
2236 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2237 -
2238 -import os,string,types
2239 -from catalyst.support import *
2240 -from generic_stage_target import *
2241 -
2242 -class netboot2_target(generic_stage_target):
2243 - """
2244 - Builder class for a netboot build, version 2
2245 - """
2246 - def __init__(self,spec,addlargs):
2247 - self.required_values=[
2248 - "boot/kernel"
2249 - ]
2250 - self.valid_values=self.required_values[:]
2251 - self.valid_values.extend([
2252 - "netboot2/packages",
2253 - "netboot2/use",
2254 - "netboot2/extra_files",
2255 - "netboot2/overlay",
2256 - "netboot2/busybox_config",
2257 - "netboot2/root_overlay",
2258 - "netboot2/linuxrc"
2259 - ])
2260 -
2261 - try:
2262 - if "netboot2/packages" in addlargs:
2263 - if type(addlargs["netboot2/packages"]) == types.StringType:
2264 - loopy=[addlargs["netboot2/packages"]]
2265 - else:
2266 - loopy=addlargs["netboot2/packages"]
2267 -
2268 - for x in loopy:
2269 - self.valid_values.append("netboot2/packages/"+x+"/files")
2270 - except:
2271 - raise CatalystError,"configuration error in netboot2/packages."
2272 -
2273 - generic_stage_target.__init__(self,spec,addlargs)
2274 - self.set_build_kernel_vars()
2275 - self.settings["merge_path"]=normpath("/tmp/image/")
2276 -
2277 - def set_target_path(self):
2278 - self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+\
2279 - self.settings["target_subpath"]+"/")
2280 - if "AUTORESUME" in self.settings \
2281 - and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
2282 - print "Resume point detected, skipping target path setup operation..."
2283 - else:
2284 - # first clean up any existing target stuff
2285 - if os.path.isfile(self.settings["target_path"]):
2286 - cmd("rm -f "+self.settings["target_path"], \
2287 - "Could not remove existing file: "+self.settings["target_path"],env=self.env)
2288 - touch(self.settings["autoresume_path"]+"setup_target_path")
2289 -
2290 - if not os.path.exists(self.settings["storedir"]+"/builds/"):
2291 - os.makedirs(self.settings["storedir"]+"/builds/")
2292 -
2293 - def copy_files_to_image(self):
2294 - # copies specific files from the buildroot to merge_path
2295 - myfiles=[]
2296 -
2297 - # check for autoresume point
2298 - if "AUTORESUME" in self.settings \
2299 - and os.path.exists(self.settings["autoresume_path"]+"copy_files_to_image"):
2300 - print "Resume point detected, skipping target path setup operation..."
2301 - else:
2302 - if "netboot2/packages" in self.settings:
2303 - if type(self.settings["netboot2/packages"]) == types.StringType:
2304 - loopy=[self.settings["netboot2/packages"]]
2305 - else:
2306 - loopy=self.settings["netboot2/packages"]
2307 -
2308 - for x in loopy:
2309 - if "netboot2/packages/"+x+"/files" in self.settings:
2310 - if type(self.settings["netboot2/packages/"+x+"/files"]) == types.ListType:
2311 - myfiles.extend(self.settings["netboot2/packages/"+x+"/files"])
2312 - else:
2313 - myfiles.append(self.settings["netboot2/packages/"+x+"/files"])
2314 -
2315 - if "netboot2/extra_files" in self.settings:
2316 - if type(self.settings["netboot2/extra_files"]) == types.ListType:
2317 - myfiles.extend(self.settings["netboot2/extra_files"])
2318 - else:
2319 - myfiles.append(self.settings["netboot2/extra_files"])
2320 -
2321 - try:
2322 - cmd("/bin/bash "+self.settings["controller_file"]+\
2323 - " image " + list_bashify(myfiles),env=self.env)
2324 - except CatalystError:
2325 - self.unbind()
2326 - raise CatalystError,"Failed to copy files to image!"
2327 -
2328 - touch(self.settings["autoresume_path"]+"copy_files_to_image")
2329 -
2330 - def setup_overlay(self):
2331 - if "AUTORESUME" in self.settings \
2332 - and os.path.exists(self.settings["autoresume_path"]+"setup_overlay"):
2333 - print "Resume point detected, skipping setup_overlay operation..."
2334 - else:
2335 - if "netboot2/overlay" in self.settings:
2336 - for x in self.settings["netboot2/overlay"]:
2337 - if os.path.exists(x):
2338 - cmd("rsync -a "+x+"/ "+\
2339 - self.settings["chroot_path"] + self.settings["merge_path"], "netboot2/overlay: "+x+" copy failed.",env=self.env)
2340 - touch(self.settings["autoresume_path"]+"setup_overlay")
2341 -
2342 - def move_kernels(self):
2343 - # we're done, move the kernels to builds/*
2344 - # no auto resume here as we always want the
2345 - # freshest images moved
2346 - try:
2347 - cmd("/bin/bash "+self.settings["controller_file"]+\
2348 - " final",env=self.env)
2349 - print ">>> Netboot Build Finished!"
2350 - except CatalystError:
2351 - self.unbind()
2352 - raise CatalystError,"Failed to move kernel images!"
2353 -
2354 - def remove(self):
2355 - if "AUTORESUME" in self.settings \
2356 - and os.path.exists(self.settings["autoresume_path"]+"remove"):
2357 - print "Resume point detected, skipping remove operation..."
2358 - else:
2359 - if self.settings["spec_prefix"]+"/rm" in self.settings:
2360 - for x in self.settings[self.settings["spec_prefix"]+"/rm"]:
2361 - # we're going to shell out for all these cleaning operations,
2362 - # so we get easy glob handling
2363 - print "netboot2: removing " + x
2364 - os.system("rm -rf " + self.settings["chroot_path"] + self.settings["merge_path"] + x)
2365 -
2366 - def empty(self):
2367 - if "AUTORESUME" in self.settings \
2368 - and os.path.exists(self.settings["autoresume_path"]+"empty"):
2369 - print "Resume point detected, skipping empty operation..."
2370 - else:
2371 - if "netboot2/empty" in self.settings:
2372 - if type(self.settings["netboot2/empty"])==types.StringType:
2373 - self.settings["netboot2/empty"]=self.settings["netboot2/empty"].split()
2374 - for x in self.settings["netboot2/empty"]:
2375 - myemp=self.settings["chroot_path"] + self.settings["merge_path"] + x
2376 - if not os.path.isdir(myemp):
2377 - print x,"not a directory or does not exist, skipping 'empty' operation."
2378 - continue
2379 - print "Emptying directory", x
2380 - # stat the dir, delete the dir, recreate the dir and set
2381 - # the proper perms and ownership
2382 - mystat=os.stat(myemp)
2383 - shutil.rmtree(myemp)
2384 - os.makedirs(myemp,0755)
2385 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
2386 - os.chmod(myemp,mystat[ST_MODE])
2387 - touch(self.settings["autoresume_path"]+"empty")
2388 -
2389 - def set_action_sequence(self):
2390 - self.settings["action_sequence"]=["unpack","unpack_snapshot","config_profile_link",
2391 - "setup_confdir","portage_overlay","bind","chroot_setup",\
2392 - "setup_environment","build_packages","root_overlay",\
2393 - "copy_files_to_image","setup_overlay","build_kernel","move_kernels",\
2394 - "remove","empty","unbind","clean","clear_autoresume"]
2395 -
2396 -def register(foo):
2397 - foo.update({"netboot2":netboot2_target})
2398 - return foo
2399 diff --git a/catalyst/modules/netboot_target.py b/catalyst/modules/netboot_target.py
2400 deleted file mode 100644
2401 index 9d01b7e..0000000
2402 --- a/catalyst/modules/netboot_target.py
2403 +++ /dev/null
2404 @@ -1,128 +0,0 @@
2405 -"""
2406 -netboot target, version 1
2407 -"""
2408 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2409 -
2410 -import os,string,types
2411 -from catalyst.support import *
2412 -from generic_stage_target import *
2413 -
2414 -class netboot_target(generic_stage_target):
2415 - """
2416 - Builder class for a netboot build.
2417 - """
2418 - def __init__(self,spec,addlargs):
2419 - self.valid_values = [
2420 - "netboot/kernel/sources",
2421 - "netboot/kernel/config",
2422 - "netboot/kernel/prebuilt",
2423 -
2424 - "netboot/busybox_config",
2425 -
2426 - "netboot/extra_files",
2427 - "netboot/packages"
2428 - ]
2429 - self.required_values=[]
2430 -
2431 - try:
2432 - if "netboot/packages" in addlargs:
2433 - if type(addlargs["netboot/packages"]) == types.StringType:
2434 - loopy=[addlargs["netboot/packages"]]
2435 - else:
2436 - loopy=addlargs["netboot/packages"]
2437 -
2438 - # for x in loopy:
2439 - # self.required_values.append("netboot/packages/"+x+"/files")
2440 - except:
2441 - raise CatalystError,"configuration error in netboot/packages."
2442 -
2443 - generic_stage_target.__init__(self,spec,addlargs)
2444 - self.set_build_kernel_vars(addlargs)
2445 - if "netboot/busybox_config" in addlargs:
2446 - file_locate(self.settings, ["netboot/busybox_config"])
2447 -
2448 - # Custom Kernel Tarball --- use that instead ...
2449 -
2450 - # unless the user wants specific CFLAGS/CXXFLAGS, let's use -Os
2451 -
2452 - for envvar in "CFLAGS", "CXXFLAGS":
2453 - if envvar not in os.environ and envvar not in addlargs:
2454 - self.settings[envvar] = "-Os -pipe"
2455 -
2456 - def set_root_path(self):
2457 - # ROOT= variable for emerges
2458 - self.settings["root_path"]=normpath("/tmp/image")
2459 - print "netboot root path is "+self.settings["root_path"]
2460 -
2461 -# def build_packages(self):
2462 -# # build packages
2463 -# if "netboot/packages" in self.settings:
2464 -# mypack=list_bashify(self.settings["netboot/packages"])
2465 -# try:
2466 -# cmd("/bin/bash "+self.settings["controller_file"]+" packages "+mypack,env=self.env)
2467 -# except CatalystError:
2468 -# self.unbind()
2469 -# raise CatalystError,"netboot build aborting due to error."
2470 -
2471 - def build_busybox(self):
2472 - # build busybox
2473 - if "netboot/busybox_config" in self.settings:
2474 - mycmd = self.settings["netboot/busybox_config"]
2475 - else:
2476 - mycmd = ""
2477 - try:
2478 - cmd("/bin/bash "+self.settings["controller_file"]+" busybox "+ mycmd,env=self.env)
2479 - except CatalystError:
2480 - self.unbind()
2481 - raise CatalystError,"netboot build aborting due to error."
2482 -
2483 - def copy_files_to_image(self):
2484 - # create image
2485 - myfiles=[]
2486 - if "netboot/packages" in self.settings:
2487 - if type(self.settings["netboot/packages"]) == types.StringType:
2488 - loopy=[self.settings["netboot/packages"]]
2489 - else:
2490 - loopy=self.settings["netboot/packages"]
2491 -
2492 - for x in loopy:
2493 - if "netboot/packages/"+x+"/files" in self.settings:
2494 - if type(self.settings["netboot/packages/"+x+"/files"]) == types.ListType:
2495 - myfiles.extend(self.settings["netboot/packages/"+x+"/files"])
2496 - else:
2497 - myfiles.append(self.settings["netboot/packages/"+x+"/files"])
2498 -
2499 - if "netboot/extra_files" in self.settings:
2500 - if type(self.settings["netboot/extra_files"]) == types.ListType:
2501 - myfiles.extend(self.settings["netboot/extra_files"])
2502 - else:
2503 - myfiles.append(self.settings["netboot/extra_files"])
2504 -
2505 - try:
2506 - cmd("/bin/bash "+self.settings["controller_file"]+\
2507 - " image " + list_bashify(myfiles),env=self.env)
2508 - except CatalystError:
2509 - self.unbind()
2510 - raise CatalystError,"netboot build aborting due to error."
2511 -
2512 - def create_netboot_files(self):
2513 - # finish it all up
2514 - try:
2515 - cmd("/bin/bash "+self.settings["controller_file"]+" finish",env=self.env)
2516 - except CatalystError:
2517 - self.unbind()
2518 - raise CatalystError,"netboot build aborting due to error."
2519 -
2520 - # end
2521 - print "netboot: build finished !"
2522 -
2523 - def set_action_sequence(self):
2524 - self.settings["action_sequence"]=["unpack","unpack_snapshot",
2525 - "config_profile_link","setup_confdir","bind","chroot_setup",\
2526 - "setup_environment","build_packages","build_busybox",\
2527 - "build_kernel","copy_files_to_image",\
2528 - "clean","create_netboot_files","unbind","clear_autoresume"]
2529 -
2530 -def register(foo):
2531 - foo.update({"netboot":netboot_target})
2532 - return foo
2533 diff --git a/catalyst/modules/snapshot_target.py b/catalyst/modules/snapshot_target.py
2534 deleted file mode 100644
2535 index e21bd1a..0000000
2536 --- a/catalyst/modules/snapshot_target.py
2537 +++ /dev/null
2538 @@ -1,91 +0,0 @@
2539 -"""
2540 -Snapshot target
2541 -"""
2542 -
2543 -import os
2544 -from catalyst.support import *
2545 -from generic_stage_target import *
2546 -
2547 -class snapshot_target(generic_stage_target):
2548 - """
2549 - Builder class for snapshots.
2550 - """
2551 - def __init__(self,myspec,addlargs):
2552 - self.required_values=["version_stamp","target"]
2553 - self.valid_values=["version_stamp","target"]
2554 -
2555 - generic_target.__init__(self,myspec,addlargs)
2556 - self.settings=myspec
2557 - self.settings["target_subpath"]="portage"
2558 - st=self.settings["storedir"]
2559 - self.settings["snapshot_path"]=normpath(st + "/snapshots/"
2560 - + self.settings["snapshot_name"]
2561 - + self.settings["version_stamp"] + ".tar.bz2")
2562 - self.settings["tmp_path"]=normpath(st+"/tmp/"+self.settings["target_subpath"])
2563 -
2564 - def setup(self):
2565 - x=normpath(self.settings["storedir"]+"/snapshots")
2566 - if not os.path.exists(x):
2567 - os.makedirs(x)
2568 -
2569 - def mount_safety_check(self):
2570 - pass
2571 -
2572 - def run(self):
2573 - if "PURGEONLY" in self.settings:
2574 - self.purge()
2575 - return
2576 -
2577 - if "PURGE" in self.settings:
2578 - self.purge()
2579 -
2580 - self.setup()
2581 - print "Creating Portage tree snapshot "+self.settings["version_stamp"]+\
2582 - " from "+self.settings["portdir"]+"..."
2583 -
2584 - mytmp=self.settings["tmp_path"]
2585 - if not os.path.exists(mytmp):
2586 - os.makedirs(mytmp)
2587 -
2588 - cmd("rsync -a --delete --exclude /packages/ --exclude /distfiles/ " +
2589 - "--exclude /local/ --exclude CVS/ --exclude .svn --filter=H_**/files/digest-* " +
2590 - self.settings["portdir"] + "/ " + mytmp + "/%s/" % self.settings["repo_name"],
2591 - "Snapshot failure",env=self.env)
2592 -
2593 - print "Compressing Portage snapshot tarball..."
2594 - cmd("tar -I lbzip2 -cf " + self.settings["snapshot_path"] + " -C " +
2595 - mytmp + " %s" % self.settings["repo_name"],
2596 - "Snapshot creation failure",env=self.env)
2597 -
2598 - self.gen_contents_file(self.settings["snapshot_path"])
2599 - self.gen_digest_file(self.settings["snapshot_path"])
2600 -
2601 - self.cleanup()
2602 - print "snapshot: complete!"
2603 -
2604 - def kill_chroot_pids(self):
2605 - pass
2606 -
2607 - def cleanup(self):
2608 - print "Cleaning up..."
2609 -
2610 - def purge(self):
2611 - myemp=self.settings["tmp_path"]
2612 - if os.path.isdir(myemp):
2613 - print "Emptying directory",myemp
2614 - """
2615 - stat the dir, delete the dir, recreate the dir and set
2616 - the proper perms and ownership
2617 - """
2618 - mystat=os.stat(myemp)
2619 - """ There's no easy way to change flags recursively in python """
2620 - if os.uname()[0] == "FreeBSD":
2621 - os.system("chflags -R noschg "+myemp)
2622 - shutil.rmtree(myemp)
2623 - os.makedirs(myemp,0755)
2624 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
2625 - os.chmod(myemp,mystat[ST_MODE])
2626 -
2627 -def register(foo):
2628 - foo.update({"snapshot":snapshot_target})
2629 - return foo
2630 diff --git a/catalyst/modules/stage1_target.py b/catalyst/modules/stage1_target.py
2631 deleted file mode 100644
2632 index 25f7116..0000000
2633 --- a/catalyst/modules/stage1_target.py
2634 +++ /dev/null
2635 @@ -1,96 +0,0 @@
2636 -"""
2637 -stage1 target
2638 -"""
2639 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2640 -
2641 -from catalyst.support import *
2642 -from generic_stage_target import *
2643 -
2644 -class stage1_target(generic_stage_target):
2645 - """
2646 - Builder class for a stage1 installation tarball build.
2647 - """
2648 - def __init__(self,spec,addlargs):
2649 - self.required_values=[]
2650 - self.valid_values=["chost"]
2651 - self.valid_values.extend(["update_seed","update_seed_command"])
2652 - generic_stage_target.__init__(self,spec,addlargs)
2653 -
2654 - def set_stage_path(self):
2655 - self.settings["stage_path"]=normpath(self.settings["chroot_path"]+self.settings["root_path"])
2656 - print "stage1 stage path is "+self.settings["stage_path"]
2657 -
2658 - def set_root_path(self):
2659 - # sets the root path, relative to 'chroot_path', of the stage1 root
2660 - self.settings["root_path"]=normpath("/tmp/stage1root")
2661 - print "stage1 root path is "+self.settings["root_path"]
2662 -
2663 - def set_cleanables(self):
2664 - generic_stage_target.set_cleanables(self)
2665 - self.settings["cleanables"].extend([\
2666 - "/usr/share/zoneinfo", "/etc/portage/package*"])
2667 -
2668 - # XXX: How do these override_foo() functions differ from the ones in generic_stage_target and why aren't they in stage3_target?
2669 -
2670 - def override_chost(self):
2671 - if "chost" in self.settings:
2672 - self.settings["CHOST"]=list_to_string(self.settings["chost"])
2673 -
2674 - def override_cflags(self):
2675 - if "cflags" in self.settings:
2676 - self.settings["CFLAGS"]=list_to_string(self.settings["cflags"])
2677 -
2678 - def override_cxxflags(self):
2679 - if "cxxflags" in self.settings:
2680 - self.settings["CXXFLAGS"]=list_to_string(self.settings["cxxflags"])
2681 -
2682 - def override_ldflags(self):
2683 - if "ldflags" in self.settings:
2684 - self.settings["LDFLAGS"]=list_to_string(self.settings["ldflags"])
2685 -
2686 - def set_portage_overlay(self):
2687 - generic_stage_target.set_portage_overlay(self)
2688 - if "portage_overlay" in self.settings:
2689 - print "\nWARNING !!!!!"
2690 - print "\tUsing an portage overlay for earlier stages could cause build issues."
2691 - print "\tIf you break it, you buy it. Don't complain to us about it."
2692 - print "\tDont say we did not warn you\n"
2693 -
2694 - def base_dirs(self):
2695 - if os.uname()[0] == "FreeBSD":
2696 - # baselayout no longer creates the .keep files in proc and dev for FreeBSD as it
2697 - # would create them too late...we need them earlier before bind mounting filesystems
2698 - # since proc and dev are not writeable, so...create them here
2699 - if not os.path.exists(self.settings["stage_path"]+"/proc"):
2700 - os.makedirs(self.settings["stage_path"]+"/proc")
2701 - if not os.path.exists(self.settings["stage_path"]+"/dev"):
2702 - os.makedirs(self.settings["stage_path"]+"/dev")
2703 - if not os.path.isfile(self.settings["stage_path"]+"/proc/.keep"):
2704 - try:
2705 - proc_keepfile = open(self.settings["stage_path"]+"/proc/.keep","w")
2706 - proc_keepfile.write('')
2707 - proc_keepfile.close()
2708 - except IOError:
2709 - print "!!! Failed to create %s" % (self.settings["stage_path"]+"/dev/.keep")
2710 - if not os.path.isfile(self.settings["stage_path"]+"/dev/.keep"):
2711 - try:
2712 - dev_keepfile = open(self.settings["stage_path"]+"/dev/.keep","w")
2713 - dev_keepfile.write('')
2714 - dev_keepfile.close()
2715 - except IOError:
2716 - print "!!! Failed to create %s" % (self.settings["stage_path"]+"/dev/.keep")
2717 - else:
2718 - pass
2719 -
2720 - def set_mounts(self):
2721 - # stage_path/proc probably doesn't exist yet, so create it
2722 - if not os.path.exists(self.settings["stage_path"]+"/proc"):
2723 - os.makedirs(self.settings["stage_path"]+"/proc")
2724 -
2725 - # alter the mount mappings to bind mount proc onto it
2726 - self.mounts.append("/tmp/stage1root/proc")
2727 - self.mountmap["/tmp/stage1root/proc"]="/proc"
2728 -
2729 -def register(foo):
2730 - foo.update({"stage1":stage1_target})
2731 - return foo
2732 diff --git a/catalyst/modules/stage2_target.py b/catalyst/modules/stage2_target.py
2733 deleted file mode 100644
2734 index 15acdee..0000000
2735 --- a/catalyst/modules/stage2_target.py
2736 +++ /dev/null
2737 @@ -1,62 +0,0 @@
2738 -"""
2739 -stage2 target, builds upon previous stage1 tarball
2740 -"""
2741 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2742 -
2743 -from catalyst.support import *
2744 -from generic_stage_target import *
2745 -
2746 -class stage2_target(generic_stage_target):
2747 - """
2748 - Builder class for a stage2 installation tarball build.
2749 - """
2750 - def __init__(self,spec,addlargs):
2751 - self.required_values=[]
2752 - self.valid_values=["chost"]
2753 - generic_stage_target.__init__(self,spec,addlargs)
2754 -
2755 - def set_source_path(self):
2756 - if "SEEDCACHE" in self.settings and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")):
2757 - self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")
2758 - else:
2759 - self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2")
2760 - if os.path.isfile(self.settings["source_path"]):
2761 - if os.path.exists(self.settings["source_path"]):
2762 - # XXX: Is this even necessary if the previous check passes?
2763 - self.settings["source_path_hash"]=generate_hash(self.settings["source_path"],\
2764 - hash_function=self.settings["hash_function"],verbose=False)
2765 - print "Source path set to "+self.settings["source_path"]
2766 - if os.path.isdir(self.settings["source_path"]):
2767 - print "\tIf this is not desired, remove this directory or turn of seedcache in the options of catalyst.conf"
2768 - print "\tthe source path will then be "+normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2\n")
2769 -
2770 - # XXX: How do these override_foo() functions differ from the ones in
2771 - # generic_stage_target and why aren't they in stage3_target?
2772 -
2773 - def override_chost(self):
2774 - if "chost" in self.settings:
2775 - self.settings["CHOST"]=list_to_string(self.settings["chost"])
2776 -
2777 - def override_cflags(self):
2778 - if "cflags" in self.settings:
2779 - self.settings["CFLAGS"]=list_to_string(self.settings["cflags"])
2780 -
2781 - def override_cxxflags(self):
2782 - if "cxxflags" in self.settings:
2783 - self.settings["CXXFLAGS"]=list_to_string(self.settings["cxxflags"])
2784 -
2785 - def override_ldflags(self):
2786 - if "ldflags" in self.settings:
2787 - self.settings["LDFLAGS"]=list_to_string(self.settings["ldflags"])
2788 -
2789 - def set_portage_overlay(self):
2790 - generic_stage_target.set_portage_overlay(self)
2791 - if "portage_overlay" in self.settings:
2792 - print "\nWARNING !!!!!"
2793 - print "\tUsing an portage overlay for earlier stages could cause build issues."
2794 - print "\tIf you break it, you buy it. Don't complain to us about it."
2795 - print "\tDont say we did not warn you\n"
2796 -
2797 -def register(foo):
2798 - foo.update({"stage2":stage2_target})
2799 - return foo
2800 diff --git a/catalyst/modules/stage3_target.py b/catalyst/modules/stage3_target.py
2801 deleted file mode 100644
2802 index 89edd66..0000000
2803 --- a/catalyst/modules/stage3_target.py
2804 +++ /dev/null
2805 @@ -1,31 +0,0 @@
2806 -"""
2807 -stage3 target, builds upon previous stage2/stage3 tarball
2808 -"""
2809 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2810 -
2811 -from catalyst.support import *
2812 -from generic_stage_target import *
2813 -
2814 -class stage3_target(generic_stage_target):
2815 - """
2816 - Builder class for a stage3 installation tarball build.
2817 - """
2818 - def __init__(self,spec,addlargs):
2819 - self.required_values=[]
2820 - self.valid_values=[]
2821 - generic_stage_target.__init__(self,spec,addlargs)
2822 -
2823 - def set_portage_overlay(self):
2824 - generic_stage_target.set_portage_overlay(self)
2825 - if "portage_overlay" in self.settings:
2826 - print "\nWARNING !!!!!"
2827 - print "\tUsing an overlay for earlier stages could cause build issues."
2828 - print "\tIf you break it, you buy it. Don't complain to us about it."
2829 - print "\tDont say we did not warn you\n"
2830 -
2831 - def set_cleanables(self):
2832 - generic_stage_target.set_cleanables(self)
2833 -
2834 -def register(foo):
2835 - foo.update({"stage3":stage3_target})
2836 - return foo
2837 diff --git a/catalyst/modules/stage4_target.py b/catalyst/modules/stage4_target.py
2838 deleted file mode 100644
2839 index 9168f2e..0000000
2840 --- a/catalyst/modules/stage4_target.py
2841 +++ /dev/null
2842 @@ -1,43 +0,0 @@
2843 -"""
2844 -stage4 target, builds upon previous stage3/stage4 tarball
2845 -"""
2846 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2847 -
2848 -from catalyst.support import *
2849 -from generic_stage_target import *
2850 -
2851 -class stage4_target(generic_stage_target):
2852 - """
2853 - Builder class for stage4.
2854 - """
2855 - def __init__(self,spec,addlargs):
2856 - self.required_values=["stage4/packages"]
2857 - self.valid_values=self.required_values[:]
2858 - self.valid_values.extend(["stage4/use","boot/kernel",\
2859 - "stage4/root_overlay","stage4/fsscript",\
2860 - "stage4/gk_mainargs","splash_theme",\
2861 - "portage_overlay","stage4/rcadd","stage4/rcdel",\
2862 - "stage4/linuxrc","stage4/unmerge","stage4/rm","stage4/empty"])
2863 - generic_stage_target.__init__(self,spec,addlargs)
2864 -
2865 - def set_cleanables(self):
2866 - self.settings["cleanables"]=["/var/tmp/*","/tmp/*"]
2867 -
2868 - def set_action_sequence(self):
2869 - self.settings["action_sequence"]=["unpack","unpack_snapshot",\
2870 - "config_profile_link","setup_confdir","portage_overlay",\
2871 - "bind","chroot_setup","setup_environment","build_packages",\
2872 - "build_kernel","bootloader","root_overlay","fsscript",\
2873 - "preclean","rcupdate","unmerge","unbind","remove","empty",\
2874 - "clean"]
2875 -
2876 -# if "TARBALL" in self.settings or \
2877 -# "FETCH" not in self.settings:
2878 - if "FETCH" not in self.settings:
2879 - self.settings["action_sequence"].append("capture")
2880 - self.settings["action_sequence"].append("clear_autoresume")
2881 -
2882 -def register(foo):
2883 - foo.update({"stage4":stage4_target})
2884 - return foo
2885 -
2886 diff --git a/catalyst/modules/tinderbox_target.py b/catalyst/modules/tinderbox_target.py
2887 deleted file mode 100644
2888 index 5985c5b..0000000
2889 --- a/catalyst/modules/tinderbox_target.py
2890 +++ /dev/null
2891 @@ -1,44 +0,0 @@
2892 -"""
2893 -Tinderbox target
2894 -"""
2895 -# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2896 -
2897 -from catalyst.support import *
2898 -from generic_stage_target import *
2899 -
2900 -class tinderbox_target(generic_stage_target):
2901 - """
2902 - Builder class for the tinderbox target
2903 - """
2904 - def __init__(self,spec,addlargs):
2905 - self.required_values=["tinderbox/packages"]
2906 - self.valid_values=self.required_values[:]
2907 - self.valid_values.extend(["tinderbox/use"])
2908 - generic_stage_target.__init__(self,spec,addlargs)
2909 -
2910 - def run_local(self):
2911 - # tinderbox
2912 - # example call: "grp.sh run xmms vim sys-apps/gleep"
2913 - try:
2914 - if os.path.exists(self.settings["controller_file"]):
2915 - cmd("/bin/bash "+self.settings["controller_file"]+" run "+\
2916 - list_bashify(self.settings["tinderbox/packages"]),"run script failed.",env=self.env)
2917 -
2918 - except CatalystError:
2919 - self.unbind()
2920 - raise CatalystError,"Tinderbox aborting due to error."
2921 -
2922 - def set_cleanables(self):
2923 - self.settings["cleanables"]=["/etc/resolv.conf","/var/tmp/*","/root/*",
2924 - self.settings['portdir']]
2925 -
2926 - def set_action_sequence(self):
2927 - #Default action sequence for run method
2928 - self.settings["action_sequence"]=["unpack","unpack_snapshot",\
2929 - "config_profile_link","setup_confdir","bind","chroot_setup",\
2930 - "setup_environment","run_local","preclean","unbind","clean",\
2931 - "clear_autoresume"]
2932 -
2933 -def register(foo):
2934 - foo.update({"tinderbox":tinderbox_target})
2935 - return foo
2936 diff --git a/catalyst/targets/__init__.py b/catalyst/targets/__init__.py
2937 new file mode 100644
2938 index 0000000..8b13789
2939 --- /dev/null
2940 +++ b/catalyst/targets/__init__.py
2941 @@ -0,0 +1 @@
2942 +
2943 diff --git a/catalyst/targets/embedded_target.py b/catalyst/targets/embedded_target.py
2944 new file mode 100644
2945 index 0000000..7cee7a6
2946 --- /dev/null
2947 +++ b/catalyst/targets/embedded_target.py
2948 @@ -0,0 +1,51 @@
2949 +"""
2950 +Enbedded target, similar to the stage2 target, builds upon a stage2 tarball.
2951 +
2952 +A stage2 tarball is unpacked, but instead
2953 +of building a stage3, it emerges @system into another directory
2954 +inside the stage2 system. This way, we do not have to emerge GCC/portage
2955 +into the staged system.
2956 +It may sound complicated but basically it runs
2957 +ROOT=/tmp/submerge emerge --something foo bar .
2958 +"""
2959 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2960 +
2961 +import os,string,imp,types,shutil
2962 +from catalyst.support import *
2963 +from generic_stage_target import *
2964 +from stat import *
2965 +
2966 +class embedded_target(generic_stage_target):
2967 + """
2968 + Builder class for embedded target
2969 + """
2970 + def __init__(self,spec,addlargs):
2971 + self.required_values=[]
2972 + self.valid_values=[]
2973 + self.valid_values.extend(["embedded/empty","embedded/rm","embedded/unmerge","embedded/fs-prepare","embedded/fs-finish","embedded/mergeroot","embedded/packages","embedded/fs-type","embedded/runscript","boot/kernel","embedded/linuxrc"])
2974 + self.valid_values.extend(["embedded/use"])
2975 + if "embedded/fs-type" in addlargs:
2976 + self.valid_values.append("embedded/fs-ops")
2977 +
2978 + generic_stage_target.__init__(self,spec,addlargs)
2979 + self.set_build_kernel_vars(addlargs)
2980 +
2981 + def set_action_sequence(self):
2982 + self.settings["action_sequence"]=["dir_setup","unpack","unpack_snapshot",\
2983 + "config_profile_link","setup_confdir",\
2984 + "portage_overlay","bind","chroot_setup",\
2985 + "setup_environment","build_kernel","build_packages",\
2986 + "bootloader","root_overlay","fsscript","unmerge",\
2987 + "unbind","remove","empty","clean","capture","clear_autoresume"]
2988 +
2989 + def set_stage_path(self):
2990 + self.settings["stage_path"]=normpath(self.settings["chroot_path"]+"/tmp/mergeroot")
2991 + print "embedded stage path is "+self.settings["stage_path"]
2992 +
2993 + def set_root_path(self):
2994 + self.settings["root_path"]=normpath("/tmp/mergeroot")
2995 + print "embedded root path is "+self.settings["root_path"]
2996 +
2997 +def register(foo):
2998 + foo.update({"embedded":embedded_target})
2999 + return foo
3000 diff --git a/catalyst/targets/generic_stage_target.py b/catalyst/targets/generic_stage_target.py
3001 new file mode 100644
3002 index 0000000..5200d8a
3003 --- /dev/null
3004 +++ b/catalyst/targets/generic_stage_target.py
3005 @@ -0,0 +1,1691 @@
3006 +import os,string,imp,types,shutil
3007 +from catalyst.support import *
3008 +from generic_target import *
3009 +from stat import *
3010 +from catalyst.lock import LockDir
3011 +
3012 +class generic_stage_target(generic_target):
3013 + """
3014 + This class does all of the chroot setup, copying of files, etc. It is
3015 + the driver class for pretty much everything that Catalyst does.
3016 + """
3017 + def __init__(self,myspec,addlargs):
3018 + self.required_values.extend(["version_stamp","target","subarch",\
3019 + "rel_type","profile","snapshot","source_subpath"])
3020 +
3021 + self.valid_values.extend(["version_stamp","target","subarch",\
3022 + "rel_type","profile","snapshot","source_subpath","portage_confdir",\
3023 + "cflags","cxxflags","ldflags","cbuild","hostuse","portage_overlay",\
3024 + "distcc_hosts","makeopts","pkgcache_path","kerncache_path"])
3025 +
3026 + self.set_valid_build_kernel_vars(addlargs)
3027 + generic_target.__init__(self,myspec,addlargs)
3028 +
3029 + """
3030 + The semantics of subarchmap and machinemap changed a bit in 2.0.3 to
3031 + work better with vapier's CBUILD stuff. I've removed the "monolithic"
3032 + machinemap from this file and split up its contents amongst the
3033 + various arch/foo.py files.
3034 +
3035 + When register() is called on each module in the arch/ dir, it now
3036 + returns a tuple instead of acting on the subarchmap dict that is
3037 + passed to it. The tuple contains the values that were previously
3038 + added to subarchmap as well as a new list of CHOSTs that go along
3039 + with that arch. This allows us to build machinemap on the fly based
3040 + on the keys in subarchmap and the values of the 2nd list returned
3041 + (tmpmachinemap).
3042 +
3043 + Also, after talking with vapier. I have a slightly better idea of what
3044 + certain variables are used for and what they should be set to. Neither
3045 + 'buildarch' or 'hostarch' are used directly, so their value doesn't
3046 + really matter. They are just compared to determine if we are
3047 + cross-compiling. Because of this, they are just set to the name of the
3048 + module in arch/ that the subarch is part of to make things simpler.
3049 + The entire build process is still based off of 'subarch' like it was
3050 + previously. -agaffney
3051 + """
3052 +
3053 + self.archmap = {}
3054 + self.subarchmap = {}
3055 + machinemap = {}
3056 + arch_dir = self.settings["PythonDir"] + "/arch/"
3057 + for x in [x[:-3] for x in os.listdir(arch_dir) if x.endswith(".py")]:
3058 + try:
3059 + fh=open(arch_dir + x + ".py")
3060 + """
3061 + This next line loads the plugin as a module and assigns it to
3062 + archmap[x]
3063 + """
3064 + self.archmap[x]=imp.load_module(x,fh,"../arch/" + x + ".py",
3065 + (".py", "r", imp.PY_SOURCE))
3066 + """
3067 + This next line registers all the subarches supported in the
3068 + plugin
3069 + """
3070 + tmpsubarchmap, tmpmachinemap = self.archmap[x].register()
3071 + self.subarchmap.update(tmpsubarchmap)
3072 + for machine in tmpmachinemap:
3073 + machinemap[machine] = x
3074 + for subarch in tmpsubarchmap:
3075 + machinemap[subarch] = x
3076 + fh.close()
3077 + except IOError:
3078 + """
3079 + This message should probably change a bit, since everything in
3080 + the dir should load just fine. If it doesn't, it's probably a
3081 + syntax error in the module
3082 + """
3083 + msg("Can't find/load " + x + ".py plugin in " + arch_dir)
3084 +
3085 + if "chost" in self.settings:
3086 + hostmachine = self.settings["chost"].split("-")[0]
3087 + if hostmachine not in machinemap:
3088 + raise CatalystError, "Unknown host machine type "+hostmachine
3089 + self.settings["hostarch"]=machinemap[hostmachine]
3090 + else:
3091 + hostmachine = self.settings["subarch"]
3092 + if hostmachine in machinemap:
3093 + hostmachine = machinemap[hostmachine]
3094 + self.settings["hostarch"]=hostmachine
3095 + if "cbuild" in self.settings:
3096 + buildmachine = self.settings["cbuild"].split("-")[0]
3097 + else:
3098 + buildmachine = os.uname()[4]
3099 + if buildmachine not in machinemap:
3100 + raise CatalystError, "Unknown build machine type "+buildmachine
3101 + self.settings["buildarch"]=machinemap[buildmachine]
3102 + self.settings["crosscompile"]=(self.settings["hostarch"]!=\
3103 + self.settings["buildarch"])
3104 +
3105 + """ Call arch constructor, pass our settings """
3106 + try:
3107 + self.arch=self.subarchmap[self.settings["subarch"]](self.settings)
3108 + except KeyError:
3109 + print "Invalid subarch: "+self.settings["subarch"]
3110 + print "Choose one of the following:",
3111 + for x in self.subarchmap:
3112 + print x,
3113 + print
3114 + sys.exit(2)
3115 +
3116 + print "Using target:",self.settings["target"]
3117 + """ Print a nice informational message """
3118 + if self.settings["buildarch"]==self.settings["hostarch"]:
3119 + print "Building natively for",self.settings["hostarch"]
3120 + elif self.settings["crosscompile"]:
3121 + print "Cross-compiling on",self.settings["buildarch"],\
3122 + "for different machine type",self.settings["hostarch"]
3123 + else:
3124 + print "Building on",self.settings["buildarch"],\
3125 + "for alternate personality type",self.settings["hostarch"]
3126 +
3127 + """ This must be set first as other set_ options depend on this """
3128 + self.set_spec_prefix()
3129 +
3130 + """ Define all of our core variables """
3131 + self.set_target_profile()
3132 + self.set_target_subpath()
3133 + self.set_source_subpath()
3134 +
3135 + """ Set paths """
3136 + self.set_snapshot_path()
3137 + self.set_root_path()
3138 + self.set_source_path()
3139 + self.set_snapcache_path()
3140 + self.set_chroot_path()
3141 + self.set_autoresume_path()
3142 + self.set_dest_path()
3143 + self.set_stage_path()
3144 + self.set_target_path()
3145 +
3146 + self.set_controller_file()
3147 + self.set_action_sequence()
3148 + self.set_use()
3149 + self.set_cleanables()
3150 + self.set_iso_volume_id()
3151 + self.set_build_kernel_vars()
3152 + self.set_fsscript()
3153 + self.set_install_mask()
3154 + self.set_rcadd()
3155 + self.set_rcdel()
3156 + self.set_cdtar()
3157 + self.set_fstype()
3158 + self.set_fsops()
3159 + self.set_iso()
3160 + self.set_packages()
3161 + self.set_rm()
3162 + self.set_linuxrc()
3163 + self.set_busybox_config()
3164 + self.set_overlay()
3165 + self.set_portage_overlay()
3166 + self.set_root_overlay()
3167 +
3168 + """
3169 + This next line checks to make sure that the specified variables exist
3170 + on disk.
3171 + """
3172 + #pdb.set_trace()
3173 + file_locate(self.settings,["source_path","snapshot_path","distdir"],\
3174 + expand=0)
3175 + """ If we are using portage_confdir, check that as well. """
3176 + if "portage_confdir" in self.settings:
3177 + file_locate(self.settings,["portage_confdir"],expand=0)
3178 +
3179 + """ Setup our mount points """
3180 + if "SNAPCACHE" in self.settings:
3181 + self.mounts=["/proc","/dev","/usr/portage","/usr/portage/distfiles","/var/tmp/portage"]
3182 + self.mountmap={"/proc":"/proc","/dev":"/dev","/dev/pts":"/dev/pts",\
3183 + "/usr/portage":self.settings["snapshot_cache_path"]+"/portage",\
3184 + "/usr/portage/distfiles":self.settings["distdir"],"/var/tmp/portage":"tmpfs"}
3185 + else:
3186 + self.mounts=["proc","dev", "distdir", "port_tmpdir"]
3187 + self.mountmap={"proc":"/proc", "dev":"/dev", "pts":"/dev/pts",
3188 + "distdir":self.settings["distdir"], "port_tmpdir":"tmpfs"}
3189 + if os.uname()[0] == "Linux":
3190 + self.mounts.append("pts")
3191 +
3192 + self.set_mounts()
3193 +
3194 + """
3195 + Configure any user specified options (either in catalyst.conf or on
3196 + the command line).
3197 + """
3198 + if "PKGCACHE" in self.settings:
3199 + self.set_pkgcache_path()
3200 + print "Location of the package cache is "+\
3201 + self.settings["pkgcache_path"]
3202 + self.mounts.append("packagedir")
3203 + self.mountmap["packagedir"] = self.settings["pkgcache_path"]
3204 +
3205 + if "KERNCACHE" in self.settings:
3206 + self.set_kerncache_path()
3207 + print "Location of the kerncache is "+\
3208 + self.settings["kerncache_path"]
3209 + self.mounts.append("kerncache")
3210 + self.mountmap["kerncache"]=self.settings["kerncache_path"]
3211 +
3212 + if "CCACHE" in self.settings:
3213 + if "CCACHE_DIR" in os.environ:
3214 + ccdir=os.environ["CCACHE_DIR"]
3215 + del os.environ["CCACHE_DIR"]
3216 + else:
3217 + ccdir="/root/.ccache"
3218 + if not os.path.isdir(ccdir):
3219 + raise CatalystError,\
3220 + "Compiler cache support can't be enabled (can't find "+\
3221 + ccdir+")"
3222 + self.mounts.append("ccache")
3223 + self.mountmap["ccache"]=ccdir
3224 + """ for the chroot: """
3225 + self.env["CCACHE_DIR"]="/var/tmp/ccache"
3226 +
3227 + if "ICECREAM" in self.settings:
3228 + self.mounts.append("/var/cache/icecream")
3229 + self.mountmap["/var/cache/icecream"]="/var/cache/icecream"
3230 + self.env["PATH"]="/usr/lib/icecc/bin:"+self.env["PATH"]
3231 +
3232 + if "port_logdir" in self.settings:
3233 + self.mounts.append("/var/log/portage")
3234 + self.mountmap["/var/log/portage"]=self.settings["port_logdir"]
3235 + self.env["PORT_LOGDIR"]="/var/log/portage"
3236 + self.env["PORT_LOGDIR_CLEAN"]='find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete'
3237 +
3238 + def override_cbuild(self):
3239 + if "CBUILD" in self.makeconf:
3240 + self.settings["CBUILD"]=self.makeconf["CBUILD"]
3241 +
3242 + def override_chost(self):
3243 + if "CHOST" in self.makeconf:
3244 + self.settings["CHOST"]=self.makeconf["CHOST"]
3245 +
3246 + def override_cflags(self):
3247 + if "CFLAGS" in self.makeconf:
3248 + self.settings["CFLAGS"]=self.makeconf["CFLAGS"]
3249 +
3250 + def override_cxxflags(self):
3251 + if "CXXFLAGS" in self.makeconf:
3252 + self.settings["CXXFLAGS"]=self.makeconf["CXXFLAGS"]
3253 +
3254 + def override_ldflags(self):
3255 + if "LDFLAGS" in self.makeconf:
3256 + self.settings["LDFLAGS"]=self.makeconf["LDFLAGS"]
3257 +
3258 + def set_install_mask(self):
3259 + if "install_mask" in self.settings:
3260 + if type(self.settings["install_mask"])!=types.StringType:
3261 + self.settings["install_mask"]=\
3262 + string.join(self.settings["install_mask"])
3263 +
3264 + def set_spec_prefix(self):
3265 + self.settings["spec_prefix"]=self.settings["target"]
3266 +
3267 + def set_target_profile(self):
3268 + self.settings["target_profile"]=self.settings["profile"]
3269 +
3270 + def set_target_subpath(self):
3271 + self.settings["target_subpath"]=self.settings["rel_type"]+"/"+\
3272 + self.settings["target"]+"-"+self.settings["subarch"]+"-"+\
3273 + self.settings["version_stamp"]
3274 +
3275 + def set_source_subpath(self):
3276 + if type(self.settings["source_subpath"])!=types.StringType:
3277 + raise CatalystError,\
3278 + "source_subpath should have been a string. Perhaps you have something wrong in your spec file?"
3279 +
3280 + def set_pkgcache_path(self):
3281 + if "pkgcache_path" in self.settings:
3282 + if type(self.settings["pkgcache_path"])!=types.StringType:
3283 + self.settings["pkgcache_path"]=\
3284 + normpath(string.join(self.settings["pkgcache_path"]))
3285 + else:
3286 + self.settings["pkgcache_path"]=\
3287 + normpath(self.settings["storedir"]+"/packages/"+\
3288 + self.settings["target_subpath"]+"/")
3289 +
3290 + def set_kerncache_path(self):
3291 + if "kerncache_path" in self.settings:
3292 + if type(self.settings["kerncache_path"])!=types.StringType:
3293 + self.settings["kerncache_path"]=\
3294 + normpath(string.join(self.settings["kerncache_path"]))
3295 + else:
3296 + self.settings["kerncache_path"]=normpath(self.settings["storedir"]+\
3297 + "/kerncache/"+self.settings["target_subpath"]+"/")
3298 +
3299 + def set_target_path(self):
3300 + self.settings["target_path"]=normpath(self.settings["storedir"]+\
3301 + "/builds/"+self.settings["target_subpath"]+".tar.bz2")
3302 + if "AUTORESUME" in self.settings\
3303 + and os.path.exists(self.settings["autoresume_path"]+\
3304 + "setup_target_path"):
3305 + print \
3306 + "Resume point detected, skipping target path setup operation..."
3307 + else:
3308 + """ First clean up any existing target stuff """
3309 + # XXX WTF are we removing the old tarball before we start building the
3310 + # XXX new one? If the build fails, you don't want to be left with
3311 + # XXX nothing at all
3312 +# if os.path.isfile(self.settings["target_path"]):
3313 +# cmd("rm -f "+self.settings["target_path"],\
3314 +# "Could not remove existing file: "\
3315 +# +self.settings["target_path"],env=self.env)
3316 + touch(self.settings["autoresume_path"]+"setup_target_path")
3317 +
3318 + if not os.path.exists(self.settings["storedir"]+"/builds/"):
3319 + os.makedirs(self.settings["storedir"]+"/builds/")
3320 +
3321 + def set_fsscript(self):
3322 + if self.settings["spec_prefix"]+"/fsscript" in self.settings:
3323 + self.settings["fsscript"]=\
3324 + self.settings[self.settings["spec_prefix"]+"/fsscript"]
3325 + del self.settings[self.settings["spec_prefix"]+"/fsscript"]
3326 +
3327 + def set_rcadd(self):
3328 + if self.settings["spec_prefix"]+"/rcadd" in self.settings:
3329 + self.settings["rcadd"]=\
3330 + self.settings[self.settings["spec_prefix"]+"/rcadd"]
3331 + del self.settings[self.settings["spec_prefix"]+"/rcadd"]
3332 +
3333 + def set_rcdel(self):
3334 + if self.settings["spec_prefix"]+"/rcdel" in self.settings:
3335 + self.settings["rcdel"]=\
3336 + self.settings[self.settings["spec_prefix"]+"/rcdel"]
3337 + del self.settings[self.settings["spec_prefix"]+"/rcdel"]
3338 +
3339 + def set_cdtar(self):
3340 + if self.settings["spec_prefix"]+"/cdtar" in self.settings:
3341 + self.settings["cdtar"]=\
3342 + normpath(self.settings[self.settings["spec_prefix"]+"/cdtar"])
3343 + del self.settings[self.settings["spec_prefix"]+"/cdtar"]
3344 +
3345 + def set_iso(self):
3346 + if self.settings["spec_prefix"]+"/iso" in self.settings:
3347 + if self.settings[self.settings["spec_prefix"]+"/iso"].startswith('/'):
3348 + self.settings["iso"]=\
3349 + normpath(self.settings[self.settings["spec_prefix"]+"/iso"])
3350 + else:
3351 + # This automatically prepends the build dir to the ISO output path
3352 + # if it doesn't start with a /
3353 + self.settings["iso"] = normpath(self.settings["storedir"] + \
3354 + "/builds/" + self.settings["rel_type"] + "/" + \
3355 + self.settings[self.settings["spec_prefix"]+"/iso"])
3356 + del self.settings[self.settings["spec_prefix"]+"/iso"]
3357 +
3358 + def set_fstype(self):
3359 + if self.settings["spec_prefix"]+"/fstype" in self.settings:
3360 + self.settings["fstype"]=\
3361 + self.settings[self.settings["spec_prefix"]+"/fstype"]
3362 + del self.settings[self.settings["spec_prefix"]+"/fstype"]
3363 +
3364 + if "fstype" not in self.settings:
3365 + self.settings["fstype"]="normal"
3366 + for x in self.valid_values:
3367 + if x == self.settings["spec_prefix"]+"/fstype":
3368 + print "\n"+self.settings["spec_prefix"]+\
3369 + "/fstype is being set to the default of \"normal\"\n"
3370 +
3371 + def set_fsops(self):
3372 + if "fstype" in self.settings:
3373 + self.valid_values.append("fsops")
3374 + if self.settings["spec_prefix"]+"/fsops" in self.settings:
3375 + self.settings["fsops"]=\
3376 + self.settings[self.settings["spec_prefix"]+"/fsops"]
3377 + del self.settings[self.settings["spec_prefix"]+"/fsops"]
3378 +
3379 + def set_source_path(self):
3380 + if "SEEDCACHE" in self.settings\
3381 + and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+\
3382 + self.settings["source_subpath"]+"/")):
3383 + self.settings["source_path"]=normpath(self.settings["storedir"]+\
3384 + "/tmp/"+self.settings["source_subpath"]+"/")
3385 + else:
3386 + self.settings["source_path"]=normpath(self.settings["storedir"]+\
3387 + "/builds/"+self.settings["source_subpath"]+".tar.bz2")
3388 + if os.path.isfile(self.settings["source_path"]):
3389 + # XXX: Is this even necessary if the previous check passes?
3390 + if os.path.exists(self.settings["source_path"]):
3391 + self.settings["source_path_hash"]=\
3392 + generate_hash(self.settings["source_path"],\
3393 + hash_function=self.settings["hash_function"],\
3394 + verbose=False)
3395 + print "Source path set to "+self.settings["source_path"]
3396 + if os.path.isdir(self.settings["source_path"]):
3397 + print "\tIf this is not desired, remove this directory or turn off"
3398 + print "\tseedcache in the options of catalyst.conf the source path"
3399 + print "\twill then be "+\
3400 + normpath(self.settings["storedir"]+"/builds/"+\
3401 + self.settings["source_subpath"]+".tar.bz2\n")
3402 +
3403 + def set_dest_path(self):
3404 + if "root_path" in self.settings:
3405 + self.settings["destpath"]=normpath(self.settings["chroot_path"]+\
3406 + self.settings["root_path"])
3407 + else:
3408 + self.settings["destpath"]=normpath(self.settings["chroot_path"])
3409 +
3410 + def set_cleanables(self):
3411 + self.settings["cleanables"]=["/etc/resolv.conf","/var/tmp/*","/tmp/*",\
3412 + "/root/*", self.settings["portdir"]]
3413 +
3414 + def set_snapshot_path(self):
3415 + self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
3416 + "/snapshots/" + self.settings["snapshot_name"] +
3417 + self.settings["snapshot"]+".tar.xz")
3418 +
3419 + if os.path.exists(self.settings["snapshot_path"]):
3420 + self.settings["snapshot_path_hash"]=\
3421 + generate_hash(self.settings["snapshot_path"],\
3422 + hash_function=self.settings["hash_function"],verbose=False)
3423 + else:
3424 + self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
3425 + "/snapshots/" + self.settings["snapshot_name"] +
3426 + self.settings["snapshot"]+".tar.bz2")
3427 +
3428 + if os.path.exists(self.settings["snapshot_path"]):
3429 + self.settings["snapshot_path_hash"]=\
3430 + generate_hash(self.settings["snapshot_path"],\
3431 + hash_function=self.settings["hash_function"],verbose=False)
3432 +
3433 + def set_snapcache_path(self):
3434 + if "SNAPCACHE" in self.settings:
3435 + self.settings["snapshot_cache_path"]=\
3436 + normpath(self.settings["snapshot_cache"]+"/"+\
3437 + self.settings["snapshot"]+"/")
3438 + self.snapcache_lock=\
3439 + LockDir(self.settings["snapshot_cache_path"])
3440 + print "Caching snapshot to "+self.settings["snapshot_cache_path"]
3441 +
3442 + def set_chroot_path(self):
3443 + """
3444 + NOTE: the trailing slash is very important!
3445 + Things *will* break without it!
3446 + """
3447 + self.settings["chroot_path"]=normpath(self.settings["storedir"]+\
3448 + "/tmp/"+self.settings["target_subpath"]+"/")
3449 + self.chroot_lock=LockDir(self.settings["chroot_path"])
3450 +
3451 + def set_autoresume_path(self):
3452 + self.settings["autoresume_path"]=normpath(self.settings["storedir"]+\
3453 + "/tmp/"+self.settings["rel_type"]+"/"+".autoresume-"+\
3454 + self.settings["target"]+"-"+self.settings["subarch"]+"-"+\
3455 + self.settings["version_stamp"]+"/")
3456 + if "AUTORESUME" in self.settings:
3457 + print "The autoresume path is " + self.settings["autoresume_path"]
3458 + if not os.path.exists(self.settings["autoresume_path"]):
3459 + os.makedirs(self.settings["autoresume_path"],0755)
3460 +
3461 + def set_controller_file(self):
3462 + self.settings["controller_file"]=normpath(self.settings["sharedir"]+\
3463 + "/targets/"+self.settings["target"]+"/"+self.settings["target"]+\
3464 + "-controller.sh")
3465 +
3466 + def set_iso_volume_id(self):
3467 + if self.settings["spec_prefix"]+"/volid" in self.settings:
3468 + self.settings["iso_volume_id"]=\
3469 + self.settings[self.settings["spec_prefix"]+"/volid"]
3470 + if len(self.settings["iso_volume_id"])>32:
3471 + raise CatalystError,\
3472 + "ISO volume ID must not exceed 32 characters."
3473 + else:
3474 + self.settings["iso_volume_id"]="catalyst "+self.settings["snapshot"]
3475 +
3476 + def set_action_sequence(self):
3477 + """ Default action sequence for run method """
3478 + self.settings["action_sequence"]=["unpack","unpack_snapshot",\
3479 + "setup_confdir","portage_overlay",\
3480 + "base_dirs","bind","chroot_setup","setup_environment",\
3481 + "run_local","preclean","unbind","clean"]
3482 +# if "TARBALL" in self.settings or \
3483 +# "FETCH" not in self.settings:
3484 + if "FETCH" not in self.settings:
3485 + self.settings["action_sequence"].append("capture")
3486 + self.settings["action_sequence"].append("clear_autoresume")
3487 +
3488 + def set_use(self):
3489 + if self.settings["spec_prefix"]+"/use" in self.settings:
3490 + self.settings["use"]=\
3491 + self.settings[self.settings["spec_prefix"]+"/use"]
3492 + del self.settings[self.settings["spec_prefix"]+"/use"]
3493 + if "use" not in self.settings:
3494 + self.settings["use"]=""
3495 + if type(self.settings["use"])==types.StringType:
3496 + self.settings["use"]=self.settings["use"].split()
3497 +
3498 + # Force bindist when options ask for it
3499 + if "BINDIST" in self.settings:
3500 + self.settings["use"].append("bindist")
3501 +
3502 + def set_stage_path(self):
3503 + self.settings["stage_path"]=normpath(self.settings["chroot_path"])
3504 +
3505 + def set_mounts(self):
3506 + pass
3507 +
3508 + def set_packages(self):
3509 + pass
3510 +
3511 + def set_rm(self):
3512 + if self.settings["spec_prefix"]+"/rm" in self.settings:
3513 + if type(self.settings[self.settings["spec_prefix"]+\
3514 + "/rm"])==types.StringType:
3515 + self.settings[self.settings["spec_prefix"]+"/rm"]=\
3516 + self.settings[self.settings["spec_prefix"]+"/rm"].split()
3517 +
3518 + def set_linuxrc(self):
3519 + if self.settings["spec_prefix"]+"/linuxrc" in self.settings:
3520 + if type(self.settings[self.settings["spec_prefix"]+\
3521 + "/linuxrc"])==types.StringType:
3522 + self.settings["linuxrc"]=\
3523 + self.settings[self.settings["spec_prefix"]+"/linuxrc"]
3524 + del self.settings[self.settings["spec_prefix"]+"/linuxrc"]
3525 +
3526 + def set_busybox_config(self):
3527 + if self.settings["spec_prefix"]+"/busybox_config" in self.settings:
3528 + if type(self.settings[self.settings["spec_prefix"]+\
3529 + "/busybox_config"])==types.StringType:
3530 + self.settings["busybox_config"]=\
3531 + self.settings[self.settings["spec_prefix"]+"/busybox_config"]
3532 + del self.settings[self.settings["spec_prefix"]+"/busybox_config"]
3533 +
3534 + def set_portage_overlay(self):
3535 + if "portage_overlay" in self.settings:
3536 + if type(self.settings["portage_overlay"])==types.StringType:
3537 + self.settings["portage_overlay"]=\
3538 + self.settings["portage_overlay"].split()
3539 + print "portage_overlay directories are set to: \""+\
3540 + string.join(self.settings["portage_overlay"])+"\""
3541 +
3542 + def set_overlay(self):
3543 + if self.settings["spec_prefix"]+"/overlay" in self.settings:
3544 + if type(self.settings[self.settings["spec_prefix"]+\
3545 + "/overlay"])==types.StringType:
3546 + self.settings[self.settings["spec_prefix"]+"/overlay"]=\
3547 + self.settings[self.settings["spec_prefix"]+\
3548 + "/overlay"].split()
3549 +
3550 + def set_root_overlay(self):
3551 + if self.settings["spec_prefix"]+"/root_overlay" in self.settings:
3552 + if type(self.settings[self.settings["spec_prefix"]+\
3553 + "/root_overlay"])==types.StringType:
3554 + self.settings[self.settings["spec_prefix"]+"/root_overlay"]=\
3555 + self.settings[self.settings["spec_prefix"]+\
3556 + "/root_overlay"].split()
3557 +
3558 + def set_root_path(self):
3559 + """ ROOT= variable for emerges """
3560 + self.settings["root_path"]="/"
3561 +
3562 + def set_valid_build_kernel_vars(self,addlargs):
3563 + if "boot/kernel" in addlargs:
3564 + if type(addlargs["boot/kernel"])==types.StringType:
3565 + loopy=[addlargs["boot/kernel"]]
3566 + else:
3567 + loopy=addlargs["boot/kernel"]
3568 +
3569 + for x in loopy:
3570 + self.valid_values.append("boot/kernel/"+x+"/aliases")
3571 + self.valid_values.append("boot/kernel/"+x+"/config")
3572 + self.valid_values.append("boot/kernel/"+x+"/console")
3573 + self.valid_values.append("boot/kernel/"+x+"/extraversion")
3574 + self.valid_values.append("boot/kernel/"+x+"/gk_action")
3575 + self.valid_values.append("boot/kernel/"+x+"/gk_kernargs")
3576 + self.valid_values.append("boot/kernel/"+x+"/initramfs_overlay")
3577 + self.valid_values.append("boot/kernel/"+x+"/machine_type")
3578 + self.valid_values.append("boot/kernel/"+x+"/sources")
3579 + self.valid_values.append("boot/kernel/"+x+"/softlevel")
3580 + self.valid_values.append("boot/kernel/"+x+"/use")
3581 + self.valid_values.append("boot/kernel/"+x+"/packages")
3582 + if "boot/kernel/"+x+"/packages" in addlargs:
3583 + if type(addlargs["boot/kernel/"+x+\
3584 + "/packages"])==types.StringType:
3585 + addlargs["boot/kernel/"+x+"/packages"]=\
3586 + [addlargs["boot/kernel/"+x+"/packages"]]
3587 +
3588 + def set_build_kernel_vars(self):
3589 + if self.settings["spec_prefix"]+"/gk_mainargs" in self.settings:
3590 + self.settings["gk_mainargs"]=\
3591 + self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
3592 + del self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
3593 +
3594 + def kill_chroot_pids(self):
3595 + print "Checking for processes running in chroot and killing them."
3596 +
3597 + """
3598 + Force environment variables to be exported so script can see them
3599 + """
3600 + self.setup_environment()
3601 +
3602 + if os.path.exists(self.settings["sharedir"]+\
3603 + "/targets/support/kill-chroot-pids.sh"):
3604 + cmd("/bin/bash "+self.settings["sharedir"]+\
3605 + "/targets/support/kill-chroot-pids.sh",\
3606 + "kill-chroot-pids script failed.",env=self.env)
3607 +
3608 + def mount_safety_check(self):
3609 + mypath=self.settings["chroot_path"]
3610 +
3611 + """
3612 + Check and verify that none of our paths in mypath are mounted. We don't
3613 + want to clean up with things still mounted, and this allows us to check.
3614 + Returns 1 on ok, 0 on "something is still mounted" case.
3615 + """
3616 +
3617 + if not os.path.exists(mypath):
3618 + return
3619 +
3620 + for x in self.mounts:
3621 + if not os.path.exists(mypath + self.mountmap[x]):
3622 + continue
3623 +
3624 + if ismount(mypath +self.mountmap[x]):
3625 + """ Something is still mounted "" """
3626 + try:
3627 + print self.mountmap[x] + " is still mounted; performing auto-bind-umount...",
3628 + """ Try to umount stuff ourselves """
3629 + self.unbind()
3630 + if ismount(mypath + self.mountmap[x]):
3631 + raise CatalystError, "Auto-unbind failed for " + self.mountmap[x]
3632 + else:
3633 + print "Auto-unbind successful..."
3634 + except CatalystError:
3635 + raise CatalystError, "Unable to auto-unbind " + self.mountmap[x]
3636 +
3637 + def unpack(self):
3638 + unpack=True
3639 +
3640 + clst_unpack_hash=read_from_clst(self.settings["autoresume_path"]+\
3641 + "unpack")
3642 +
3643 + if "SEEDCACHE" in self.settings:
3644 + if os.path.isdir(self.settings["source_path"]):
3645 + """ SEEDCACHE Is a directory, use rsync """
3646 + unpack_cmd="rsync -a --delete "+self.settings["source_path"]+\
3647 + " "+self.settings["chroot_path"]
3648 + display_msg="\nStarting rsync from "+\
3649 + self.settings["source_path"]+"\nto "+\
3650 + self.settings["chroot_path"]+\
3651 + " (This may take some time) ...\n"
3652 + error_msg="Rsync of "+self.settings["source_path"]+" to "+\
3653 + self.settings["chroot_path"]+" failed."
3654 + else:
3655 + """ SEEDCACHE is a not a directory, try untar'ing """
3656 + print "Referenced SEEDCACHE does not appear to be a directory, trying to untar..."
3657 + display_msg="\nStarting tar extract from "+\
3658 + self.settings["source_path"]+"\nto "+\
3659 + self.settings["chroot_path"]+\
3660 + " (This may take some time) ...\n"
3661 + if "bz2" == self.settings["chroot_path"][-3:]:
3662 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
3663 + self.settings["chroot_path"]
3664 + else:
3665 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
3666 + self.settings["chroot_path"]
3667 + error_msg="Tarball extraction of "+\
3668 + self.settings["source_path"]+" to "+\
3669 + self.settings["chroot_path"]+" failed."
3670 + else:
3671 + """ No SEEDCACHE, use tar """
3672 + display_msg="\nStarting tar extract from "+\
3673 + self.settings["source_path"]+"\nto "+\
3674 + self.settings["chroot_path"]+\
3675 + " (This may take some time) ...\n"
3676 + if "bz2" == self.settings["chroot_path"][-3:]:
3677 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
3678 + self.settings["chroot_path"]
3679 + else:
3680 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
3681 + self.settings["chroot_path"]
3682 + error_msg="Tarball extraction of "+self.settings["source_path"]+\
3683 + " to "+self.settings["chroot_path"]+" failed."
3684 +
3685 + if "AUTORESUME" in self.settings:
3686 + if os.path.isdir(self.settings["source_path"]) \
3687 + and os.path.exists(self.settings["autoresume_path"]+"unpack"):
3688 + """ Autoresume is valid, SEEDCACHE is valid """
3689 + unpack=False
3690 + invalid_snapshot=False
3691 +
3692 + elif os.path.isfile(self.settings["source_path"]) \
3693 + and self.settings["source_path_hash"]==clst_unpack_hash:
3694 + """ Autoresume is valid, tarball is valid """
3695 + unpack=False
3696 + invalid_snapshot=True
3697 +
3698 + elif os.path.isdir(self.settings["source_path"]) \
3699 + and not os.path.exists(self.settings["autoresume_path"]+\
3700 + "unpack"):
3701 + """ Autoresume is invalid, SEEDCACHE """
3702 + unpack=True
3703 + invalid_snapshot=False
3704 +
3705 + elif os.path.isfile(self.settings["source_path"]) \
3706 + and self.settings["source_path_hash"]!=clst_unpack_hash:
3707 + """ Autoresume is invalid, tarball """
3708 + unpack=True
3709 + invalid_snapshot=True
3710 + else:
3711 + """ No autoresume, SEEDCACHE """
3712 + if "SEEDCACHE" in self.settings:
3713 + """ SEEDCACHE so let's run rsync and let it clean up """
3714 + if os.path.isdir(self.settings["source_path"]):
3715 + unpack=True
3716 + invalid_snapshot=False
3717 + elif os.path.isfile(self.settings["source_path"]):
3718 + """ Tarball so unpack and remove anything already there """
3719 + unpack=True
3720 + invalid_snapshot=True
3721 + """ No autoresume, no SEEDCACHE """
3722 + else:
3723 + """ Tarball so unpack and remove anything already there """
3724 + if os.path.isfile(self.settings["source_path"]):
3725 + unpack=True
3726 + invalid_snapshot=True
3727 + elif os.path.isdir(self.settings["source_path"]):
3728 + """ We should never reach this, so something is very wrong """
3729 + raise CatalystError,\
3730 + "source path is a dir but seedcache is not enabled"
3731 +
3732 + if unpack:
3733 + self.mount_safety_check()
3734 +
3735 + if invalid_snapshot:
3736 + if "AUTORESUME" in self.settings:
3737 + print "No Valid Resume point detected, cleaning up..."
3738 +
3739 + self.clear_autoresume()
3740 + self.clear_chroot()
3741 +
3742 + if not os.path.exists(self.settings["chroot_path"]):
3743 + os.makedirs(self.settings["chroot_path"])
3744 +
3745 + if not os.path.exists(self.settings["chroot_path"]+"/tmp"):
3746 + os.makedirs(self.settings["chroot_path"]+"/tmp",1777)
3747 +
3748 + if "PKGCACHE" in self.settings:
3749 + if not os.path.exists(self.settings["pkgcache_path"]):
3750 + os.makedirs(self.settings["pkgcache_path"],0755)
3751 +
3752 + if "KERNCACHE" in self.settings:
3753 + if not os.path.exists(self.settings["kerncache_path"]):
3754 + os.makedirs(self.settings["kerncache_path"],0755)
3755 +
3756 + print display_msg
3757 + cmd(unpack_cmd,error_msg,env=self.env)
3758 +
3759 + if "source_path_hash" in self.settings:
3760 + myf=open(self.settings["autoresume_path"]+"unpack","w")
3761 + myf.write(self.settings["source_path_hash"])
3762 + myf.close()
3763 + else:
3764 + touch(self.settings["autoresume_path"]+"unpack")
3765 + else:
3766 + print "Resume point detected, skipping unpack operation..."
3767 +
3768 + def unpack_snapshot(self):
3769 + unpack=True
3770 + snapshot_hash=read_from_clst(self.settings["autoresume_path"]+\
3771 + "unpack_portage")
3772 +
3773 + if "SNAPCACHE" in self.settings:
3774 + snapshot_cache_hash=\
3775 + read_from_clst(self.settings["snapshot_cache_path"]+\
3776 + "catalyst-hash")
3777 + destdir=self.settings["snapshot_cache_path"]
3778 + if "bz2" == self.settings["chroot_path"][-3:]:
3779 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["snapshot_path"]+" -C "+destdir
3780 + else:
3781 + unpack_cmd="tar xpf "+self.settings["snapshot_path"]+" -C "+destdir
3782 + unpack_errmsg="Error unpacking snapshot"
3783 + cleanup_msg="Cleaning up invalid snapshot cache at \n\t"+\
3784 + self.settings["snapshot_cache_path"]+\
3785 + " (This can take a long time)..."
3786 + cleanup_errmsg="Error removing existing snapshot cache directory."
3787 + self.snapshot_lock_object=self.snapcache_lock
3788 +
3789 + if self.settings["snapshot_path_hash"]==snapshot_cache_hash:
3790 + print "Valid snapshot cache, skipping unpack of portage tree..."
3791 + unpack=False
3792 + else:
3793 + destdir=normpath(self.settings["chroot_path"] + self.settings["portdir"])
3794 + cleanup_errmsg="Error removing existing snapshot directory."
3795 + cleanup_msg=\
3796 + "Cleaning up existing portage tree (This can take a long time)..."
3797 + if "bz2" == self.settings["chroot_path"][-3:]:
3798 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["snapshot_path"]+" -C "+\
3799 + self.settings["chroot_path"]+"/usr"
3800 + else:
3801 + unpack_cmd="tar xpf "+self.settings["snapshot_path"]+" -C "+\
3802 + self.settings["chroot_path"]+"/usr"
3803 + unpack_errmsg="Error unpacking snapshot"
3804 +
3805 + if "AUTORESUME" in self.settings \
3806 + and os.path.exists(self.settings["chroot_path"]+\
3807 + self.settings["portdir"]) \
3808 + and os.path.exists(self.settings["autoresume_path"]\
3809 + +"unpack_portage") \
3810 + and self.settings["snapshot_path_hash"] == snapshot_hash:
3811 + print \
3812 + "Valid Resume point detected, skipping unpack of portage tree..."
3813 + unpack=False
3814 +
3815 + if unpack:
3816 + if "SNAPCACHE" in self.settings:
3817 + self.snapshot_lock_object.write_lock()
3818 + if os.path.exists(destdir):
3819 + print cleanup_msg
3820 + cleanup_cmd="rm -rf "+destdir
3821 + cmd(cleanup_cmd,cleanup_errmsg,env=self.env)
3822 + if not os.path.exists(destdir):
3823 + os.makedirs(destdir,0755)
3824 +
3825 + print "Unpacking portage tree (This can take a long time) ..."
3826 + cmd(unpack_cmd,unpack_errmsg,env=self.env)
3827 +
3828 + if "SNAPCACHE" in self.settings:
3829 + myf=open(self.settings["snapshot_cache_path"]+"catalyst-hash","w")
3830 + myf.write(self.settings["snapshot_path_hash"])
3831 + myf.close()
3832 + else:
3833 + print "Setting snapshot autoresume point"
3834 + myf=open(self.settings["autoresume_path"]+"unpack_portage","w")
3835 + myf.write(self.settings["snapshot_path_hash"])
3836 + myf.close()
3837 +
3838 + if "SNAPCACHE" in self.settings:
3839 + self.snapshot_lock_object.unlock()
3840 +
3841 + def config_profile_link(self):
3842 + if "AUTORESUME" in self.settings \
3843 + and os.path.exists(self.settings["autoresume_path"]+\
3844 + "config_profile_link"):
3845 + print \
3846 + "Resume point detected, skipping config_profile_link operation..."
3847 + else:
3848 + # TODO: zmedico and I discussed making this a directory and pushing
3849 + # in a parent file, as well as other user-specified configuration.
3850 + print "Configuring profile link..."
3851 + cmd("rm -f "+self.settings["chroot_path"]+"/etc/portage/make.profile",\
3852 + "Error zapping profile link",env=self.env)
3853 + cmd("mkdir -p "+self.settings["chroot_path"]+"/etc/portage/")
3854 + cmd("ln -sf ../.." + self.settings["portdir"] + "/profiles/"+\
3855 + self.settings["target_profile"]+" "+\
3856 + self.settings["chroot_path"]+"/etc/portage/make.profile",\
3857 + "Error creating profile link",env=self.env)
3858 + touch(self.settings["autoresume_path"]+"config_profile_link")
3859 +
3860 + def setup_confdir(self):
3861 + if "AUTORESUME" in self.settings \
3862 + and os.path.exists(self.settings["autoresume_path"]+\
3863 + "setup_confdir"):
3864 + print "Resume point detected, skipping setup_confdir operation..."
3865 + else:
3866 + if "portage_confdir" in self.settings:
3867 + print "Configuring /etc/portage..."
3868 + cmd("rsync -a "+self.settings["portage_confdir"]+"/ "+\
3869 + self.settings["chroot_path"]+"/etc/portage/",\
3870 + "Error copying /etc/portage",env=self.env)
3871 + touch(self.settings["autoresume_path"]+"setup_confdir")
3872 +
3873 + def portage_overlay(self):
3874 + """ We copy the contents of our overlays to /usr/local/portage """
3875 + if "portage_overlay" in self.settings:
3876 + for x in self.settings["portage_overlay"]:
3877 + if os.path.exists(x):
3878 + print "Copying overlay dir " +x
3879 + cmd("mkdir -p "+self.settings["chroot_path"]+\
3880 + self.settings["local_overlay"],\
3881 + "Could not make portage_overlay dir",env=self.env)
3882 + cmd("cp -R "+x+"/* "+self.settings["chroot_path"]+\
3883 + self.settings["local_overlay"],\
3884 + "Could not copy portage_overlay",env=self.env)
3885 +
3886 + def root_overlay(self):
3887 + """ Copy over the root_overlay """
3888 + if self.settings["spec_prefix"]+"/root_overlay" in self.settings:
3889 + for x in self.settings[self.settings["spec_prefix"]+\
3890 + "/root_overlay"]:
3891 + if os.path.exists(x):
3892 + print "Copying root_overlay: "+x
3893 + cmd("rsync -a "+x+"/ "+\
3894 + self.settings["chroot_path"],\
3895 + self.settings["spec_prefix"]+"/root_overlay: "+x+\
3896 + " copy failed.",env=self.env)
3897 +
3898 + def base_dirs(self):
3899 + pass
3900 +
3901 + def bind(self):
3902 + for x in self.mounts:
3903 + if not os.path.exists(self.settings["chroot_path"] + self.mountmap[x]):
3904 + os.makedirs(self.settings["chroot_path"]+x,0755)
3905 +
3906 + if not os.path.exists(self.mountmap[x]):
3907 + if not self.mountmap[x] == "tmpfs":
3908 + os.makedirs(self.mountmap[x],0755)
3909 +
3910 + src=self.mountmap[x]
3911 + if "SNAPCACHE" in self.settings and x == "/usr/portage":
3912 + self.snapshot_lock_object.read_lock()
3913 + if os.uname()[0] == "FreeBSD":
3914 + if src == "/dev":
3915 + retval=os.system("mount -t devfs none " +
3916 + self.settings["chroot_path"] + src)
3917 + else:
3918 + retval=os.system("mount_nullfs " + src + " " +
3919 + self.settings["chroot_path"] + src)
3920 + else:
3921 + if src == "tmpfs":
3922 + if "var_tmpfs_portage" in self.settings:
3923 + retval=os.system("mount -t tmpfs -o size="+\
3924 + self.settings["var_tmpfs_portage"]+"G "+src+" "+\
3925 + self.settings["chroot_path"]+x)
3926 + else:
3927 + retval=os.system("mount --bind " + src + " " +
3928 + self.settings["chroot_path"] + src)
3929 + if retval!=0:
3930 + self.unbind()
3931 + raise CatalystError,"Couldn't bind mount " + src
3932 +
3933 + def unbind(self):
3934 + ouch=0
3935 + mypath=self.settings["chroot_path"]
3936 + myrevmounts=self.mounts[:]
3937 + myrevmounts.reverse()
3938 + """ Unmount in reverse order for nested bind-mounts """
3939 + for x in myrevmounts:
3940 + if not os.path.exists(mypath + self.mountmap[x]):
3941 + continue
3942 +
3943 + if not ismount(mypath + self.mountmap[x]):
3944 + continue
3945 +
3946 + retval=os.system("umount "+\
3947 + os.path.join(mypath, self.mountmap[x].lstrip(os.path.sep)))
3948 +
3949 + if retval!=0:
3950 + warn("First attempt to unmount: " + mypath +
3951 + self.mountmap[x] +" failed.")
3952 + warn("Killing any pids still running in the chroot")
3953 +
3954 + self.kill_chroot_pids()
3955 +
3956 + retval2=os.system("umount " + mypath + self.mountmap[x])
3957 + if retval2!=0:
3958 + ouch=1
3959 + warn("Couldn't umount bind mount: " + mypath + self.mountmap[x])
3960 +
3961 + if "SNAPCACHE" in self.settings and x == "/usr/portage":
3962 + try:
3963 + """
3964 + It's possible the snapshot lock object isn't created yet.
3965 + This is because mount safety check calls unbind before the
3966 + target is fully initialized
3967 + """
3968 + self.snapshot_lock_object.unlock()
3969 + except:
3970 + pass
3971 + if ouch:
3972 + """
3973 + if any bind mounts really failed, then we need to raise
3974 + this to potentially prevent an upcoming bash stage cleanup script
3975 + from wiping our bind mounts.
3976 + """
3977 + raise CatalystError,\
3978 + "Couldn't umount one or more bind-mounts; aborting for safety."
3979 +
3980 + def chroot_setup(self):
3981 + self.makeconf=read_makeconf(self.settings["chroot_path"]+\
3982 + "/etc/portage/make.conf")
3983 + self.override_cbuild()
3984 + self.override_chost()
3985 + self.override_cflags()
3986 + self.override_cxxflags()
3987 + self.override_ldflags()
3988 + if "AUTORESUME" in self.settings \
3989 + and os.path.exists(self.settings["autoresume_path"]+"chroot_setup"):
3990 + print "Resume point detected, skipping chroot_setup operation..."
3991 + else:
3992 + print "Setting up chroot..."
3993 +
3994 + #self.makeconf=read_makeconf(self.settings["chroot_path"]+"/etc/portage/make.conf")
3995 +
3996 + cmd("cp /etc/resolv.conf "+self.settings["chroot_path"]+"/etc",\
3997 + "Could not copy resolv.conf into place.",env=self.env)
3998 +
3999 + """ Copy over the envscript, if applicable """
4000 + if "ENVSCRIPT" in self.settings:
4001 + if not os.path.exists(self.settings["ENVSCRIPT"]):
4002 + raise CatalystError,\
4003 + "Can't find envscript "+self.settings["ENVSCRIPT"]
4004 +
4005 + print "\nWarning!!!!"
4006 + print "\tOverriding certain env variables may cause catastrophic failure."
4007 + print "\tIf your build fails look here first as the possible problem."
4008 + print "\tCatalyst assumes you know what you are doing when setting"
4009 + print "\t\tthese variables."
4010 + print "\tCatalyst Maintainers use VERY minimal envscripts if used at all"
4011 + print "\tYou have been warned\n"
4012 +
4013 + cmd("cp "+self.settings["ENVSCRIPT"]+" "+\
4014 + self.settings["chroot_path"]+"/tmp/envscript",\
4015 + "Could not copy envscript into place.",env=self.env)
4016 +
4017 + """
4018 + Copy over /etc/hosts from the host in case there are any
4019 + specialties in there
4020 + """
4021 + if os.path.exists(self.settings["chroot_path"]+"/etc/hosts"):
4022 + cmd("mv "+self.settings["chroot_path"]+"/etc/hosts "+\
4023 + self.settings["chroot_path"]+"/etc/hosts.catalyst",\
4024 + "Could not backup /etc/hosts",env=self.env)
4025 + cmd("cp /etc/hosts "+self.settings["chroot_path"]+"/etc/hosts",\
4026 + "Could not copy /etc/hosts",env=self.env)
4027 +
4028 + """ Modify and write out make.conf (for the chroot) """
4029 + cmd("rm -f "+self.settings["chroot_path"]+"/etc/portage/make.conf",\
4030 + "Could not remove "+self.settings["chroot_path"]+\
4031 + "/etc/portage/make.conf",env=self.env)
4032 + myf=open(self.settings["chroot_path"]+"/etc/portage/make.conf","w")
4033 + myf.write("# These settings were set by the catalyst build script that automatically\n# built this stage.\n")
4034 + myf.write("# Please consult /usr/share/portage/config/make.conf.example for a more\n# detailed example.\n")
4035 + if "CFLAGS" in self.settings:
4036 + myf.write('CFLAGS="'+self.settings["CFLAGS"]+'"\n')
4037 + if "CXXFLAGS" in self.settings:
4038 + if self.settings["CXXFLAGS"]!=self.settings["CFLAGS"]:
4039 + myf.write('CXXFLAGS="'+self.settings["CXXFLAGS"]+'"\n')
4040 + else:
4041 + myf.write('CXXFLAGS="${CFLAGS}"\n')
4042 + else:
4043 + myf.write('CXXFLAGS="${CFLAGS}"\n')
4044 +
4045 + if "LDFLAGS" in self.settings:
4046 + myf.write("# LDFLAGS is unsupported. USE AT YOUR OWN RISK!\n")
4047 + myf.write('LDFLAGS="'+self.settings["LDFLAGS"]+'"\n')
4048 + if "CBUILD" in self.settings:
4049 + myf.write("# This should not be changed unless you know exactly what you are doing. You\n# should probably be using a different stage, instead.\n")
4050 + myf.write('CBUILD="'+self.settings["CBUILD"]+'"\n')
4051 +
4052 + myf.write("# WARNING: Changing your CHOST is not something that should be done lightly.\n# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.\n")
4053 + myf.write('CHOST="'+self.settings["CHOST"]+'"\n')
4054 +
4055 + """ Figure out what our USE vars are for building """
4056 + myusevars=[]
4057 + if "HOSTUSE" in self.settings:
4058 + myusevars.extend(self.settings["HOSTUSE"])
4059 +
4060 + if "use" in self.settings:
4061 + myusevars.extend(self.settings["use"])
4062 +
4063 + if myusevars:
4064 + myf.write("# These are the USE flags that were used in addition to what is provided by the\n# profile used for building.\n")
4065 + myusevars = sorted(set(myusevars))
4066 + myf.write('USE="'+string.join(myusevars)+'"\n')
4067 + if '-*' in myusevars:
4068 + print "\nWarning!!! "
4069 + print "\tThe use of -* in "+self.settings["spec_prefix"]+\
4070 + "/use will cause portage to ignore"
4071 + print "\tpackage.use in the profile and portage_confdir. You've been warned!"
4072 +
4073 + myf.write('PORTDIR="%s"\n' % self.settings['portdir'])
4074 + myf.write('DISTDIR="%s"\n' % self.settings['distdir'])
4075 + myf.write('PKGDIR="%s"\n' % self.settings['packagedir'])
4076 +
4077 + """ Setup the portage overlay """
4078 + if "portage_overlay" in self.settings:
4079 + myf.write('PORTDIR_OVERLAY="/usr/local/portage"\n')
4080 +
4081 + myf.close()
4082 + cmd("cp "+self.settings["chroot_path"]+"/etc/portage/make.conf "+\
4083 + self.settings["chroot_path"]+"/etc/portage/make.conf.catalyst",\
4084 + "Could not backup /etc/portage/make.conf",env=self.env)
4085 + touch(self.settings["autoresume_path"]+"chroot_setup")
4086 +
4087 + def fsscript(self):
4088 + if "AUTORESUME" in self.settings \
4089 + and os.path.exists(self.settings["autoresume_path"]+"fsscript"):
4090 + print "Resume point detected, skipping fsscript operation..."
4091 + else:
4092 + if "fsscript" in self.settings:
4093 + if os.path.exists(self.settings["controller_file"]):
4094 + cmd("/bin/bash "+self.settings["controller_file"]+\
4095 + " fsscript","fsscript script failed.",env=self.env)
4096 + touch(self.settings["autoresume_path"]+"fsscript")
4097 +
4098 + def rcupdate(self):
4099 + if "AUTORESUME" in self.settings \
4100 + and os.path.exists(self.settings["autoresume_path"]+"rcupdate"):
4101 + print "Resume point detected, skipping rcupdate operation..."
4102 + else:
4103 + if os.path.exists(self.settings["controller_file"]):
4104 + cmd("/bin/bash "+self.settings["controller_file"]+" rc-update",\
4105 + "rc-update script failed.",env=self.env)
4106 + touch(self.settings["autoresume_path"]+"rcupdate")
4107 +
4108 + def clean(self):
4109 + if "AUTORESUME" in self.settings \
4110 + and os.path.exists(self.settings["autoresume_path"]+"clean"):
4111 + print "Resume point detected, skipping clean operation..."
4112 + else:
4113 + for x in self.settings["cleanables"]:
4114 + print "Cleaning chroot: "+x+"... "
4115 + cmd("rm -rf "+self.settings["destpath"]+x,"Couldn't clean "+\
4116 + x,env=self.env)
4117 +
4118 + """ Put /etc/hosts back into place """
4119 + if os.path.exists(self.settings["chroot_path"]+"/etc/hosts.catalyst"):
4120 + cmd("mv -f "+self.settings["chroot_path"]+"/etc/hosts.catalyst "+\
4121 + self.settings["chroot_path"]+"/etc/hosts",\
4122 + "Could not replace /etc/hosts",env=self.env)
4123 +
4124 + """ Remove our overlay """
4125 + if os.path.exists(self.settings["chroot_path"] + self.settings["local_overlay"]):
4126 + cmd("rm -rf " + self.settings["chroot_path"] + self.settings["local_overlay"],
4127 + "Could not remove " + self.settings["local_overlay"], env=self.env)
4128 + cmd("sed -i '/^PORTDIR_OVERLAY/d' "+self.settings["chroot_path"]+\
4129 + "/etc/portage/make.conf",\
4130 + "Could not remove PORTDIR_OVERLAY from make.conf",env=self.env)
4131 +
4132 + """ Clean up old and obsoleted files in /etc """
4133 + if os.path.exists(self.settings["stage_path"]+"/etc"):
4134 + cmd("find "+self.settings["stage_path"]+\
4135 + "/etc -maxdepth 1 -name \"*-\" | xargs rm -f",\
4136 + "Could not remove stray files in /etc",env=self.env)
4137 +
4138 + if os.path.exists(self.settings["controller_file"]):
4139 + cmd("/bin/bash "+self.settings["controller_file"]+" clean",\
4140 + "clean script failed.",env=self.env)
4141 + touch(self.settings["autoresume_path"]+"clean")
4142 +
4143 + def empty(self):
4144 + if "AUTORESUME" in self.settings \
4145 + and os.path.exists(self.settings["autoresume_path"]+"empty"):
4146 + print "Resume point detected, skipping empty operation..."
4147 + else:
4148 + if self.settings["spec_prefix"]+"/empty" in self.settings:
4149 + if type(self.settings[self.settings["spec_prefix"]+\
4150 + "/empty"])==types.StringType:
4151 + self.settings[self.settings["spec_prefix"]+"/empty"]=\
4152 + self.settings[self.settings["spec_prefix"]+\
4153 + "/empty"].split()
4154 + for x in self.settings[self.settings["spec_prefix"]+"/empty"]:
4155 + myemp=self.settings["destpath"]+x
4156 + if not os.path.isdir(myemp) or os.path.islink(myemp):
4157 + print x,"not a directory or does not exist, skipping 'empty' operation."
4158 + continue
4159 + print "Emptying directory",x
4160 + """
4161 + stat the dir, delete the dir, recreate the dir and set
4162 + the proper perms and ownership
4163 + """
4164 + mystat=os.stat(myemp)
4165 + shutil.rmtree(myemp)
4166 + os.makedirs(myemp,0755)
4167 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
4168 + os.chmod(myemp,mystat[ST_MODE])
4169 + touch(self.settings["autoresume_path"]+"empty")
4170 +
4171 + def remove(self):
4172 + if "AUTORESUME" in self.settings \
4173 + and os.path.exists(self.settings["autoresume_path"]+"remove"):
4174 + print "Resume point detected, skipping remove operation..."
4175 + else:
4176 + if self.settings["spec_prefix"]+"/rm" in self.settings:
4177 + for x in self.settings[self.settings["spec_prefix"]+"/rm"]:
4178 + """
4179 + We're going to shell out for all these cleaning
4180 + operations, so we get easy glob handling.
4181 + """
4182 + print "livecd: removing "+x
4183 + os.system("rm -rf "+self.settings["chroot_path"]+x)
4184 + try:
4185 + if os.path.exists(self.settings["controller_file"]):
4186 + cmd("/bin/bash "+self.settings["controller_file"]+\
4187 + " clean","Clean failed.",env=self.env)
4188 + touch(self.settings["autoresume_path"]+"remove")
4189 + except:
4190 + self.unbind()
4191 + raise
4192 +
4193 + def preclean(self):
4194 + if "AUTORESUME" in self.settings \
4195 + and os.path.exists(self.settings["autoresume_path"]+"preclean"):
4196 + print "Resume point detected, skipping preclean operation..."
4197 + else:
4198 + try:
4199 + if os.path.exists(self.settings["controller_file"]):
4200 + cmd("/bin/bash "+self.settings["controller_file"]+\
4201 + " preclean","preclean script failed.",env=self.env)
4202 + touch(self.settings["autoresume_path"]+"preclean")
4203 +
4204 + except:
4205 + self.unbind()
4206 + raise CatalystError, "Build failed, could not execute preclean"
4207 +
4208 + def capture(self):
4209 + if "AUTORESUME" in self.settings \
4210 + and os.path.exists(self.settings["autoresume_path"]+"capture"):
4211 + print "Resume point detected, skipping capture operation..."
4212 + else:
4213 + """ Capture target in a tarball """
4214 + mypath=self.settings["target_path"].split("/")
4215 + """ Remove filename from path """
4216 + mypath=string.join(mypath[:-1],"/")
4217 +
4218 + """ Now make sure path exists """
4219 + if not os.path.exists(mypath):
4220 + os.makedirs(mypath)
4221 +
4222 + print "Creating stage tarball..."
4223 +
4224 + cmd("tar -I lbzip2 -cpf "+self.settings["target_path"]+" -C "+\
4225 + self.settings["stage_path"]+" .",\
4226 + "Couldn't create stage tarball",env=self.env)
4227 +
4228 + self.gen_contents_file(self.settings["target_path"])
4229 + self.gen_digest_file(self.settings["target_path"])
4230 +
4231 + touch(self.settings["autoresume_path"]+"capture")
4232 +
4233 + def run_local(self):
4234 + if "AUTORESUME" in self.settings \
4235 + and os.path.exists(self.settings["autoresume_path"]+"run_local"):
4236 + print "Resume point detected, skipping run_local operation..."
4237 + else:
4238 + try:
4239 + if os.path.exists(self.settings["controller_file"]):
4240 + cmd("/bin/bash "+self.settings["controller_file"]+" run",\
4241 + "run script failed.",env=self.env)
4242 + touch(self.settings["autoresume_path"]+"run_local")
4243 +
4244 + except CatalystError:
4245 + self.unbind()
4246 + raise CatalystError,"Stage build aborting due to error."
4247 +
4248 + def setup_environment(self):
4249 + """
4250 + Modify the current environment. This is an ugly hack that should be
4251 + fixed. We need this to use the os.system() call since we can't
4252 + specify our own environ
4253 + """
4254 + for x in self.settings.keys():
4255 + """ Sanitize var names by doing "s|/-.|_|g" """
4256 + varname="clst_"+string.replace(x,"/","_")
4257 + varname=string.replace(varname,"-","_")
4258 + varname=string.replace(varname,".","_")
4259 + if type(self.settings[x])==types.StringType:
4260 + """ Prefix to prevent namespace clashes """
4261 + #os.environ[varname]=self.settings[x]
4262 + self.env[varname]=self.settings[x]
4263 + elif type(self.settings[x])==types.ListType:
4264 + #os.environ[varname]=string.join(self.settings[x])
4265 + self.env[varname]=string.join(self.settings[x])
4266 + elif type(self.settings[x])==types.BooleanType:
4267 + if self.settings[x]:
4268 + self.env[varname]="true"
4269 + else:
4270 + self.env[varname]="false"
4271 + if "makeopts" in self.settings:
4272 + self.env["MAKEOPTS"]=self.settings["makeopts"]
4273 +
4274 + def run(self):
4275 + self.chroot_lock.write_lock()
4276 +
4277 + """ Kill any pids in the chroot "" """
4278 + self.kill_chroot_pids()
4279 +
4280 + """ Check for mounts right away and abort if we cannot unmount them """
4281 + self.mount_safety_check()
4282 +
4283 + if "CLEAR_AUTORESUME" in self.settings:
4284 + self.clear_autoresume()
4285 +
4286 + if "PURGETMPONLY" in self.settings:
4287 + self.purge()
4288 + return
4289 +
4290 + if "PURGEONLY" in self.settings:
4291 + self.purge()
4292 + return
4293 +
4294 + if "PURGE" in self.settings:
4295 + self.purge()
4296 +
4297 + for x in self.settings["action_sequence"]:
4298 + print "--- Running action sequence: "+x
4299 + sys.stdout.flush()
4300 + try:
4301 + apply(getattr(self,x))
4302 + except:
4303 + self.mount_safety_check()
4304 + raise
4305 +
4306 + self.chroot_lock.unlock()
4307 +
4308 + def unmerge(self):
4309 + if "AUTORESUME" in self.settings \
4310 + and os.path.exists(self.settings["autoresume_path"]+"unmerge"):
4311 + print "Resume point detected, skipping unmerge operation..."
4312 + else:
4313 + if self.settings["spec_prefix"]+"/unmerge" in self.settings:
4314 + if type(self.settings[self.settings["spec_prefix"]+\
4315 + "/unmerge"])==types.StringType:
4316 + self.settings[self.settings["spec_prefix"]+"/unmerge"]=\
4317 + [self.settings[self.settings["spec_prefix"]+"/unmerge"]]
4318 + myunmerge=\
4319 + self.settings[self.settings["spec_prefix"]+"/unmerge"][:]
4320 +
4321 + for x in range(0,len(myunmerge)):
4322 + """
4323 + Surround args with quotes for passing to bash, allows
4324 + things like "<" to remain intact
4325 + """
4326 + myunmerge[x]="'"+myunmerge[x]+"'"
4327 + myunmerge=string.join(myunmerge)
4328 +
4329 + """ Before cleaning, unmerge stuff """
4330 + try:
4331 + cmd("/bin/bash "+self.settings["controller_file"]+\
4332 + " unmerge "+ myunmerge,"Unmerge script failed.",\
4333 + env=self.env)
4334 + print "unmerge shell script"
4335 + except CatalystError:
4336 + self.unbind()
4337 + raise
4338 + touch(self.settings["autoresume_path"]+"unmerge")
4339 +
4340 + def target_setup(self):
4341 + if "AUTORESUME" in self.settings \
4342 + and os.path.exists(self.settings["autoresume_path"]+"target_setup"):
4343 + print "Resume point detected, skipping target_setup operation..."
4344 + else:
4345 + print "Setting up filesystems per filesystem type"
4346 + cmd("/bin/bash "+self.settings["controller_file"]+\
4347 + " target_image_setup "+ self.settings["target_path"],\
4348 + "target_image_setup script failed.",env=self.env)
4349 + touch(self.settings["autoresume_path"]+"target_setup")
4350 +
4351 + def setup_overlay(self):
4352 + if "AUTORESUME" in self.settings \
4353 + and os.path.exists(self.settings["autoresume_path"]+"setup_overlay"):
4354 + print "Resume point detected, skipping setup_overlay operation..."
4355 + else:
4356 + if self.settings["spec_prefix"]+"/overlay" in self.settings:
4357 + for x in self.settings[self.settings["spec_prefix"]+"/overlay"]:
4358 + if os.path.exists(x):
4359 + cmd("rsync -a "+x+"/ "+\
4360 + self.settings["target_path"],\
4361 + self.settings["spec_prefix"]+"overlay: "+x+\
4362 + " copy failed.",env=self.env)
4363 + touch(self.settings["autoresume_path"]+"setup_overlay")
4364 +
4365 + def create_iso(self):
4366 + if "AUTORESUME" in self.settings \
4367 + and os.path.exists(self.settings["autoresume_path"]+"create_iso"):
4368 + print "Resume point detected, skipping create_iso operation..."
4369 + else:
4370 + """ Create the ISO """
4371 + if "iso" in self.settings:
4372 + cmd("/bin/bash "+self.settings["controller_file"]+" iso "+\
4373 + self.settings["iso"],"ISO creation script failed.",\
4374 + env=self.env)
4375 + self.gen_contents_file(self.settings["iso"])
4376 + self.gen_digest_file(self.settings["iso"])
4377 + touch(self.settings["autoresume_path"]+"create_iso")
4378 + else:
4379 + print "WARNING: livecd/iso was not defined."
4380 + print "An ISO Image will not be created."
4381 +
4382 + def build_packages(self):
4383 + if "AUTORESUME" in self.settings \
4384 + and os.path.exists(self.settings["autoresume_path"]+\
4385 + "build_packages"):
4386 + print "Resume point detected, skipping build_packages operation..."
4387 + else:
4388 + if self.settings["spec_prefix"]+"/packages" in self.settings:
4389 + if "AUTORESUME" in self.settings \
4390 + and os.path.exists(self.settings["autoresume_path"]+\
4391 + "build_packages"):
4392 + print "Resume point detected, skipping build_packages operation..."
4393 + else:
4394 + mypack=\
4395 + list_bashify(self.settings[self.settings["spec_prefix"]\
4396 + +"/packages"])
4397 + try:
4398 + cmd("/bin/bash "+self.settings["controller_file"]+\
4399 + " build_packages "+mypack,\
4400 + "Error in attempt to build packages",env=self.env)
4401 + touch(self.settings["autoresume_path"]+"build_packages")
4402 + except CatalystError:
4403 + self.unbind()
4404 + raise CatalystError,self.settings["spec_prefix"]+\
4405 + "build aborting due to error."
4406 +
4407 + def build_kernel(self):
4408 + "Build all configured kernels"
4409 + if "AUTORESUME" in self.settings \
4410 + and os.path.exists(self.settings["autoresume_path"]+"build_kernel"):
4411 + print "Resume point detected, skipping build_kernel operation..."
4412 + else:
4413 + if "boot/kernel" in self.settings:
4414 + try:
4415 + mynames=self.settings["boot/kernel"]
4416 + if type(mynames)==types.StringType:
4417 + mynames=[mynames]
4418 + """
4419 + Execute the script that sets up the kernel build environment
4420 + """
4421 + cmd("/bin/bash "+self.settings["controller_file"]+\
4422 + " pre-kmerge ","Runscript pre-kmerge failed",\
4423 + env=self.env)
4424 + for kname in mynames:
4425 + self._build_kernel(kname=kname)
4426 + touch(self.settings["autoresume_path"]+"build_kernel")
4427 + except CatalystError:
4428 + self.unbind()
4429 + raise CatalystError,\
4430 + "build aborting due to kernel build error."
4431 +
4432 + def _build_kernel(self, kname):
4433 + "Build a single configured kernel by name"
4434 + if "AUTORESUME" in self.settings \
4435 + and os.path.exists(self.settings["autoresume_path"]\
4436 + +"build_kernel_"+kname):
4437 + print "Resume point detected, skipping build_kernel for "+kname+" operation..."
4438 + return
4439 + self._copy_kernel_config(kname=kname)
4440 +
4441 + """
4442 + If we need to pass special options to the bootloader
4443 + for this kernel put them into the environment
4444 + """
4445 + if "boot/kernel/"+kname+"/kernelopts" in self.settings:
4446 + myopts=self.settings["boot/kernel/"+kname+\
4447 + "/kernelopts"]
4448 +
4449 + if type(myopts) != types.StringType:
4450 + myopts = string.join(myopts)
4451 + self.env[kname+"_kernelopts"]=myopts
4452 +
4453 + else:
4454 + self.env[kname+"_kernelopts"]=""
4455 +
4456 + if "boot/kernel/"+kname+"/extraversion" not in self.settings:
4457 + self.settings["boot/kernel/"+kname+\
4458 + "/extraversion"]=""
4459 +
4460 + self.env["clst_kextraversion"]=\
4461 + self.settings["boot/kernel/"+kname+\
4462 + "/extraversion"]
4463 +
4464 + self._copy_initramfs_overlay(kname=kname)
4465 +
4466 + """ Execute the script that builds the kernel """
4467 + cmd("/bin/bash "+self.settings["controller_file"]+\
4468 + " kernel "+kname,\
4469 + "Runscript kernel build failed",env=self.env)
4470 +
4471 + if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings:
4472 + if os.path.exists(self.settings["chroot_path"]+\
4473 + "/tmp/initramfs_overlay/"):
4474 + print "Cleaning up temporary overlay dir"
4475 + cmd("rm -R "+self.settings["chroot_path"]+\
4476 + "/tmp/initramfs_overlay/",env=self.env)
4477 +
4478 + touch(self.settings["autoresume_path"]+\
4479 + "build_kernel_"+kname)
4480 +
4481 + """
4482 + Execute the script that cleans up the kernel build
4483 + environment
4484 + """
4485 + cmd("/bin/bash "+self.settings["controller_file"]+\
4486 + " post-kmerge ",
4487 + "Runscript post-kmerge failed",env=self.env)
4488 +
4489 + def _copy_kernel_config(self, kname):
4490 + if "boot/kernel/"+kname+"/config" in self.settings:
4491 + if not os.path.exists(self.settings["boot/kernel/"+kname+"/config"]):
4492 + self.unbind()
4493 + raise CatalystError,\
4494 + "Can't find kernel config: "+\
4495 + self.settings["boot/kernel/"+kname+\
4496 + "/config"]
4497 +
4498 + try:
4499 + cmd("cp "+self.settings["boot/kernel/"+kname+\
4500 + "/config"]+" "+\
4501 + self.settings["chroot_path"]+"/var/tmp/"+\
4502 + kname+".config",\
4503 + "Couldn't copy kernel config: "+\
4504 + self.settings["boot/kernel/"+kname+\
4505 + "/config"],env=self.env)
4506 +
4507 + except CatalystError:
4508 + self.unbind()
4509 +
4510 + def _copy_initramfs_overlay(self, kname):
4511 + if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings:
4512 + if os.path.exists(self.settings["boot/kernel/"+\
4513 + kname+"/initramfs_overlay"]):
4514 + print "Copying initramfs_overlay dir "+\
4515 + self.settings["boot/kernel/"+kname+\
4516 + "/initramfs_overlay"]
4517 +
4518 + cmd("mkdir -p "+\
4519 + self.settings["chroot_path"]+\
4520 + "/tmp/initramfs_overlay/"+\
4521 + self.settings["boot/kernel/"+kname+\
4522 + "/initramfs_overlay"],env=self.env)
4523 +
4524 + cmd("cp -R "+self.settings["boot/kernel/"+\
4525 + kname+"/initramfs_overlay"]+"/* "+\
4526 + self.settings["chroot_path"]+\
4527 + "/tmp/initramfs_overlay/"+\
4528 + self.settings["boot/kernel/"+kname+\
4529 + "/initramfs_overlay"],env=self.env)
4530 +
4531 + def bootloader(self):
4532 + if "AUTORESUME" in self.settings \
4533 + and os.path.exists(self.settings["autoresume_path"]+"bootloader"):
4534 + print "Resume point detected, skipping bootloader operation..."
4535 + else:
4536 + try:
4537 + cmd("/bin/bash "+self.settings["controller_file"]+\
4538 + " bootloader " + self.settings["target_path"],\
4539 + "Bootloader script failed.",env=self.env)
4540 + touch(self.settings["autoresume_path"]+"bootloader")
4541 + except CatalystError:
4542 + self.unbind()
4543 + raise CatalystError,"Script aborting due to error."
4544 +
4545 + def livecd_update(self):
4546 + if "AUTORESUME" in self.settings \
4547 + and os.path.exists(self.settings["autoresume_path"]+\
4548 + "livecd_update"):
4549 + print "Resume point detected, skipping build_packages operation..."
4550 + else:
4551 + try:
4552 + cmd("/bin/bash "+self.settings["controller_file"]+\
4553 + " livecd-update","livecd-update failed.",env=self.env)
4554 + touch(self.settings["autoresume_path"]+"livecd_update")
4555 +
4556 + except CatalystError:
4557 + self.unbind()
4558 + raise CatalystError,"build aborting due to livecd_update error."
4559 +
4560 + def clear_chroot(self):
4561 + myemp=self.settings["chroot_path"]
4562 + if os.path.isdir(myemp):
4563 + print "Emptying directory",myemp
4564 + """
4565 + stat the dir, delete the dir, recreate the dir and set
4566 + the proper perms and ownership
4567 + """
4568 + mystat=os.stat(myemp)
4569 + #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
4570 + """ There's no easy way to change flags recursively in python """
4571 + if os.uname()[0] == "FreeBSD":
4572 + os.system("chflags -R noschg "+myemp)
4573 + shutil.rmtree(myemp)
4574 + os.makedirs(myemp,0755)
4575 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
4576 + os.chmod(myemp,mystat[ST_MODE])
4577 +
4578 + def clear_packages(self):
4579 + if "PKGCACHE" in self.settings:
4580 + print "purging the pkgcache ..."
4581 +
4582 + myemp=self.settings["pkgcache_path"]
4583 + if os.path.isdir(myemp):
4584 + print "Emptying directory",myemp
4585 + """
4586 + stat the dir, delete the dir, recreate the dir and set
4587 + the proper perms and ownership
4588 + """
4589 + mystat=os.stat(myemp)
4590 + #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
4591 + shutil.rmtree(myemp)
4592 + os.makedirs(myemp,0755)
4593 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
4594 + os.chmod(myemp,mystat[ST_MODE])
4595 +
4596 + def clear_kerncache(self):
4597 + if "KERNCACHE" in self.settings:
4598 + print "purging the kerncache ..."
4599 +
4600 + myemp=self.settings["kerncache_path"]
4601 + if os.path.isdir(myemp):
4602 + print "Emptying directory",myemp
4603 + """
4604 + stat the dir, delete the dir, recreate the dir and set
4605 + the proper perms and ownership
4606 + """
4607 + mystat=os.stat(myemp)
4608 + #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
4609 + shutil.rmtree(myemp)
4610 + os.makedirs(myemp,0755)
4611 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
4612 + os.chmod(myemp,mystat[ST_MODE])
4613 +
4614 + def clear_autoresume(self):
4615 + """ Clean resume points since they are no longer needed """
4616 + if "AUTORESUME" in self.settings:
4617 + print "Removing AutoResume Points: ..."
4618 + myemp=self.settings["autoresume_path"]
4619 + if os.path.isdir(myemp):
4620 + if "AUTORESUME" in self.settings:
4621 + print "Emptying directory",myemp
4622 + """
4623 + stat the dir, delete the dir, recreate the dir and set
4624 + the proper perms and ownership
4625 + """
4626 + mystat=os.stat(myemp)
4627 + if os.uname()[0] == "FreeBSD":
4628 + cmd("chflags -R noschg "+myemp,\
4629 + "Could not remove immutable flag for file "\
4630 + +myemp)
4631 + #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env-self.env)
4632 + shutil.rmtree(myemp)
4633 + os.makedirs(myemp,0755)
4634 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
4635 + os.chmod(myemp,mystat[ST_MODE])
4636 +
4637 + def gen_contents_file(self,file):
4638 + if os.path.exists(file+".CONTENTS"):
4639 + os.remove(file+".CONTENTS")
4640 + if "contents" in self.settings:
4641 + if os.path.exists(file):
4642 + myf=open(file+".CONTENTS","w")
4643 + keys={}
4644 + for i in self.settings["contents"].split():
4645 + keys[i]=1
4646 + array=keys.keys()
4647 + array.sort()
4648 + for j in array:
4649 + contents=generate_contents(file,contents_function=j,\
4650 + verbose="VERBOSE" in self.settings)
4651 + if contents:
4652 + myf.write(contents)
4653 + myf.close()
4654 +
4655 + def gen_digest_file(self,file):
4656 + if os.path.exists(file+".DIGESTS"):
4657 + os.remove(file+".DIGESTS")
4658 + if "digests" in self.settings:
4659 + if os.path.exists(file):
4660 + myf=open(file+".DIGESTS","w")
4661 + keys={}
4662 + for i in self.settings["digests"].split():
4663 + keys[i]=1
4664 + array=keys.keys()
4665 + array.sort()
4666 + for f in [file, file+'.CONTENTS']:
4667 + if os.path.exists(f):
4668 + if "all" in array:
4669 + for k in hash_map.keys():
4670 + hash=generate_hash(f,hash_function=k,verbose=\
4671 + "VERBOSE" in self.settings)
4672 + myf.write(hash)
4673 + else:
4674 + for j in array:
4675 + hash=generate_hash(f,hash_function=j,verbose=\
4676 + "VERBOSE" in self.settings)
4677 + myf.write(hash)
4678 + myf.close()
4679 +
4680 + def purge(self):
4681 + countdown(10,"Purging Caches ...")
4682 + if any(k in self.settings for k in ("PURGE","PURGEONLY","PURGETMPONLY")):
4683 + print "clearing autoresume ..."
4684 + self.clear_autoresume()
4685 +
4686 + print "clearing chroot ..."
4687 + self.clear_chroot()
4688 +
4689 + if "PURGETMPONLY" not in self.settings:
4690 + print "clearing package cache ..."
4691 + self.clear_packages()
4692 +
4693 + print "clearing kerncache ..."
4694 + self.clear_kerncache()
4695 +
4696 +# vim: ts=4 sw=4 sta et sts=4 ai
4697 diff --git a/catalyst/targets/generic_target.py b/catalyst/targets/generic_target.py
4698 new file mode 100644
4699 index 0000000..de51994
4700 --- /dev/null
4701 +++ b/catalyst/targets/generic_target.py
4702 @@ -0,0 +1,11 @@
4703 +from catalyst.support import *
4704 +
4705 +class generic_target:
4706 + """
4707 + The toplevel class for generic_stage_target. This is about as generic as we get.
4708 + """
4709 + def __init__(self,myspec,addlargs):
4710 + addl_arg_parse(myspec,addlargs,self.required_values,self.valid_values)
4711 + self.settings=myspec
4712 + self.env={}
4713 + self.env["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin"
4714 diff --git a/catalyst/targets/grp_target.py b/catalyst/targets/grp_target.py
4715 new file mode 100644
4716 index 0000000..8e70042
4717 --- /dev/null
4718 +++ b/catalyst/targets/grp_target.py
4719 @@ -0,0 +1,118 @@
4720 +"""
4721 +Gentoo Reference Platform (GRP) target
4722 +"""
4723 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
4724 +
4725 +import os,types,glob
4726 +from catalyst.support import *
4727 +from generic_stage_target import *
4728 +
4729 +class grp_target(generic_stage_target):
4730 + """
4731 + The builder class for GRP (Gentoo Reference Platform) builds.
4732 + """
4733 + def __init__(self,spec,addlargs):
4734 + self.required_values=["version_stamp","target","subarch",\
4735 + "rel_type","profile","snapshot","source_subpath"]
4736 +
4737 + self.valid_values=self.required_values[:]
4738 + self.valid_values.extend(["grp/use"])
4739 + if "grp" not in addlargs:
4740 + raise CatalystError,"Required value \"grp\" not specified in spec."
4741 +
4742 + self.required_values.extend(["grp"])
4743 + if type(addlargs["grp"])==types.StringType:
4744 + addlargs["grp"]=[addlargs["grp"]]
4745 +
4746 + if "grp/use" in addlargs:
4747 + if type(addlargs["grp/use"])==types.StringType:
4748 + addlargs["grp/use"]=[addlargs["grp/use"]]
4749 +
4750 + for x in addlargs["grp"]:
4751 + self.required_values.append("grp/"+x+"/packages")
4752 + self.required_values.append("grp/"+x+"/type")
4753 +
4754 + generic_stage_target.__init__(self,spec,addlargs)
4755 +
4756 + def set_target_path(self):
4757 + self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
4758 + if "AUTORESUME" in self.settings \
4759 + and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
4760 + print "Resume point detected, skipping target path setup operation..."
4761 + else:
4762 + # first clean up any existing target stuff
4763 + #if os.path.isdir(self.settings["target_path"]):
4764 + #cmd("rm -rf "+self.settings["target_path"],
4765 + #"Could not remove existing directory: "+self.settings["target_path"],env=self.env)
4766 + if not os.path.exists(self.settings["target_path"]):
4767 + os.makedirs(self.settings["target_path"])
4768 +
4769 + touch(self.settings["autoresume_path"]+"setup_target_path")
4770 +
4771 + def run_local(self):
4772 + for pkgset in self.settings["grp"]:
4773 + # example call: "grp.sh run pkgset cd1 xmms vim sys-apps/gleep"
4774 + mypackages=list_bashify(self.settings["grp/"+pkgset+"/packages"])
4775 + try:
4776 + cmd("/bin/bash "+self.settings["controller_file"]+" run "+self.settings["grp/"+pkgset+"/type"]\
4777 + +" "+pkgset+" "+mypackages,env=self.env)
4778 +
4779 + except CatalystError:
4780 + self.unbind()
4781 + raise CatalystError,"GRP build aborting due to error."
4782 +
4783 + def set_use(self):
4784 + generic_stage_target.set_use(self)
4785 + if "BINDIST" in self.settings:
4786 + if "use" in self.settings:
4787 + self.settings["use"].append("bindist")
4788 + else:
4789 + self.settings["use"]=["bindist"]
4790 +
4791 + def set_mounts(self):
4792 + self.mounts.append("/tmp/grp")
4793 + self.mountmap["/tmp/grp"]=self.settings["target_path"]
4794 +
4795 + def generate_digests(self):
4796 + for pkgset in self.settings["grp"]:
4797 + if self.settings["grp/"+pkgset+"/type"] == "pkgset":
4798 + destdir=normpath(self.settings["target_path"]+"/"+pkgset+"/All")
4799 + print "Digesting files in the pkgset....."
4800 + digests=glob.glob(destdir+'/*.DIGESTS')
4801 + for i in digests:
4802 + if os.path.exists(i):
4803 + os.remove(i)
4804 +
4805 + files=os.listdir(destdir)
4806 + #ignore files starting with '.' using list comprehension
4807 + files=[filename for filename in files if filename[0] != '.']
4808 + for i in files:
4809 + if os.path.isfile(normpath(destdir+"/"+i)):
4810 + self.gen_contents_file(normpath(destdir+"/"+i))
4811 + self.gen_digest_file(normpath(destdir+"/"+i))
4812 + else:
4813 + destdir=normpath(self.settings["target_path"]+"/"+pkgset)
4814 + print "Digesting files in the srcset....."
4815 +
4816 + digests=glob.glob(destdir+'/*.DIGESTS')
4817 + for i in digests:
4818 + if os.path.exists(i):
4819 + os.remove(i)
4820 +
4821 + files=os.listdir(destdir)
4822 + #ignore files starting with '.' using list comprehension
4823 + files=[filename for filename in files if filename[0] != '.']
4824 + for i in files:
4825 + if os.path.isfile(normpath(destdir+"/"+i)):
4826 + #self.gen_contents_file(normpath(destdir+"/"+i))
4827 + self.gen_digest_file(normpath(destdir+"/"+i))
4828 +
4829 + def set_action_sequence(self):
4830 + self.settings["action_sequence"]=["unpack","unpack_snapshot",\
4831 + "config_profile_link","setup_confdir","portage_overlay","bind","chroot_setup",\
4832 + "setup_environment","run_local","unbind",\
4833 + "generate_digests","clear_autoresume"]
4834 +
4835 +def register(foo):
4836 + foo.update({"grp":grp_target})
4837 + return foo
4838 diff --git a/catalyst/targets/livecd_stage1_target.py b/catalyst/targets/livecd_stage1_target.py
4839 new file mode 100644
4840 index 0000000..ac846ec
4841 --- /dev/null
4842 +++ b/catalyst/targets/livecd_stage1_target.py
4843 @@ -0,0 +1,75 @@
4844 +"""
4845 +LiveCD stage1 target
4846 +"""
4847 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
4848 +
4849 +from catalyst.support import *
4850 +from generic_stage_target import *
4851 +
4852 +class livecd_stage1_target(generic_stage_target):
4853 + """
4854 + Builder class for LiveCD stage1.
4855 + """
4856 + def __init__(self,spec,addlargs):
4857 + self.required_values=["livecd/packages"]
4858 + self.valid_values=self.required_values[:]
4859 +
4860 + self.valid_values.extend(["livecd/use"])
4861 + generic_stage_target.__init__(self,spec,addlargs)
4862 +
4863 + def set_action_sequence(self):
4864 + self.settings["action_sequence"]=["unpack","unpack_snapshot",\
4865 + "config_profile_link","setup_confdir","portage_overlay",\
4866 + "bind","chroot_setup","setup_environment","build_packages",\
4867 + "unbind", "clean","clear_autoresume"]
4868 +
4869 + def set_target_path(self):
4870 + self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"])
4871 + if "AUTORESUME" in self.settings \
4872 + and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
4873 + print "Resume point detected, skipping target path setup operation..."
4874 + else:
4875 + # first clean up any existing target stuff
4876 + if os.path.exists(self.settings["target_path"]):
4877 + cmd("rm -rf "+self.settings["target_path"],\
4878 + "Could not remove existing directory: "+self.settings["target_path"],env=self.env)
4879 + touch(self.settings["autoresume_path"]+"setup_target_path")
4880 +
4881 + if not os.path.exists(self.settings["target_path"]):
4882 + os.makedirs(self.settings["target_path"])
4883 +
4884 + def set_target_path(self):
4885 + pass
4886 +
4887 + def set_spec_prefix(self):
4888 + self.settings["spec_prefix"]="livecd"
4889 +
4890 + def set_use(self):
4891 + generic_stage_target.set_use(self)
4892 + if "use" in self.settings:
4893 + self.settings["use"].append("livecd")
4894 + if "BINDIST" in self.settings:
4895 + self.settings["use"].append("bindist")
4896 + else:
4897 + self.settings["use"]=["livecd"]
4898 + if "BINDIST" in self.settings:
4899 + self.settings["use"].append("bindist")
4900 +
4901 + def set_packages(self):
4902 + generic_stage_target.set_packages(self)
4903 + if self.settings["spec_prefix"]+"/packages" in self.settings:
4904 + if type(self.settings[self.settings["spec_prefix"]+"/packages"]) == types.StringType:
4905 + self.settings[self.settings["spec_prefix"]+"/packages"] = \
4906 + self.settings[self.settings["spec_prefix"]+"/packages"].split()
4907 + self.settings[self.settings["spec_prefix"]+"/packages"].append("app-misc/livecd-tools")
4908 +
4909 + def set_pkgcache_path(self):
4910 + if "pkgcache_path" in self.settings:
4911 + if type(self.settings["pkgcache_path"]) != types.StringType:
4912 + self.settings["pkgcache_path"]=normpath(string.join(self.settings["pkgcache_path"]))
4913 + else:
4914 + generic_stage_target.set_pkgcache_path(self)
4915 +
4916 +def register(foo):
4917 + foo.update({"livecd-stage1":livecd_stage1_target})
4918 + return foo
4919 diff --git a/catalyst/targets/livecd_stage2_target.py b/catalyst/targets/livecd_stage2_target.py
4920 new file mode 100644
4921 index 0000000..1bfd820
4922 --- /dev/null
4923 +++ b/catalyst/targets/livecd_stage2_target.py
4924 @@ -0,0 +1,146 @@
4925 +"""
4926 +LiveCD stage2 target, builds upon previous LiveCD stage1 tarball
4927 +"""
4928 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
4929 +
4930 +import os,string,types,stat,shutil
4931 +from catalyst.support import *
4932 +from generic_stage_target import *
4933 +
4934 +class livecd_stage2_target(generic_stage_target):
4935 + """
4936 + Builder class for a LiveCD stage2 build.
4937 + """
4938 + def __init__(self,spec,addlargs):
4939 + self.required_values=["boot/kernel"]
4940 +
4941 + self.valid_values=[]
4942 +
4943 + self.valid_values.extend(self.required_values)
4944 + self.valid_values.extend(["livecd/cdtar","livecd/empty","livecd/rm",\
4945 + "livecd/unmerge","livecd/iso","livecd/gk_mainargs","livecd/type",\
4946 + "livecd/readme","livecd/motd","livecd/overlay",\
4947 + "livecd/modblacklist","livecd/splash_theme","livecd/rcadd",\
4948 + "livecd/rcdel","livecd/fsscript","livecd/xinitrc",\
4949 + "livecd/root_overlay","livecd/users","portage_overlay",\
4950 + "livecd/fstype","livecd/fsops","livecd/linuxrc","livecd/bootargs",\
4951 + "gamecd/conf","livecd/xdm","livecd/xsession","livecd/volid"])
4952 +
4953 + generic_stage_target.__init__(self,spec,addlargs)
4954 + if "livecd/type" not in self.settings:
4955 + self.settings["livecd/type"] = "generic-livecd"
4956 +
4957 + file_locate(self.settings, ["cdtar","controller_file"])
4958 +
4959 + def set_source_path(self):
4960 + self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2")
4961 + if os.path.isfile(self.settings["source_path"]):
4962 + self.settings["source_path_hash"]=generate_hash(self.settings["source_path"])
4963 + else:
4964 + self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/")
4965 + if not os.path.exists(self.settings["source_path"]):
4966 + raise CatalystError,"Source Path: "+self.settings["source_path"]+" does not exist."
4967 +
4968 + def set_spec_prefix(self):
4969 + self.settings["spec_prefix"]="livecd"
4970 +
4971 + def set_target_path(self):
4972 + self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
4973 + if "AUTORESUME" in self.settings \
4974 + and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
4975 + print "Resume point detected, skipping target path setup operation..."
4976 + else:
4977 + # first clean up any existing target stuff
4978 + if os.path.isdir(self.settings["target_path"]):
4979 + cmd("rm -rf "+self.settings["target_path"],
4980 + "Could not remove existing directory: "+self.settings["target_path"],env=self.env)
4981 + touch(self.settings["autoresume_path"]+"setup_target_path")
4982 + if not os.path.exists(self.settings["target_path"]):
4983 + os.makedirs(self.settings["target_path"])
4984 +
4985 + def run_local(self):
4986 + # what modules do we want to blacklist?
4987 + if "livecd/modblacklist" in self.settings:
4988 + try:
4989 + myf=open(self.settings["chroot_path"]+"/etc/modprobe.d/blacklist.conf","a")
4990 + except:
4991 + self.unbind()
4992 + raise CatalystError,"Couldn't open "+self.settings["chroot_path"]+"/etc/modprobe.d/blacklist.conf."
4993 +
4994 + myf.write("\n#Added by Catalyst:")
4995 + # workaround until config.py is using configparser
4996 + if isinstance(self.settings["livecd/modblacklist"], str):
4997 + self.settings["livecd/modblacklist"] = self.settings["livecd/modblacklist"].split()
4998 + for x in self.settings["livecd/modblacklist"]:
4999 + myf.write("\nblacklist "+x)
5000 + myf.close()
5001 +
5002 + def unpack(self):
5003 + unpack=True
5004 + display_msg=None
5005 +
5006 + clst_unpack_hash=read_from_clst(self.settings["autoresume_path"]+"unpack")
5007 +
5008 + if os.path.isdir(self.settings["source_path"]):
5009 + unpack_cmd="rsync -a --delete "+self.settings["source_path"]+" "+self.settings["chroot_path"]
5010 + display_msg="\nStarting rsync from "+self.settings["source_path"]+"\nto "+\
5011 + self.settings["chroot_path"]+" (This may take some time) ...\n"
5012 + error_msg="Rsync of "+self.settings["source_path"]+" to "+self.settings["chroot_path"]+" failed."
5013 + invalid_snapshot=False
5014 +
5015 + if "AUTORESUME" in self.settings:
5016 + if os.path.isdir(self.settings["source_path"]) and \
5017 + os.path.exists(self.settings["autoresume_path"]+"unpack"):
5018 + print "Resume point detected, skipping unpack operation..."
5019 + unpack=False
5020 + elif "source_path_hash" in self.settings:
5021 + if self.settings["source_path_hash"] != clst_unpack_hash:
5022 + invalid_snapshot=True
5023 +
5024 + if unpack:
5025 + self.mount_safety_check()
5026 + if invalid_snapshot:
5027 + print "No Valid Resume point detected, cleaning up ..."
5028 + #os.remove(self.settings["autoresume_path"]+"dir_setup")
5029 + self.clear_autoresume()
5030 + self.clear_chroot()
5031 + #self.dir_setup()
5032 +
5033 + if not os.path.exists(self.settings["chroot_path"]):
5034 + os.makedirs(self.settings["chroot_path"])
5035 +
5036 + if not os.path.exists(self.settings["chroot_path"]+"/tmp"):
5037 + os.makedirs(self.settings["chroot_path"]+"/tmp",1777)
5038 +
5039 + if "PKGCACHE" in self.settings:
5040 + if not os.path.exists(self.settings["pkgcache_path"]):
5041 + os.makedirs(self.settings["pkgcache_path"],0755)
5042 +
5043 + if not display_msg:
5044 + raise CatalystError,"Could not find appropriate source. Please check the 'source_subpath' setting in the spec file."
5045 +
5046 + print display_msg
5047 + cmd(unpack_cmd,error_msg,env=self.env)
5048 +
5049 + if "source_path_hash" in self.settings:
5050 + myf=open(self.settings["autoresume_path"]+"unpack","w")
5051 + myf.write(self.settings["source_path_hash"])
5052 + myf.close()
5053 + else:
5054 + touch(self.settings["autoresume_path"]+"unpack")
5055 +
5056 + def set_action_sequence(self):
5057 + self.settings["action_sequence"]=["unpack","unpack_snapshot",\
5058 + "config_profile_link","setup_confdir","portage_overlay",\
5059 + "bind","chroot_setup","setup_environment","run_local",\
5060 + "build_kernel"]
5061 + if "FETCH" not in self.settings:
5062 + self.settings["action_sequence"] += ["bootloader","preclean",\
5063 + "livecd_update","root_overlay","fsscript","rcupdate","unmerge",\
5064 + "unbind","remove","empty","target_setup",\
5065 + "setup_overlay","create_iso"]
5066 + self.settings["action_sequence"].append("clear_autoresume")
5067 +
5068 +def register(foo):
5069 + foo.update({"livecd-stage2":livecd_stage2_target})
5070 + return foo
5071 diff --git a/catalyst/targets/netboot2_target.py b/catalyst/targets/netboot2_target.py
5072 new file mode 100644
5073 index 0000000..2b3cd20
5074 --- /dev/null
5075 +++ b/catalyst/targets/netboot2_target.py
5076 @@ -0,0 +1,166 @@
5077 +"""
5078 +netboot target, version 2
5079 +"""
5080 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
5081 +
5082 +import os,string,types
5083 +from catalyst.support import *
5084 +from generic_stage_target import *
5085 +
5086 +class netboot2_target(generic_stage_target):
5087 + """
5088 + Builder class for a netboot build, version 2
5089 + """
5090 + def __init__(self,spec,addlargs):
5091 + self.required_values=[
5092 + "boot/kernel"
5093 + ]
5094 + self.valid_values=self.required_values[:]
5095 + self.valid_values.extend([
5096 + "netboot2/packages",
5097 + "netboot2/use",
5098 + "netboot2/extra_files",
5099 + "netboot2/overlay",
5100 + "netboot2/busybox_config",
5101 + "netboot2/root_overlay",
5102 + "netboot2/linuxrc"
5103 + ])
5104 +
5105 + try:
5106 + if "netboot2/packages" in addlargs:
5107 + if type(addlargs["netboot2/packages"]) == types.StringType:
5108 + loopy=[addlargs["netboot2/packages"]]
5109 + else:
5110 + loopy=addlargs["netboot2/packages"]
5111 +
5112 + for x in loopy:
5113 + self.valid_values.append("netboot2/packages/"+x+"/files")
5114 + except:
5115 + raise CatalystError,"configuration error in netboot2/packages."
5116 +
5117 + generic_stage_target.__init__(self,spec,addlargs)
5118 + self.set_build_kernel_vars()
5119 + self.settings["merge_path"]=normpath("/tmp/image/")
5120 +
5121 + def set_target_path(self):
5122 + self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+\
5123 + self.settings["target_subpath"]+"/")
5124 + if "AUTORESUME" in self.settings \
5125 + and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
5126 + print "Resume point detected, skipping target path setup operation..."
5127 + else:
5128 + # first clean up any existing target stuff
5129 + if os.path.isfile(self.settings["target_path"]):
5130 + cmd("rm -f "+self.settings["target_path"], \
5131 + "Could not remove existing file: "+self.settings["target_path"],env=self.env)
5132 + touch(self.settings["autoresume_path"]+"setup_target_path")
5133 +
5134 + if not os.path.exists(self.settings["storedir"]+"/builds/"):
5135 + os.makedirs(self.settings["storedir"]+"/builds/")
5136 +
5137 + def copy_files_to_image(self):
5138 + # copies specific files from the buildroot to merge_path
5139 + myfiles=[]
5140 +
5141 + # check for autoresume point
5142 + if "AUTORESUME" in self.settings \
5143 + and os.path.exists(self.settings["autoresume_path"]+"copy_files_to_image"):
5144 + print "Resume point detected, skipping target path setup operation..."
5145 + else:
5146 + if "netboot2/packages" in self.settings:
5147 + if type(self.settings["netboot2/packages"]) == types.StringType:
5148 + loopy=[self.settings["netboot2/packages"]]
5149 + else:
5150 + loopy=self.settings["netboot2/packages"]
5151 +
5152 + for x in loopy:
5153 + if "netboot2/packages/"+x+"/files" in self.settings:
5154 + if type(self.settings["netboot2/packages/"+x+"/files"]) == types.ListType:
5155 + myfiles.extend(self.settings["netboot2/packages/"+x+"/files"])
5156 + else:
5157 + myfiles.append(self.settings["netboot2/packages/"+x+"/files"])
5158 +
5159 + if "netboot2/extra_files" in self.settings:
5160 + if type(self.settings["netboot2/extra_files"]) == types.ListType:
5161 + myfiles.extend(self.settings["netboot2/extra_files"])
5162 + else:
5163 + myfiles.append(self.settings["netboot2/extra_files"])
5164 +
5165 + try:
5166 + cmd("/bin/bash "+self.settings["controller_file"]+\
5167 + " image " + list_bashify(myfiles),env=self.env)
5168 + except CatalystError:
5169 + self.unbind()
5170 + raise CatalystError,"Failed to copy files to image!"
5171 +
5172 + touch(self.settings["autoresume_path"]+"copy_files_to_image")
5173 +
5174 + def setup_overlay(self):
5175 + if "AUTORESUME" in self.settings \
5176 + and os.path.exists(self.settings["autoresume_path"]+"setup_overlay"):
5177 + print "Resume point detected, skipping setup_overlay operation..."
5178 + else:
5179 + if "netboot2/overlay" in self.settings:
5180 + for x in self.settings["netboot2/overlay"]:
5181 + if os.path.exists(x):
5182 + cmd("rsync -a "+x+"/ "+\
5183 + self.settings["chroot_path"] + self.settings["merge_path"], "netboot2/overlay: "+x+" copy failed.",env=self.env)
5184 + touch(self.settings["autoresume_path"]+"setup_overlay")
5185 +
5186 + def move_kernels(self):
5187 + # we're done, move the kernels to builds/*
5188 + # no auto resume here as we always want the
5189 + # freshest images moved
5190 + try:
5191 + cmd("/bin/bash "+self.settings["controller_file"]+\
5192 + " final",env=self.env)
5193 + print ">>> Netboot Build Finished!"
5194 + except CatalystError:
5195 + self.unbind()
5196 + raise CatalystError,"Failed to move kernel images!"
5197 +
5198 + def remove(self):
5199 + if "AUTORESUME" in self.settings \
5200 + and os.path.exists(self.settings["autoresume_path"]+"remove"):
5201 + print "Resume point detected, skipping remove operation..."
5202 + else:
5203 + if self.settings["spec_prefix"]+"/rm" in self.settings:
5204 + for x in self.settings[self.settings["spec_prefix"]+"/rm"]:
5205 + # we're going to shell out for all these cleaning operations,
5206 + # so we get easy glob handling
5207 + print "netboot2: removing " + x
5208 + os.system("rm -rf " + self.settings["chroot_path"] + self.settings["merge_path"] + x)
5209 +
5210 + def empty(self):
5211 + if "AUTORESUME" in self.settings \
5212 + and os.path.exists(self.settings["autoresume_path"]+"empty"):
5213 + print "Resume point detected, skipping empty operation..."
5214 + else:
5215 + if "netboot2/empty" in self.settings:
5216 + if type(self.settings["netboot2/empty"])==types.StringType:
5217 + self.settings["netboot2/empty"]=self.settings["netboot2/empty"].split()
5218 + for x in self.settings["netboot2/empty"]:
5219 + myemp=self.settings["chroot_path"] + self.settings["merge_path"] + x
5220 + if not os.path.isdir(myemp):
5221 + print x,"not a directory or does not exist, skipping 'empty' operation."
5222 + continue
5223 + print "Emptying directory", x
5224 + # stat the dir, delete the dir, recreate the dir and set
5225 + # the proper perms and ownership
5226 + mystat=os.stat(myemp)
5227 + shutil.rmtree(myemp)
5228 + os.makedirs(myemp,0755)
5229 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
5230 + os.chmod(myemp,mystat[ST_MODE])
5231 + touch(self.settings["autoresume_path"]+"empty")
5232 +
5233 + def set_action_sequence(self):
5234 + self.settings["action_sequence"]=["unpack","unpack_snapshot","config_profile_link",
5235 + "setup_confdir","portage_overlay","bind","chroot_setup",\
5236 + "setup_environment","build_packages","root_overlay",\
5237 + "copy_files_to_image","setup_overlay","build_kernel","move_kernels",\
5238 + "remove","empty","unbind","clean","clear_autoresume"]
5239 +
5240 +def register(foo):
5241 + foo.update({"netboot2":netboot2_target})
5242 + return foo
5243 diff --git a/catalyst/targets/netboot_target.py b/catalyst/targets/netboot_target.py
5244 new file mode 100644
5245 index 0000000..9d01b7e
5246 --- /dev/null
5247 +++ b/catalyst/targets/netboot_target.py
5248 @@ -0,0 +1,128 @@
5249 +"""
5250 +netboot target, version 1
5251 +"""
5252 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
5253 +
5254 +import os,string,types
5255 +from catalyst.support import *
5256 +from generic_stage_target import *
5257 +
5258 +class netboot_target(generic_stage_target):
5259 + """
5260 + Builder class for a netboot build.
5261 + """
5262 + def __init__(self,spec,addlargs):
5263 + self.valid_values = [
5264 + "netboot/kernel/sources",
5265 + "netboot/kernel/config",
5266 + "netboot/kernel/prebuilt",
5267 +
5268 + "netboot/busybox_config",
5269 +
5270 + "netboot/extra_files",
5271 + "netboot/packages"
5272 + ]
5273 + self.required_values=[]
5274 +
5275 + try:
5276 + if "netboot/packages" in addlargs:
5277 + if type(addlargs["netboot/packages"]) == types.StringType:
5278 + loopy=[addlargs["netboot/packages"]]
5279 + else:
5280 + loopy=addlargs["netboot/packages"]
5281 +
5282 + # for x in loopy:
5283 + # self.required_values.append("netboot/packages/"+x+"/files")
5284 + except:
5285 + raise CatalystError,"configuration error in netboot/packages."
5286 +
5287 + generic_stage_target.__init__(self,spec,addlargs)
5288 + self.set_build_kernel_vars(addlargs)
5289 + if "netboot/busybox_config" in addlargs:
5290 + file_locate(self.settings, ["netboot/busybox_config"])
5291 +
5292 + # Custom Kernel Tarball --- use that instead ...
5293 +
5294 + # unless the user wants specific CFLAGS/CXXFLAGS, let's use -Os
5295 +
5296 + for envvar in "CFLAGS", "CXXFLAGS":
5297 + if envvar not in os.environ and envvar not in addlargs:
5298 + self.settings[envvar] = "-Os -pipe"
5299 +
5300 + def set_root_path(self):
5301 + # ROOT= variable for emerges
5302 + self.settings["root_path"]=normpath("/tmp/image")
5303 + print "netboot root path is "+self.settings["root_path"]
5304 +
5305 +# def build_packages(self):
5306 +# # build packages
5307 +# if "netboot/packages" in self.settings:
5308 +# mypack=list_bashify(self.settings["netboot/packages"])
5309 +# try:
5310 +# cmd("/bin/bash "+self.settings["controller_file"]+" packages "+mypack,env=self.env)
5311 +# except CatalystError:
5312 +# self.unbind()
5313 +# raise CatalystError,"netboot build aborting due to error."
5314 +
5315 + def build_busybox(self):
5316 + # build busybox
5317 + if "netboot/busybox_config" in self.settings:
5318 + mycmd = self.settings["netboot/busybox_config"]
5319 + else:
5320 + mycmd = ""
5321 + try:
5322 + cmd("/bin/bash "+self.settings["controller_file"]+" busybox "+ mycmd,env=self.env)
5323 + except CatalystError:
5324 + self.unbind()
5325 + raise CatalystError,"netboot build aborting due to error."
5326 +
5327 + def copy_files_to_image(self):
5328 + # create image
5329 + myfiles=[]
5330 + if "netboot/packages" in self.settings:
5331 + if type(self.settings["netboot/packages"]) == types.StringType:
5332 + loopy=[self.settings["netboot/packages"]]
5333 + else:
5334 + loopy=self.settings["netboot/packages"]
5335 +
5336 + for x in loopy:
5337 + if "netboot/packages/"+x+"/files" in self.settings:
5338 + if type(self.settings["netboot/packages/"+x+"/files"]) == types.ListType:
5339 + myfiles.extend(self.settings["netboot/packages/"+x+"/files"])
5340 + else:
5341 + myfiles.append(self.settings["netboot/packages/"+x+"/files"])
5342 +
5343 + if "netboot/extra_files" in self.settings:
5344 + if type(self.settings["netboot/extra_files"]) == types.ListType:
5345 + myfiles.extend(self.settings["netboot/extra_files"])
5346 + else:
5347 + myfiles.append(self.settings["netboot/extra_files"])
5348 +
5349 + try:
5350 + cmd("/bin/bash "+self.settings["controller_file"]+\
5351 + " image " + list_bashify(myfiles),env=self.env)
5352 + except CatalystError:
5353 + self.unbind()
5354 + raise CatalystError,"netboot build aborting due to error."
5355 +
5356 + def create_netboot_files(self):
5357 + # finish it all up
5358 + try:
5359 + cmd("/bin/bash "+self.settings["controller_file"]+" finish",env=self.env)
5360 + except CatalystError:
5361 + self.unbind()
5362 + raise CatalystError,"netboot build aborting due to error."
5363 +
5364 + # end
5365 + print "netboot: build finished !"
5366 +
5367 + def set_action_sequence(self):
5368 + self.settings["action_sequence"]=["unpack","unpack_snapshot",
5369 + "config_profile_link","setup_confdir","bind","chroot_setup",\
5370 + "setup_environment","build_packages","build_busybox",\
5371 + "build_kernel","copy_files_to_image",\
5372 + "clean","create_netboot_files","unbind","clear_autoresume"]
5373 +
5374 +def register(foo):
5375 + foo.update({"netboot":netboot_target})
5376 + return foo
5377 diff --git a/catalyst/targets/snapshot_target.py b/catalyst/targets/snapshot_target.py
5378 new file mode 100644
5379 index 0000000..e21bd1a
5380 --- /dev/null
5381 +++ b/catalyst/targets/snapshot_target.py
5382 @@ -0,0 +1,91 @@
5383 +"""
5384 +Snapshot target
5385 +"""
5386 +
5387 +import os
5388 +from catalyst.support import *
5389 +from generic_stage_target import *
5390 +
5391 +class snapshot_target(generic_stage_target):
5392 + """
5393 + Builder class for snapshots.
5394 + """
5395 + def __init__(self,myspec,addlargs):
5396 + self.required_values=["version_stamp","target"]
5397 + self.valid_values=["version_stamp","target"]
5398 +
5399 + generic_target.__init__(self,myspec,addlargs)
5400 + self.settings=myspec
5401 + self.settings["target_subpath"]="portage"
5402 + st=self.settings["storedir"]
5403 + self.settings["snapshot_path"]=normpath(st + "/snapshots/"
5404 + + self.settings["snapshot_name"]
5405 + + self.settings["version_stamp"] + ".tar.bz2")
5406 + self.settings["tmp_path"]=normpath(st+"/tmp/"+self.settings["target_subpath"])
5407 +
5408 + def setup(self):
5409 + x=normpath(self.settings["storedir"]+"/snapshots")
5410 + if not os.path.exists(x):
5411 + os.makedirs(x)
5412 +
5413 + def mount_safety_check(self):
5414 + pass
5415 +
5416 + def run(self):
5417 + if "PURGEONLY" in self.settings:
5418 + self.purge()
5419 + return
5420 +
5421 + if "PURGE" in self.settings:
5422 + self.purge()
5423 +
5424 + self.setup()
5425 + print "Creating Portage tree snapshot "+self.settings["version_stamp"]+\
5426 + " from "+self.settings["portdir"]+"..."
5427 +
5428 + mytmp=self.settings["tmp_path"]
5429 + if not os.path.exists(mytmp):
5430 + os.makedirs(mytmp)
5431 +
5432 + cmd("rsync -a --delete --exclude /packages/ --exclude /distfiles/ " +
5433 + "--exclude /local/ --exclude CVS/ --exclude .svn --filter=H_**/files/digest-* " +
5434 + self.settings["portdir"] + "/ " + mytmp + "/%s/" % self.settings["repo_name"],
5435 + "Snapshot failure",env=self.env)
5436 +
5437 + print "Compressing Portage snapshot tarball..."
5438 + cmd("tar -I lbzip2 -cf " + self.settings["snapshot_path"] + " -C " +
5439 + mytmp + " %s" % self.settings["repo_name"],
5440 + "Snapshot creation failure",env=self.env)
5441 +
5442 + self.gen_contents_file(self.settings["snapshot_path"])
5443 + self.gen_digest_file(self.settings["snapshot_path"])
5444 +
5445 + self.cleanup()
5446 + print "snapshot: complete!"
5447 +
5448 + def kill_chroot_pids(self):
5449 + pass
5450 +
5451 + def cleanup(self):
5452 + print "Cleaning up..."
5453 +
5454 + def purge(self):
5455 + myemp=self.settings["tmp_path"]
5456 + if os.path.isdir(myemp):
5457 + print "Emptying directory",myemp
5458 + """
5459 + stat the dir, delete the dir, recreate the dir and set
5460 + the proper perms and ownership
5461 + """
5462 + mystat=os.stat(myemp)
5463 + """ There's no easy way to change flags recursively in python """
5464 + if os.uname()[0] == "FreeBSD":
5465 + os.system("chflags -R noschg "+myemp)
5466 + shutil.rmtree(myemp)
5467 + os.makedirs(myemp,0755)
5468 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
5469 + os.chmod(myemp,mystat[ST_MODE])
5470 +
5471 +def register(foo):
5472 + foo.update({"snapshot":snapshot_target})
5473 + return foo
5474 diff --git a/catalyst/targets/stage1_target.py b/catalyst/targets/stage1_target.py
5475 new file mode 100644
5476 index 0000000..25f7116
5477 --- /dev/null
5478 +++ b/catalyst/targets/stage1_target.py
5479 @@ -0,0 +1,96 @@
5480 +"""
5481 +stage1 target
5482 +"""
5483 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
5484 +
5485 +from catalyst.support import *
5486 +from generic_stage_target import *
5487 +
5488 +class stage1_target(generic_stage_target):
5489 + """
5490 + Builder class for a stage1 installation tarball build.
5491 + """
5492 + def __init__(self,spec,addlargs):
5493 + self.required_values=[]
5494 + self.valid_values=["chost"]
5495 + self.valid_values.extend(["update_seed","update_seed_command"])
5496 + generic_stage_target.__init__(self,spec,addlargs)
5497 +
5498 + def set_stage_path(self):
5499 + self.settings["stage_path"]=normpath(self.settings["chroot_path"]+self.settings["root_path"])
5500 + print "stage1 stage path is "+self.settings["stage_path"]
5501 +
5502 + def set_root_path(self):
5503 + # sets the root path, relative to 'chroot_path', of the stage1 root
5504 + self.settings["root_path"]=normpath("/tmp/stage1root")
5505 + print "stage1 root path is "+self.settings["root_path"]
5506 +
5507 + def set_cleanables(self):
5508 + generic_stage_target.set_cleanables(self)
5509 + self.settings["cleanables"].extend([\
5510 + "/usr/share/zoneinfo", "/etc/portage/package*"])
5511 +
5512 + # XXX: How do these override_foo() functions differ from the ones in generic_stage_target and why aren't they in stage3_target?
5513 +
5514 + def override_chost(self):
5515 + if "chost" in self.settings:
5516 + self.settings["CHOST"]=list_to_string(self.settings["chost"])
5517 +
5518 + def override_cflags(self):
5519 + if "cflags" in self.settings:
5520 + self.settings["CFLAGS"]=list_to_string(self.settings["cflags"])
5521 +
5522 + def override_cxxflags(self):
5523 + if "cxxflags" in self.settings:
5524 + self.settings["CXXFLAGS"]=list_to_string(self.settings["cxxflags"])
5525 +
5526 + def override_ldflags(self):
5527 + if "ldflags" in self.settings:
5528 + self.settings["LDFLAGS"]=list_to_string(self.settings["ldflags"])
5529 +
5530 + def set_portage_overlay(self):
5531 + generic_stage_target.set_portage_overlay(self)
5532 + if "portage_overlay" in self.settings:
5533 + print "\nWARNING !!!!!"
5534 + print "\tUsing an portage overlay for earlier stages could cause build issues."
5535 + print "\tIf you break it, you buy it. Don't complain to us about it."
5536 + print "\tDont say we did not warn you\n"
5537 +
5538 + def base_dirs(self):
5539 + if os.uname()[0] == "FreeBSD":
5540 + # baselayout no longer creates the .keep files in proc and dev for FreeBSD as it
5541 + # would create them too late...we need them earlier before bind mounting filesystems
5542 + # since proc and dev are not writeable, so...create them here
5543 + if not os.path.exists(self.settings["stage_path"]+"/proc"):
5544 + os.makedirs(self.settings["stage_path"]+"/proc")
5545 + if not os.path.exists(self.settings["stage_path"]+"/dev"):
5546 + os.makedirs(self.settings["stage_path"]+"/dev")
5547 + if not os.path.isfile(self.settings["stage_path"]+"/proc/.keep"):
5548 + try:
5549 + proc_keepfile = open(self.settings["stage_path"]+"/proc/.keep","w")
5550 + proc_keepfile.write('')
5551 + proc_keepfile.close()
5552 + except IOError:
5553 + print "!!! Failed to create %s" % (self.settings["stage_path"]+"/dev/.keep")
5554 + if not os.path.isfile(self.settings["stage_path"]+"/dev/.keep"):
5555 + try:
5556 + dev_keepfile = open(self.settings["stage_path"]+"/dev/.keep","w")
5557 + dev_keepfile.write('')
5558 + dev_keepfile.close()
5559 + except IOError:
5560 + print "!!! Failed to create %s" % (self.settings["stage_path"]+"/dev/.keep")
5561 + else:
5562 + pass
5563 +
5564 + def set_mounts(self):
5565 + # stage_path/proc probably doesn't exist yet, so create it
5566 + if not os.path.exists(self.settings["stage_path"]+"/proc"):
5567 + os.makedirs(self.settings["stage_path"]+"/proc")
5568 +
5569 + # alter the mount mappings to bind mount proc onto it
5570 + self.mounts.append("/tmp/stage1root/proc")
5571 + self.mountmap["/tmp/stage1root/proc"]="/proc"
5572 +
5573 +def register(foo):
5574 + foo.update({"stage1":stage1_target})
5575 + return foo
5576 diff --git a/catalyst/targets/stage2_target.py b/catalyst/targets/stage2_target.py
5577 new file mode 100644
5578 index 0000000..15acdee
5579 --- /dev/null
5580 +++ b/catalyst/targets/stage2_target.py
5581 @@ -0,0 +1,62 @@
5582 +"""
5583 +stage2 target, builds upon previous stage1 tarball
5584 +"""
5585 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
5586 +
5587 +from catalyst.support import *
5588 +from generic_stage_target import *
5589 +
5590 +class stage2_target(generic_stage_target):
5591 + """
5592 + Builder class for a stage2 installation tarball build.
5593 + """
5594 + def __init__(self,spec,addlargs):
5595 + self.required_values=[]
5596 + self.valid_values=["chost"]
5597 + generic_stage_target.__init__(self,spec,addlargs)
5598 +
5599 + def set_source_path(self):
5600 + if "SEEDCACHE" in self.settings and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")):
5601 + self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")
5602 + else:
5603 + self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2")
5604 + if os.path.isfile(self.settings["source_path"]):
5605 + if os.path.exists(self.settings["source_path"]):
5606 + # XXX: Is this even necessary if the previous check passes?
5607 + self.settings["source_path_hash"]=generate_hash(self.settings["source_path"],\
5608 + hash_function=self.settings["hash_function"],verbose=False)
5609 + print "Source path set to "+self.settings["source_path"]
5610 + if os.path.isdir(self.settings["source_path"]):
5611 + print "\tIf this is not desired, remove this directory or turn of seedcache in the options of catalyst.conf"
5612 + print "\tthe source path will then be "+normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2\n")
5613 +
5614 + # XXX: How do these override_foo() functions differ from the ones in
5615 + # generic_stage_target and why aren't they in stage3_target?
5616 +
5617 + def override_chost(self):
5618 + if "chost" in self.settings:
5619 + self.settings["CHOST"]=list_to_string(self.settings["chost"])
5620 +
5621 + def override_cflags(self):
5622 + if "cflags" in self.settings:
5623 + self.settings["CFLAGS"]=list_to_string(self.settings["cflags"])
5624 +
5625 + def override_cxxflags(self):
5626 + if "cxxflags" in self.settings:
5627 + self.settings["CXXFLAGS"]=list_to_string(self.settings["cxxflags"])
5628 +
5629 + def override_ldflags(self):
5630 + if "ldflags" in self.settings:
5631 + self.settings["LDFLAGS"]=list_to_string(self.settings["ldflags"])
5632 +
5633 + def set_portage_overlay(self):
5634 + generic_stage_target.set_portage_overlay(self)
5635 + if "portage_overlay" in self.settings:
5636 + print "\nWARNING !!!!!"
5637 + print "\tUsing an portage overlay for earlier stages could cause build issues."
5638 + print "\tIf you break it, you buy it. Don't complain to us about it."
5639 + print "\tDont say we did not warn you\n"
5640 +
5641 +def register(foo):
5642 + foo.update({"stage2":stage2_target})
5643 + return foo
5644 diff --git a/catalyst/targets/stage3_target.py b/catalyst/targets/stage3_target.py
5645 new file mode 100644
5646 index 0000000..89edd66
5647 --- /dev/null
5648 +++ b/catalyst/targets/stage3_target.py
5649 @@ -0,0 +1,31 @@
5650 +"""
5651 +stage3 target, builds upon previous stage2/stage3 tarball
5652 +"""
5653 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
5654 +
5655 +from catalyst.support import *
5656 +from generic_stage_target import *
5657 +
5658 +class stage3_target(generic_stage_target):
5659 + """
5660 + Builder class for a stage3 installation tarball build.
5661 + """
5662 + def __init__(self,spec,addlargs):
5663 + self.required_values=[]
5664 + self.valid_values=[]
5665 + generic_stage_target.__init__(self,spec,addlargs)
5666 +
5667 + def set_portage_overlay(self):
5668 + generic_stage_target.set_portage_overlay(self)
5669 + if "portage_overlay" in self.settings:
5670 + print "\nWARNING !!!!!"
5671 + print "\tUsing an overlay for earlier stages could cause build issues."
5672 + print "\tIf you break it, you buy it. Don't complain to us about it."
5673 + print "\tDont say we did not warn you\n"
5674 +
5675 + def set_cleanables(self):
5676 + generic_stage_target.set_cleanables(self)
5677 +
5678 +def register(foo):
5679 + foo.update({"stage3":stage3_target})
5680 + return foo
5681 diff --git a/catalyst/targets/stage4_target.py b/catalyst/targets/stage4_target.py
5682 new file mode 100644
5683 index 0000000..9168f2e
5684 --- /dev/null
5685 +++ b/catalyst/targets/stage4_target.py
5686 @@ -0,0 +1,43 @@
5687 +"""
5688 +stage4 target, builds upon previous stage3/stage4 tarball
5689 +"""
5690 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
5691 +
5692 +from catalyst.support import *
5693 +from generic_stage_target import *
5694 +
5695 +class stage4_target(generic_stage_target):
5696 + """
5697 + Builder class for stage4.
5698 + """
5699 + def __init__(self,spec,addlargs):
5700 + self.required_values=["stage4/packages"]
5701 + self.valid_values=self.required_values[:]
5702 + self.valid_values.extend(["stage4/use","boot/kernel",\
5703 + "stage4/root_overlay","stage4/fsscript",\
5704 + "stage4/gk_mainargs","splash_theme",\
5705 + "portage_overlay","stage4/rcadd","stage4/rcdel",\
5706 + "stage4/linuxrc","stage4/unmerge","stage4/rm","stage4/empty"])
5707 + generic_stage_target.__init__(self,spec,addlargs)
5708 +
5709 + def set_cleanables(self):
5710 + self.settings["cleanables"]=["/var/tmp/*","/tmp/*"]
5711 +
5712 + def set_action_sequence(self):
5713 + self.settings["action_sequence"]=["unpack","unpack_snapshot",\
5714 + "config_profile_link","setup_confdir","portage_overlay",\
5715 + "bind","chroot_setup","setup_environment","build_packages",\
5716 + "build_kernel","bootloader","root_overlay","fsscript",\
5717 + "preclean","rcupdate","unmerge","unbind","remove","empty",\
5718 + "clean"]
5719 +
5720 +# if "TARBALL" in self.settings or \
5721 +# "FETCH" not in self.settings:
5722 + if "FETCH" not in self.settings:
5723 + self.settings["action_sequence"].append("capture")
5724 + self.settings["action_sequence"].append("clear_autoresume")
5725 +
5726 +def register(foo):
5727 + foo.update({"stage4":stage4_target})
5728 + return foo
5729 +
5730 diff --git a/catalyst/targets/tinderbox_target.py b/catalyst/targets/tinderbox_target.py
5731 new file mode 100644
5732 index 0000000..5985c5b
5733 --- /dev/null
5734 +++ b/catalyst/targets/tinderbox_target.py
5735 @@ -0,0 +1,44 @@
5736 +"""
5737 +Tinderbox target
5738 +"""
5739 +# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
5740 +
5741 +from catalyst.support import *
5742 +from generic_stage_target import *
5743 +
5744 +class tinderbox_target(generic_stage_target):
5745 + """
5746 + Builder class for the tinderbox target
5747 + """
5748 + def __init__(self,spec,addlargs):
5749 + self.required_values=["tinderbox/packages"]
5750 + self.valid_values=self.required_values[:]
5751 + self.valid_values.extend(["tinderbox/use"])
5752 + generic_stage_target.__init__(self,spec,addlargs)
5753 +
5754 + def run_local(self):
5755 + # tinderbox
5756 + # example call: "grp.sh run xmms vim sys-apps/gleep"
5757 + try:
5758 + if os.path.exists(self.settings["controller_file"]):
5759 + cmd("/bin/bash "+self.settings["controller_file"]+" run "+\
5760 + list_bashify(self.settings["tinderbox/packages"]),"run script failed.",env=self.env)
5761 +
5762 + except CatalystError:
5763 + self.unbind()
5764 + raise CatalystError,"Tinderbox aborting due to error."
5765 +
5766 + def set_cleanables(self):
5767 + self.settings["cleanables"]=["/etc/resolv.conf","/var/tmp/*","/root/*",
5768 + self.settings['portdir']]
5769 +
5770 + def set_action_sequence(self):
5771 + #Default action sequence for run method
5772 + self.settings["action_sequence"]=["unpack","unpack_snapshot",\
5773 + "config_profile_link","setup_confdir","bind","chroot_setup",\
5774 + "setup_environment","run_local","preclean","unbind","clean",\
5775 + "clear_autoresume"]
5776 +
5777 +def register(foo):
5778 + foo.update({"tinderbox":tinderbox_target})
5779 + return foo
5780 --
5781 1.8.3.2