Gentoo Archives: gentoo-catalyst

From: Brian Dolbec <dolsen@g.o>
To: gentoo-catalyst@l.g.o
Subject: [gentoo-catalyst] [PATCH 1/3] [1 of 3] Move base stage and target files to thier own sub-pkg
Date: Thu, 11 Sep 2014 03:51:00
Message-Id: 1410407450-2888-2-git-send-email-dolsen@gentoo.org
In Reply to: [gentoo-catalyst] [PATCH 0/3] Code breakup & restructuring by Brian Dolbec
1 Fix an indent error in grp_target.py
2 ---
3 catalyst/base/__init__.py | 1 +
4 catalyst/base/clearbase.py | 115 +++
5 catalyst/base/genbase.py | 58 ++
6 catalyst/base/stagebase.py | 1630 ++++++++++++++++++++++++++++++
7 catalyst/base/targetbase.py | 15 +
8 catalyst/targets/clearbase.py | 115 ---
9 catalyst/targets/embedded_target.py | 12 +-
10 catalyst/targets/genbase.py | 58 --
11 catalyst/targets/generic_stage_target.py | 1630 ------------------------------
12 catalyst/targets/grp_target.py | 34 +-
13 catalyst/targets/livecd_stage1_target.py | 21 +-
14 catalyst/targets/livecd_stage2_target.py | 13 +-
15 catalyst/targets/netboot2_target.py | 17 +-
16 catalyst/targets/netboot_target.py | 15 +-
17 catalyst/targets/snapshot_target.py | 4 +-
18 catalyst/targets/stage1_target.py | 17 +-
19 catalyst/targets/stage2_target.py | 15 +-
20 catalyst/targets/stage3_target.py | 12 +-
21 catalyst/targets/stage4_target.py | 8 +-
22 catalyst/targets/targetbase.py | 15 -
23 catalyst/targets/tinderbox_target.py | 11 +-
24 21 files changed, 1927 insertions(+), 1889 deletions(-)
25 create mode 100644 catalyst/base/__init__.py
26 create mode 100644 catalyst/base/clearbase.py
27 create mode 100644 catalyst/base/genbase.py
28 create mode 100644 catalyst/base/stagebase.py
29 create mode 100644 catalyst/base/targetbase.py
30 delete mode 100644 catalyst/targets/clearbase.py
31 delete mode 100644 catalyst/targets/genbase.py
32 delete mode 100644 catalyst/targets/generic_stage_target.py
33 delete mode 100644 catalyst/targets/targetbase.py
34
35 diff --git a/catalyst/base/__init__.py b/catalyst/base/__init__.py
36 new file mode 100644
37 index 0000000..8b13789
38 --- /dev/null
39 +++ b/catalyst/base/__init__.py
40 @@ -0,0 +1 @@
41 +
42 diff --git a/catalyst/base/clearbase.py b/catalyst/base/clearbase.py
43 new file mode 100644
44 index 0000000..8519acc
45 --- /dev/null
46 +++ b/catalyst/base/clearbase.py
47 @@ -0,0 +1,115 @@
48 +
49 +import os
50 +import shutil
51 +from stat import ST_UID, ST_GID, ST_MODE
52 +
53 +
54 +from catalyst.support import cmd, countdown
55 +
56 +
57 +class ClearBase(object):
58 + """
59 + This class does all of clearing after task completion
60 + """
61 + def __init__(self, myspec):
62 + self.settings = myspec
63 +
64 +
65 +
66 + def clear_autoresume(self):
67 + """ Clean resume points since they are no longer needed """
68 + if "autoresume" in self.settings["options"]:
69 + print "Removing AutoResume Points: ..."
70 + myemp=self.settings["autoresume_path"]
71 + if os.path.isdir(myemp):
72 + if "autoresume" in self.settings["options"]:
73 + print "Emptying directory",myemp
74 + """
75 + stat the dir, delete the dir, recreate the dir and set
76 + the proper perms and ownership
77 + """
78 + mystat=os.stat(myemp)
79 + if os.uname()[0] == "FreeBSD":
80 + cmd("chflags -R noschg "+myemp,\
81 + "Could not remove immutable flag for file "\
82 + +myemp)
83 + #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env-self.env)
84 + shutil.rmtree(myemp)
85 + os.makedirs(myemp,0755)
86 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
87 + os.chmod(myemp,mystat[ST_MODE])
88 +
89 +
90 + def clear_chroot(self):
91 + myemp=self.settings["chroot_path"]
92 + if os.path.isdir(myemp):
93 + print "Emptying directory",myemp
94 + """
95 + stat the dir, delete the dir, recreate the dir and set
96 + the proper perms and ownership
97 + """
98 + mystat=os.stat(myemp)
99 + #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
100 + """ There's no easy way to change flags recursively in python """
101 + if os.uname()[0] == "FreeBSD":
102 + os.system("chflags -R noschg "+myemp)
103 + shutil.rmtree(myemp)
104 + os.makedirs(myemp,0755)
105 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
106 + os.chmod(myemp,mystat[ST_MODE])
107 +
108 +
109 + def clear_packages(self):
110 + if "pkgcache" in self.settings["options"]:
111 + print "purging the pkgcache ..."
112 +
113 + myemp=self.settings["pkgcache_path"]
114 + if os.path.isdir(myemp):
115 + print "Emptying directory",myemp
116 + """
117 + stat the dir, delete the dir, recreate the dir and set
118 + the proper perms and ownership
119 + """
120 + mystat=os.stat(myemp)
121 + #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
122 + shutil.rmtree(myemp)
123 + os.makedirs(myemp,0755)
124 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
125 + os.chmod(myemp,mystat[ST_MODE])
126 +
127 +
128 + def clear_kerncache(self):
129 + if "kerncache" in self.settings["options"]:
130 + print "purging the kerncache ..."
131 +
132 + myemp=self.settings["kerncache_path"]
133 + if os.path.isdir(myemp):
134 + print "Emptying directory",myemp
135 + """
136 + stat the dir, delete the dir, recreate the dir and set
137 + the proper perms and ownership
138 + """
139 + mystat=os.stat(myemp)
140 + #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
141 + shutil.rmtree(myemp)
142 + os.makedirs(myemp,0755)
143 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
144 + os.chmod(myemp,mystat[ST_MODE])
145 +
146 +
147 + def purge(self):
148 + countdown(10,"Purging Caches ...")
149 + if any(k in self.settings["options"] for k in ("purge","purgeonly","purgetmponly")):
150 + print "clearing autoresume ..."
151 + self.clear_autoresume()
152 +
153 + print "clearing chroot ..."
154 + self.clear_chroot()
155 +
156 + if "PURGETMPONLY" not in self.settings:
157 + print "clearing package cache ..."
158 + self.clear_packages()
159 +
160 + print "clearing kerncache ..."
161 + self.clear_kerncache()
162 +
163 diff --git a/catalyst/base/genbase.py b/catalyst/base/genbase.py
164 new file mode 100644
165 index 0000000..e818781
166 --- /dev/null
167 +++ b/catalyst/base/genbase.py
168 @@ -0,0 +1,58 @@
169 +
170 +
171 +import os
172 +
173 +
174 +class GenBase(object):
175 + """
176 + This class does generation of the contents and digests files.
177 + """
178 + def __init__(self,myspec):
179 + self.settings = myspec
180 +
181 +
182 + def gen_contents_file(self,file):
183 + if os.path.exists(file+".CONTENTS"):
184 + os.remove(file+".CONTENTS")
185 + if "contents" in self.settings:
186 + contents_map = self.settings["contents_map"]
187 + if os.path.exists(file):
188 + myf=open(file+".CONTENTS","w")
189 + keys={}
190 + for i in self.settings["contents"].split():
191 + keys[i]=1
192 + array=keys.keys()
193 + array.sort()
194 + for j in array:
195 + contents = contents_map.generate_contents(file, j,
196 + verbose="VERBOSE" in self.settings)
197 + if contents:
198 + myf.write(contents)
199 + myf.close()
200 +
201 + def gen_digest_file(self,file):
202 + if os.path.exists(file+".DIGESTS"):
203 + os.remove(file+".DIGESTS")
204 + if "digests" in self.settings:
205 + hash_map = self.settings["hash_map"]
206 + if os.path.exists(file):
207 + myf=open(file+".DIGESTS","w")
208 + keys={}
209 + for i in self.settings["digests"].split():
210 + keys[i]=1
211 + array=keys.keys()
212 + array.sort()
213 + for f in [file, file+'.CONTENTS']:
214 + if os.path.exists(f):
215 + if "all" in array:
216 + for k in list(hash_map.hash_map):
217 + hash = hash_map.generate_hash(f,hash_=k,
218 + verbose = "VERBOSE" in self.settings)
219 + myf.write(hash)
220 + else:
221 + for j in array:
222 + hash = hash_map.generate_hash(f,hash_=j,
223 + verbose = "VERBOSE" in self.settings)
224 + myf.write(hash)
225 + myf.close()
226 +
227 diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
228 new file mode 100644
229 index 0000000..bebb5dc
230 --- /dev/null
231 +++ b/catalyst/base/stagebase.py
232 @@ -0,0 +1,1630 @@
233 +
234 +import os
235 +import string
236 +import imp
237 +import types
238 +import shutil
239 +import sys
240 +from stat import ST_UID, ST_GID, ST_MODE
241 +
242 +# for convienience
243 +pjoin = os.path.join
244 +
245 +from catalyst.defaults import (SOURCE_MOUNT_DEFAULTS, TARGET_MOUNT_DEFAULTS,
246 + PORT_LOGDIR_CLEAN)
247 +from catalyst.support import (CatalystError, msg, file_locate, normpath,
248 + touch, cmd, warn, list_bashify, read_makeconf, read_from_clst, ismount)
249 +from catalyst.base.targetbase import TargetBase
250 +from catalyst.base.clearbase import ClearBase
251 +from catalyst.base.genbase import GenBase
252 +from catalyst.lock import LockDir
253 +
254 +
255 +class StageBase(TargetBase, ClearBase, GenBase):
256 + """
257 + This class does all of the chroot setup, copying of files, etc. It is
258 + the driver class for pretty much everything that Catalyst does.
259 + """
260 + def __init__(self,myspec,addlargs):
261 + self.required_values.extend(["version_stamp","target","subarch",\
262 + "rel_type","profile","snapshot","source_subpath"])
263 +
264 + self.valid_values.extend(["version_stamp","target","subarch",\
265 + "rel_type","profile","snapshot","source_subpath","portage_confdir",\
266 + "cflags","cxxflags","ldflags","cbuild","hostuse","portage_overlay",\
267 + "distcc_hosts","makeopts","pkgcache_path","kerncache_path"])
268 +
269 + self.set_valid_build_kernel_vars(addlargs)
270 + TargetBase.__init__(self, myspec, addlargs)
271 + GenBase.__init__(self, myspec)
272 + ClearBase.__init__(self, myspec)
273 +
274 + """
275 + The semantics of subarchmap and machinemap changed a bit in 2.0.3 to
276 + work better with vapier's CBUILD stuff. I've removed the "monolithic"
277 + machinemap from this file and split up its contents amongst the
278 + various arch/foo.py files.
279 +
280 + When register() is called on each module in the arch/ dir, it now
281 + returns a tuple instead of acting on the subarchmap dict that is
282 + passed to it. The tuple contains the values that were previously
283 + added to subarchmap as well as a new list of CHOSTs that go along
284 + with that arch. This allows us to build machinemap on the fly based
285 + on the keys in subarchmap and the values of the 2nd list returned
286 + (tmpmachinemap).
287 +
288 + Also, after talking with vapier. I have a slightly better idea of what
289 + certain variables are used for and what they should be set to. Neither
290 + 'buildarch' or 'hostarch' are used directly, so their value doesn't
291 + really matter. They are just compared to determine if we are
292 + cross-compiling. Because of this, they are just set to the name of the
293 + module in arch/ that the subarch is part of to make things simpler.
294 + The entire build process is still based off of 'subarch' like it was
295 + previously. -agaffney
296 + """
297 +
298 + self.archmap = {}
299 + self.subarchmap = {}
300 + machinemap = {}
301 + arch_dir = self.settings["PythonDir"] + "/arch/"
302 + for x in [x[:-3] for x in os.listdir(arch_dir) if x.endswith(".py")]:
303 + if x == "__init__":
304 + continue
305 + try:
306 + fh=open(arch_dir + x + ".py")
307 + """
308 + This next line loads the plugin as a module and assigns it to
309 + archmap[x]
310 + """
311 + self.archmap[x]=imp.load_module(x,fh,"../arch/" + x + ".py",
312 + (".py", "r", imp.PY_SOURCE))
313 + """
314 + This next line registers all the subarches supported in the
315 + plugin
316 + """
317 + tmpsubarchmap, tmpmachinemap = self.archmap[x].register()
318 + self.subarchmap.update(tmpsubarchmap)
319 + for machine in tmpmachinemap:
320 + machinemap[machine] = x
321 + for subarch in tmpsubarchmap:
322 + machinemap[subarch] = x
323 + fh.close()
324 + except IOError:
325 + """
326 + This message should probably change a bit, since everything in
327 + the dir should load just fine. If it doesn't, it's probably a
328 + syntax error in the module
329 + """
330 + msg("Can't find/load " + x + ".py plugin in " + arch_dir)
331 +
332 + if "chost" in self.settings:
333 + hostmachine = self.settings["chost"].split("-")[0]
334 + if hostmachine not in machinemap:
335 + raise CatalystError, "Unknown host machine type "+hostmachine
336 + self.settings["hostarch"]=machinemap[hostmachine]
337 + else:
338 + hostmachine = self.settings["subarch"]
339 + if hostmachine in machinemap:
340 + hostmachine = machinemap[hostmachine]
341 + self.settings["hostarch"]=hostmachine
342 + if "cbuild" in self.settings:
343 + buildmachine = self.settings["cbuild"].split("-")[0]
344 + else:
345 + buildmachine = os.uname()[4]
346 + if buildmachine not in machinemap:
347 + raise CatalystError, "Unknown build machine type "+buildmachine
348 + self.settings["buildarch"]=machinemap[buildmachine]
349 + self.settings["crosscompile"]=(self.settings["hostarch"]!=\
350 + self.settings["buildarch"])
351 +
352 + """ Call arch constructor, pass our settings """
353 + try:
354 + self.arch=self.subarchmap[self.settings["subarch"]](self.settings)
355 + except KeyError:
356 + print "Invalid subarch: "+self.settings["subarch"]
357 + print "Choose one of the following:",
358 + for x in self.subarchmap:
359 + print x,
360 + print
361 + sys.exit(2)
362 +
363 + print "Using target:",self.settings["target"]
364 + """ Print a nice informational message """
365 + if self.settings["buildarch"]==self.settings["hostarch"]:
366 + print "Building natively for",self.settings["hostarch"]
367 + elif self.settings["crosscompile"]:
368 + print "Cross-compiling on",self.settings["buildarch"],\
369 + "for different machine type",self.settings["hostarch"]
370 + else:
371 + print "Building on",self.settings["buildarch"],\
372 + "for alternate personality type",self.settings["hostarch"]
373 +
374 + """ This must be set first as other set_ options depend on this """
375 + self.set_spec_prefix()
376 +
377 + """ Define all of our core variables """
378 + self.set_target_profile()
379 + self.set_target_subpath()
380 + self.set_source_subpath()
381 +
382 + """ Set paths """
383 + self.set_snapshot_path()
384 + self.set_root_path()
385 + self.set_source_path()
386 + self.set_snapcache_path()
387 + self.set_chroot_path()
388 + self.set_autoresume_path()
389 + self.set_dest_path()
390 + self.set_stage_path()
391 + self.set_target_path()
392 +
393 + self.set_controller_file()
394 + self.set_action_sequence()
395 + self.set_use()
396 + self.set_cleanables()
397 + self.set_iso_volume_id()
398 + self.set_build_kernel_vars()
399 + self.set_fsscript()
400 + self.set_install_mask()
401 + self.set_rcadd()
402 + self.set_rcdel()
403 + self.set_cdtar()
404 + self.set_fstype()
405 + self.set_fsops()
406 + self.set_iso()
407 + self.set_packages()
408 + self.set_rm()
409 + self.set_linuxrc()
410 + self.set_busybox_config()
411 + self.set_overlay()
412 + self.set_portage_overlay()
413 + self.set_root_overlay()
414 +
415 + """
416 + This next line checks to make sure that the specified variables exist
417 + on disk.
418 + """
419 + #pdb.set_trace()
420 + file_locate(self.settings,["source_path","snapshot_path","distdir"],\
421 + expand=0)
422 + """ If we are using portage_confdir, check that as well. """
423 + if "portage_confdir" in self.settings:
424 + file_locate(self.settings,["portage_confdir"],expand=0)
425 +
426 + """ Setup our mount points """
427 + # initialize our target mounts.
428 + self.target_mounts = TARGET_MOUNT_DEFAULTS.copy()
429 +
430 + self.mounts = ["proc", "dev", "portdir", "distdir", "port_tmpdir"]
431 + # initialize our source mounts
432 + self.mountmap = SOURCE_MOUNT_DEFAULTS.copy()
433 + # update them from settings
434 + self.mountmap["distdir"] = self.settings["distdir"]
435 + if "snapcache" not in self.settings["options"]:
436 + self.mounts.remove("portdir")
437 + self.mountmap["portdir"] = None
438 + else:
439 + self.mountmap["portdir"] = normpath("/".join([
440 + self.settings["snapshot_cache_path"],
441 + self.settings["repo_name"],
442 + ]))
443 + if os.uname()[0] == "Linux":
444 + self.mounts.append("devpts")
445 + self.mounts.append("shm")
446 +
447 + self.set_mounts()
448 +
449 + """
450 + Configure any user specified options (either in catalyst.conf or on
451 + the command line).
452 + """
453 + if "pkgcache" in self.settings["options"]:
454 + self.set_pkgcache_path()
455 + print "Location of the package cache is "+\
456 + self.settings["pkgcache_path"]
457 + self.mounts.append("packagedir")
458 + self.mountmap["packagedir"] = self.settings["pkgcache_path"]
459 +
460 + if "kerncache" in self.settings["options"]:
461 + self.set_kerncache_path()
462 + print "Location of the kerncache is "+\
463 + self.settings["kerncache_path"]
464 + self.mounts.append("kerncache")
465 + self.mountmap["kerncache"] = self.settings["kerncache_path"]
466 +
467 + if "ccache" in self.settings["options"]:
468 + if "CCACHE_DIR" in os.environ:
469 + ccdir=os.environ["CCACHE_DIR"]
470 + del os.environ["CCACHE_DIR"]
471 + else:
472 + ccdir="/root/.ccache"
473 + if not os.path.isdir(ccdir):
474 + raise CatalystError,\
475 + "Compiler cache support can't be enabled (can't find "+\
476 + ccdir+")"
477 + self.mounts.append("ccache")
478 + self.mountmap["ccache"] = ccdir
479 + """ for the chroot: """
480 + self.env["CCACHE_DIR"] = self.target_mounts["ccache"]
481 +
482 + if "icecream" in self.settings["options"]:
483 + self.mounts.append("icecream")
484 + self.mountmap["icecream"] = self.settings["icecream"]
485 + self.env["PATH"] = self.target_mounts["icecream"] + ":" + \
486 + self.env["PATH"]
487 +
488 + if "port_logdir" in self.settings:
489 + self.mounts.append("port_logdir")
490 + self.mountmap["port_logdir"] = self.settings["port_logdir"]
491 + self.env["PORT_LOGDIR"] = self.settings["port_logdir"]
492 + self.env["PORT_LOGDIR_CLEAN"] = PORT_LOGDIR_CLEAN
493 +
494 + def override_cbuild(self):
495 + if "CBUILD" in self.makeconf:
496 + self.settings["CBUILD"]=self.makeconf["CBUILD"]
497 +
498 + def override_chost(self):
499 + if "CHOST" in self.makeconf:
500 + self.settings["CHOST"]=self.makeconf["CHOST"]
501 +
502 + def override_cflags(self):
503 + if "CFLAGS" in self.makeconf:
504 + self.settings["CFLAGS"]=self.makeconf["CFLAGS"]
505 +
506 + def override_cxxflags(self):
507 + if "CXXFLAGS" in self.makeconf:
508 + self.settings["CXXFLAGS"]=self.makeconf["CXXFLAGS"]
509 +
510 + def override_ldflags(self):
511 + if "LDFLAGS" in self.makeconf:
512 + self.settings["LDFLAGS"]=self.makeconf["LDFLAGS"]
513 +
514 + def set_install_mask(self):
515 + if "install_mask" in self.settings:
516 + if type(self.settings["install_mask"])!=types.StringType:
517 + self.settings["install_mask"]=\
518 + string.join(self.settings["install_mask"])
519 +
520 + def set_spec_prefix(self):
521 + self.settings["spec_prefix"]=self.settings["target"]
522 +
523 + def set_target_profile(self):
524 + self.settings["target_profile"]=self.settings["profile"]
525 +
526 + def set_target_subpath(self):
527 + self.settings["target_subpath"]=self.settings["rel_type"]+"/"+\
528 + self.settings["target"]+"-"+self.settings["subarch"]+"-"+\
529 + self.settings["version_stamp"]
530 +
531 + def set_source_subpath(self):
532 + if type(self.settings["source_subpath"])!=types.StringType:
533 + raise CatalystError,\
534 + "source_subpath should have been a string. Perhaps you have something wrong in your spec file?"
535 +
536 + def set_pkgcache_path(self):
537 + if "pkgcache_path" in self.settings:
538 + if type(self.settings["pkgcache_path"])!=types.StringType:
539 + self.settings["pkgcache_path"]=\
540 + normpath(string.join(self.settings["pkgcache_path"]))
541 + else:
542 + self.settings["pkgcache_path"]=\
543 + normpath(self.settings["storedir"]+"/packages/"+\
544 + self.settings["target_subpath"]+"/")
545 +
546 + def set_kerncache_path(self):
547 + if "kerncache_path" in self.settings:
548 + if type(self.settings["kerncache_path"])!=types.StringType:
549 + self.settings["kerncache_path"]=\
550 + normpath(string.join(self.settings["kerncache_path"]))
551 + else:
552 + self.settings["kerncache_path"]=normpath(self.settings["storedir"]+\
553 + "/kerncache/"+self.settings["target_subpath"]+"/")
554 +
555 + def set_target_path(self):
556 + self.settings["target_path"]=normpath(self.settings["storedir"]+\
557 + "/builds/"+self.settings["target_subpath"]+".tar.bz2")
558 + setup_target_path_resume = pjoin(self.settings["autoresume_path"],
559 + "setup_target_path")
560 + if "autoresume" in self.settings["options"] and \
561 + os.path.exists(setup_target_path_resume):
562 + print \
563 + "Resume point detected, skipping target path setup operation..."
564 + else:
565 + """ First clean up any existing target stuff """
566 + # XXX WTF are we removing the old tarball before we start building the
567 + # XXX new one? If the build fails, you don't want to be left with
568 + # XXX nothing at all
569 +# if os.path.isfile(self.settings["target_path"]):
570 +# cmd("rm -f "+self.settings["target_path"],\
571 +# "Could not remove existing file: "\
572 +# +self.settings["target_path"],env=self.env)
573 + touch(setup_target_path_resume)
574 +
575 + if not os.path.exists(self.settings["storedir"]+"/builds/"):
576 + os.makedirs(self.settings["storedir"]+"/builds/")
577 +
578 + def set_fsscript(self):
579 + if self.settings["spec_prefix"]+"/fsscript" in self.settings:
580 + self.settings["fsscript"]=\
581 + self.settings[self.settings["spec_prefix"]+"/fsscript"]
582 + del self.settings[self.settings["spec_prefix"]+"/fsscript"]
583 +
584 + def set_rcadd(self):
585 + if self.settings["spec_prefix"]+"/rcadd" in self.settings:
586 + self.settings["rcadd"]=\
587 + self.settings[self.settings["spec_prefix"]+"/rcadd"]
588 + del self.settings[self.settings["spec_prefix"]+"/rcadd"]
589 +
590 + def set_rcdel(self):
591 + if self.settings["spec_prefix"]+"/rcdel" in self.settings:
592 + self.settings["rcdel"]=\
593 + self.settings[self.settings["spec_prefix"]+"/rcdel"]
594 + del self.settings[self.settings["spec_prefix"]+"/rcdel"]
595 +
596 + def set_cdtar(self):
597 + if self.settings["spec_prefix"]+"/cdtar" in self.settings:
598 + self.settings["cdtar"]=\
599 + normpath(self.settings[self.settings["spec_prefix"]+"/cdtar"])
600 + del self.settings[self.settings["spec_prefix"]+"/cdtar"]
601 +
602 + def set_iso(self):
603 + if self.settings["spec_prefix"]+"/iso" in self.settings:
604 + if self.settings[self.settings["spec_prefix"]+"/iso"].startswith('/'):
605 + self.settings["iso"]=\
606 + normpath(self.settings[self.settings["spec_prefix"]+"/iso"])
607 + else:
608 + # This automatically prepends the build dir to the ISO output path
609 + # if it doesn't start with a /
610 + self.settings["iso"] = normpath(self.settings["storedir"] + \
611 + "/builds/" + self.settings["rel_type"] + "/" + \
612 + self.settings[self.settings["spec_prefix"]+"/iso"])
613 + del self.settings[self.settings["spec_prefix"]+"/iso"]
614 +
615 + def set_fstype(self):
616 + if self.settings["spec_prefix"]+"/fstype" in self.settings:
617 + self.settings["fstype"]=\
618 + self.settings[self.settings["spec_prefix"]+"/fstype"]
619 + del self.settings[self.settings["spec_prefix"]+"/fstype"]
620 +
621 + if "fstype" not in self.settings:
622 + self.settings["fstype"]="normal"
623 + for x in self.valid_values:
624 + if x == self.settings["spec_prefix"]+"/fstype":
625 + print "\n"+self.settings["spec_prefix"]+\
626 + "/fstype is being set to the default of \"normal\"\n"
627 +
628 + def set_fsops(self):
629 + if "fstype" in self.settings:
630 + self.valid_values.append("fsops")
631 + if self.settings["spec_prefix"]+"/fsops" in self.settings:
632 + self.settings["fsops"]=\
633 + self.settings[self.settings["spec_prefix"]+"/fsops"]
634 + del self.settings[self.settings["spec_prefix"]+"/fsops"]
635 +
636 + def set_source_path(self):
637 + if "seedcache" in self.settings["options"]\
638 + and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+\
639 + self.settings["source_subpath"]+"/")):
640 + self.settings["source_path"]=normpath(self.settings["storedir"]+\
641 + "/tmp/"+self.settings["source_subpath"]+"/")
642 + else:
643 + self.settings["source_path"]=normpath(self.settings["storedir"]+\
644 + "/builds/"+self.settings["source_subpath"]+".tar.bz2")
645 + if os.path.isfile(self.settings["source_path"]):
646 + # XXX: Is this even necessary if the previous check passes?
647 + if os.path.exists(self.settings["source_path"]):
648 + self.settings["source_path_hash"] = \
649 + self.settings["hash_map"].generate_hash(
650 + self.settings["source_path"],
651 + hash_ = self.settings["hash_function"],
652 + verbose = False)
653 + print "Source path set to "+self.settings["source_path"]
654 + if os.path.isdir(self.settings["source_path"]):
655 + print "\tIf this is not desired, remove this directory or turn off"
656 + print "\tseedcache in the options of catalyst.conf the source path"
657 + print "\twill then be "+\
658 + normpath(self.settings["storedir"]+"/builds/"+\
659 + self.settings["source_subpath"]+".tar.bz2\n")
660 +
661 + def set_dest_path(self):
662 + if "root_path" in self.settings:
663 + self.settings["destpath"]=normpath(self.settings["chroot_path"]+\
664 + self.settings["root_path"])
665 + else:
666 + self.settings["destpath"]=normpath(self.settings["chroot_path"])
667 +
668 + def set_cleanables(self):
669 + self.settings["cleanables"]=["/etc/resolv.conf","/var/tmp/*","/tmp/*",\
670 + "/root/*", self.settings["portdir"]]
671 +
672 + def set_snapshot_path(self):
673 + self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
674 + "/snapshots/" + self.settings["snapshot_name"] +
675 + self.settings["snapshot"] + ".tar.xz")
676 +
677 + if os.path.exists(self.settings["snapshot_path"]):
678 + self.settings["snapshot_path_hash"] = \
679 + self.settings["hash_map"].generate_hash(
680 + self.settings["snapshot_path"],
681 + hash_ = self.settings["hash_function"],
682 + verbose = False)
683 + else:
684 + self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
685 + "/snapshots/" + self.settings["snapshot_name"] +
686 + self.settings["snapshot"] + ".tar.bz2")
687 +
688 + if os.path.exists(self.settings["snapshot_path"]):
689 + self.settings["snapshot_path_hash"] = \
690 + self.settings["hash_map"].generate_hash(
691 + self.settings["snapshot_path"],
692 + hash_ = self.settings["hash_function"],
693 + verbose = False)
694 +
695 + def set_snapcache_path(self):
696 + if "snapcache" in self.settings["options"]:
697 + self.settings["snapshot_cache_path"] = \
698 + normpath(self.settings["snapshot_cache"] + "/" +
699 + self.settings["snapshot"])
700 + self.snapcache_lock=\
701 + LockDir(self.settings["snapshot_cache_path"])
702 + print "Caching snapshot to "+self.settings["snapshot_cache_path"]
703 +
704 + def set_chroot_path(self):
705 + """
706 + NOTE: the trailing slash has been removed
707 + Things *could* break if you don't use a proper join()
708 + """
709 + self.settings["chroot_path"]=normpath(self.settings["storedir"]+\
710 + "/tmp/"+self.settings["target_subpath"])
711 + self.chroot_lock=LockDir(self.settings["chroot_path"])
712 +
713 + def set_autoresume_path(self):
714 + self.settings["autoresume_path"] = normpath(pjoin(
715 + self.settings["storedir"], "tmp", self.settings["rel_type"],
716 + ".autoresume-%s-%s-%s"
717 + %(self.settings["target"], self.settings["subarch"],
718 + self.settings["version_stamp"])
719 + ))
720 + if "autoresume" in self.settings["options"]:
721 + print "The autoresume path is " + self.settings["autoresume_path"]
722 + if not os.path.exists(self.settings["autoresume_path"]):
723 + os.makedirs(self.settings["autoresume_path"],0755)
724 +
725 + def set_controller_file(self):
726 + self.settings["controller_file"]=normpath(self.settings["sharedir"]+\
727 + "/targets/"+self.settings["target"]+"/"+self.settings["target"]+\
728 + "-controller.sh")
729 +
730 + def set_iso_volume_id(self):
731 + if self.settings["spec_prefix"]+"/volid" in self.settings:
732 + self.settings["iso_volume_id"]=\
733 + self.settings[self.settings["spec_prefix"]+"/volid"]
734 + if len(self.settings["iso_volume_id"])>32:
735 + raise CatalystError,\
736 + "ISO volume ID must not exceed 32 characters."
737 + else:
738 + self.settings["iso_volume_id"]="catalyst "+self.settings["snapshot"]
739 +
740 + def set_action_sequence(self):
741 + """ Default action sequence for run method """
742 + self.settings["action_sequence"]=["unpack","unpack_snapshot",\
743 + "setup_confdir","portage_overlay",\
744 + "base_dirs","bind","chroot_setup","setup_environment",\
745 + "run_local","preclean","unbind","clean"]
746 +# if "TARBALL" in self.settings or \
747 +# "fetch" not in self.settings["options"]:
748 + if "fetch" not in self.settings["options"]:
749 + self.settings["action_sequence"].append("capture")
750 + self.settings["action_sequence"].append("clear_autoresume")
751 +
752 + def set_use(self):
753 + if self.settings["spec_prefix"]+"/use" in self.settings:
754 + self.settings["use"]=\
755 + self.settings[self.settings["spec_prefix"]+"/use"]
756 + del self.settings[self.settings["spec_prefix"]+"/use"]
757 + if "use" not in self.settings:
758 + self.settings["use"]=""
759 + if type(self.settings["use"])==types.StringType:
760 + self.settings["use"]=self.settings["use"].split()
761 +
762 + # Force bindist when options ask for it
763 + if "BINDIST" in self.settings:
764 + self.settings["use"].append("bindist")
765 +
766 + def set_stage_path(self):
767 + self.settings["stage_path"]=normpath(self.settings["chroot_path"])
768 +
769 + def set_mounts(self):
770 + pass
771 +
772 + def set_packages(self):
773 + pass
774 +
775 + def set_rm(self):
776 + if self.settings["spec_prefix"]+"/rm" in self.settings:
777 + if type(self.settings[self.settings["spec_prefix"]+\
778 + "/rm"])==types.StringType:
779 + self.settings[self.settings["spec_prefix"]+"/rm"]=\
780 + self.settings[self.settings["spec_prefix"]+"/rm"].split()
781 +
782 + def set_linuxrc(self):
783 + if self.settings["spec_prefix"]+"/linuxrc" in self.settings:
784 + if type(self.settings[self.settings["spec_prefix"]+\
785 + "/linuxrc"])==types.StringType:
786 + self.settings["linuxrc"]=\
787 + self.settings[self.settings["spec_prefix"]+"/linuxrc"]
788 + del self.settings[self.settings["spec_prefix"]+"/linuxrc"]
789 +
790 + def set_busybox_config(self):
791 + if self.settings["spec_prefix"]+"/busybox_config" in self.settings:
792 + if type(self.settings[self.settings["spec_prefix"]+\
793 + "/busybox_config"])==types.StringType:
794 + self.settings["busybox_config"]=\
795 + self.settings[self.settings["spec_prefix"]+"/busybox_config"]
796 + del self.settings[self.settings["spec_prefix"]+"/busybox_config"]
797 +
798 + def set_portage_overlay(self):
799 + if "portage_overlay" in self.settings:
800 + if type(self.settings["portage_overlay"])==types.StringType:
801 + self.settings["portage_overlay"]=\
802 + self.settings["portage_overlay"].split()
803 + print "portage_overlay directories are set to: \""+\
804 + string.join(self.settings["portage_overlay"])+"\""
805 +
806 + def set_overlay(self):
807 + if self.settings["spec_prefix"]+"/overlay" in self.settings:
808 + if type(self.settings[self.settings["spec_prefix"]+\
809 + "/overlay"])==types.StringType:
810 + self.settings[self.settings["spec_prefix"]+"/overlay"]=\
811 + self.settings[self.settings["spec_prefix"]+\
812 + "/overlay"].split()
813 +
814 + def set_root_overlay(self):
815 + if self.settings["spec_prefix"]+"/root_overlay" in self.settings:
816 + if type(self.settings[self.settings["spec_prefix"]+\
817 + "/root_overlay"])==types.StringType:
818 + self.settings[self.settings["spec_prefix"]+"/root_overlay"]=\
819 + self.settings[self.settings["spec_prefix"]+\
820 + "/root_overlay"].split()
821 +
822 + def set_root_path(self):
823 + """ ROOT= variable for emerges """
824 + self.settings["root_path"]="/"
825 +
826 + def set_valid_build_kernel_vars(self,addlargs):
827 + if "boot/kernel" in addlargs:
828 + if type(addlargs["boot/kernel"])==types.StringType:
829 + loopy=[addlargs["boot/kernel"]]
830 + else:
831 + loopy=addlargs["boot/kernel"]
832 +
833 + for x in loopy:
834 + self.valid_values.append("boot/kernel/"+x+"/aliases")
835 + self.valid_values.append("boot/kernel/"+x+"/config")
836 + self.valid_values.append("boot/kernel/"+x+"/console")
837 + self.valid_values.append("boot/kernel/"+x+"/extraversion")
838 + self.valid_values.append("boot/kernel/"+x+"/gk_action")
839 + self.valid_values.append("boot/kernel/"+x+"/gk_kernargs")
840 + self.valid_values.append("boot/kernel/"+x+"/initramfs_overlay")
841 + self.valid_values.append("boot/kernel/"+x+"/machine_type")
842 + self.valid_values.append("boot/kernel/"+x+"/sources")
843 + self.valid_values.append("boot/kernel/"+x+"/softlevel")
844 + self.valid_values.append("boot/kernel/"+x+"/use")
845 + self.valid_values.append("boot/kernel/"+x+"/packages")
846 + if "boot/kernel/"+x+"/packages" in addlargs:
847 + if type(addlargs["boot/kernel/"+x+\
848 + "/packages"])==types.StringType:
849 + addlargs["boot/kernel/"+x+"/packages"]=\
850 + [addlargs["boot/kernel/"+x+"/packages"]]
851 +
852 + def set_build_kernel_vars(self):
853 + if self.settings["spec_prefix"]+"/gk_mainargs" in self.settings:
854 + self.settings["gk_mainargs"]=\
855 + self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
856 + del self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
857 +
858 + def kill_chroot_pids(self):
859 + print "Checking for processes running in chroot and killing them."
860 +
861 + """
862 + Force environment variables to be exported so script can see them
863 + """
864 + self.setup_environment()
865 +
866 + if os.path.exists(self.settings["sharedir"]+\
867 + "/targets/support/kill-chroot-pids.sh"):
868 + cmd("/bin/bash "+self.settings["sharedir"]+\
869 + "/targets/support/kill-chroot-pids.sh",\
870 + "kill-chroot-pids script failed.",env=self.env)
871 +
872 + def mount_safety_check(self):
873 + """
874 + Check and verify that none of our paths in mypath are mounted. We don't
875 + want to clean up with things still mounted, and this allows us to check.
876 + Returns 1 on ok, 0 on "something is still mounted" case.
877 + """
878 +
879 + if not os.path.exists(self.settings["chroot_path"]):
880 + return
881 +
882 + print "self.mounts =", self.mounts
883 + for x in self.mounts:
884 + target = normpath(self.settings["chroot_path"] + self.target_mounts[x])
885 + print "mount_safety_check() x =", x, target
886 + if not os.path.exists(target):
887 + continue
888 +
889 + if ismount(target):
890 + """ Something is still mounted "" """
891 + try:
892 + print target + " is still mounted; performing auto-bind-umount...",
893 + """ Try to umount stuff ourselves """
894 + self.unbind()
895 + if ismount(target):
896 + raise CatalystError, "Auto-unbind failed for " + target
897 + else:
898 + print "Auto-unbind successful..."
899 + except CatalystError:
900 + raise CatalystError, "Unable to auto-unbind " + target
901 +
902 + def unpack(self):
903 + unpack=True
904 +
905 + unpack_resume = pjoin(self.settings["autoresume_path"], "unpack")
906 + clst_unpack_hash=read_from_clst(unpack_resume)
907 +
908 + if "seedcache" in self.settings["options"]:
909 + if os.path.isdir(self.settings["source_path"]):
910 + """ SEEDCACHE Is a directory, use rsync """
911 + unpack_cmd="rsync -a --delete "+self.settings["source_path"]+\
912 + " "+self.settings["chroot_path"]
913 + display_msg="\nStarting rsync from "+\
914 + self.settings["source_path"]+"\nto "+\
915 + self.settings["chroot_path"]+\
916 + " (This may take some time) ...\n"
917 + error_msg="Rsync of "+self.settings["source_path"]+" to "+\
918 + self.settings["chroot_path"]+" failed."
919 + else:
920 + """ SEEDCACHE is a not a directory, try untar'ing """
921 + print "Referenced SEEDCACHE does not appear to be a directory, trying to untar..."
922 + display_msg="\nStarting tar extract from "+\
923 + self.settings["source_path"]+"\nto "+\
924 + self.settings["chroot_path"]+\
925 + " (This may take some time) ...\n"
926 + if "bz2" == self.settings["chroot_path"][-3:]:
927 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
928 + self.settings["chroot_path"]
929 + else:
930 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
931 + self.settings["chroot_path"]
932 + error_msg="Tarball extraction of "+\
933 + self.settings["source_path"]+" to "+\
934 + self.settings["chroot_path"]+" failed."
935 + else:
936 + """ No SEEDCACHE, use tar """
937 + display_msg="\nStarting tar extract from "+\
938 + self.settings["source_path"]+"\nto "+\
939 + self.settings["chroot_path"]+\
940 + " (This may take some time) ...\n"
941 + if "bz2" == self.settings["chroot_path"][-3:]:
942 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
943 + self.settings["chroot_path"]
944 + else:
945 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
946 + self.settings["chroot_path"]
947 + error_msg="Tarball extraction of "+self.settings["source_path"]+\
948 + " to "+self.settings["chroot_path"]+" failed."
949 +
950 + if "autoresume" in self.settings["options"]:
951 + if os.path.isdir(self.settings["source_path"]) \
952 + and os.path.exists(unpack_resume):
953 + """ Autoresume is valid, SEEDCACHE is valid """
954 + unpack=False
955 + invalid_snapshot=False
956 +
957 + elif os.path.isfile(self.settings["source_path"]) \
958 + and self.settings["source_path_hash"]==clst_unpack_hash:
959 + """ Autoresume is valid, tarball is valid """
960 + unpack=False
961 + invalid_snapshot=True
962 +
963 + elif os.path.isdir(self.settings["source_path"]) \
964 + and not os.path.exists(unpack_resume):
965 + """ Autoresume is invalid, SEEDCACHE """
966 + unpack=True
967 + invalid_snapshot=False
968 +
969 + elif os.path.isfile(self.settings["source_path"]) \
970 + and self.settings["source_path_hash"]!=clst_unpack_hash:
971 + """ Autoresume is invalid, tarball """
972 + unpack=True
973 + invalid_snapshot=True
974 + else:
975 + """ No autoresume, SEEDCACHE """
976 + if "seedcache" in self.settings["options"]:
977 + """ SEEDCACHE so let's run rsync and let it clean up """
978 + if os.path.isdir(self.settings["source_path"]):
979 + unpack=True
980 + invalid_snapshot=False
981 + elif os.path.isfile(self.settings["source_path"]):
982 + """ Tarball so unpack and remove anything already there """
983 + unpack=True
984 + invalid_snapshot=True
985 + """ No autoresume, no SEEDCACHE """
986 + else:
987 + """ Tarball so unpack and remove anything already there """
988 + if os.path.isfile(self.settings["source_path"]):
989 + unpack=True
990 + invalid_snapshot=True
991 + elif os.path.isdir(self.settings["source_path"]):
992 + """ We should never reach this, so something is very wrong """
993 + raise CatalystError,\
994 + "source path is a dir but seedcache is not enabled"
995 +
996 + if unpack:
997 + self.mount_safety_check()
998 +
999 + if invalid_snapshot:
1000 + if "autoresume" in self.settings["options"]:
1001 + print "No Valid Resume point detected, cleaning up..."
1002 +
1003 + self.clear_autoresume()
1004 + self.clear_chroot()
1005 +
1006 + if not os.path.exists(self.settings["chroot_path"]):
1007 + os.makedirs(self.settings["chroot_path"])
1008 +
1009 + if not os.path.exists(self.settings["chroot_path"]+"/tmp"):
1010 + os.makedirs(self.settings["chroot_path"]+"/tmp",1777)
1011 +
1012 + if "pkgcache" in self.settings["options"]:
1013 + if not os.path.exists(self.settings["pkgcache_path"]):
1014 + os.makedirs(self.settings["pkgcache_path"],0755)
1015 +
1016 + if "kerncache" in self.settings["options"]:
1017 + if not os.path.exists(self.settings["kerncache_path"]):
1018 + os.makedirs(self.settings["kerncache_path"],0755)
1019 +
1020 + print display_msg
1021 + cmd(unpack_cmd,error_msg,env=self.env)
1022 +
1023 + if "source_path_hash" in self.settings:
1024 + myf=open(unpack_resume,"w")
1025 + myf.write(self.settings["source_path_hash"])
1026 + myf.close()
1027 + else:
1028 + touch(unpack_resume)
1029 + else:
1030 + print "Resume point detected, skipping unpack operation..."
1031 +
1032 + def unpack_snapshot(self):
1033 + unpack=True
1034 + unpack_portage_resume = pjoin(self.settings["autoresume_path"],
1035 + "unpack_portage")
1036 + snapshot_hash=read_from_clst(unpack_portage_resume)
1037 +
1038 + if "snapcache" in self.settings["options"]:
1039 + snapshot_cache_hash=\
1040 + read_from_clst(self.settings["snapshot_cache_path"] + "/" +
1041 + "catalyst-hash")
1042 + destdir=self.settings["snapshot_cache_path"]
1043 + if "bz2" == self.settings["chroot_path"][-3:]:
1044 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["snapshot_path"]+" -C "+destdir
1045 + else:
1046 + unpack_cmd="tar xpf "+self.settings["snapshot_path"]+" -C "+destdir
1047 + unpack_errmsg="Error unpacking snapshot"
1048 + cleanup_msg="Cleaning up invalid snapshot cache at \n\t"+\
1049 + self.settings["snapshot_cache_path"]+\
1050 + " (This can take a long time)..."
1051 + cleanup_errmsg="Error removing existing snapshot cache directory."
1052 + self.snapshot_lock_object=self.snapcache_lock
1053 +
1054 + if self.settings["snapshot_path_hash"]==snapshot_cache_hash:
1055 + print "Valid snapshot cache, skipping unpack of portage tree..."
1056 + unpack=False
1057 + else:
1058 + destdir = normpath(self.settings["chroot_path"] + self.settings["portdir"])
1059 + cleanup_errmsg="Error removing existing snapshot directory."
1060 + cleanup_msg=\
1061 + "Cleaning up existing portage tree (This can take a long time)..."
1062 + if "bz2" == self.settings["chroot_path"][-3:]:
1063 + unpack_cmd="tar -I lbzip2 -xpf "+self.settings["snapshot_path"]+" -C "+\
1064 + self.settings["chroot_path"]+"/usr"
1065 + else:
1066 + unpack_cmd="tar xpf "+self.settings["snapshot_path"]+" -C "+\
1067 + self.settings["chroot_path"]+"/usr"
1068 + unpack_errmsg="Error unpacking snapshot"
1069 +
1070 + if "autoresume" in self.settings["options"] \
1071 + and os.path.exists(self.settings["chroot_path"]+\
1072 + self.settings["portdir"]) \
1073 + and os.path.exists(unpack_portage_resume) \
1074 + and self.settings["snapshot_path_hash"] == snapshot_hash:
1075 + print \
1076 + "Valid Resume point detected, skipping unpack of portage tree..."
1077 + unpack=False
1078 +
1079 + if unpack:
1080 + if "snapcache" in self.settings["options"]:
1081 + self.snapshot_lock_object.write_lock()
1082 + if os.path.exists(destdir):
1083 + print cleanup_msg
1084 + cleanup_cmd="rm -rf "+destdir
1085 + cmd(cleanup_cmd,cleanup_errmsg,env=self.env)
1086 + if not os.path.exists(destdir):
1087 + os.makedirs(destdir,0755)
1088 +
1089 + print "Unpacking portage tree (This can take a long time) ..."
1090 + cmd(unpack_cmd,unpack_errmsg,env=self.env)
1091 +
1092 + if "snapcache" in self.settings["options"]:
1093 + myf=open(self.settings["snapshot_cache_path"] +
1094 + "/" + "catalyst-hash","w")
1095 + myf.write(self.settings["snapshot_path_hash"])
1096 + myf.close()
1097 + else:
1098 + print "Setting snapshot autoresume point"
1099 + myf=open(unpack_portage_resume,"w")
1100 + myf.write(self.settings["snapshot_path_hash"])
1101 + myf.close()
1102 +
1103 + if "snapcache" in self.settings["options"]:
1104 + self.snapshot_lock_object.unlock()
1105 +
1106 + def config_profile_link(self):
1107 + config_protect_link_resume = pjoin(self.settings["autoresume_path"],
1108 + "config_profile_link")
1109 + if "autoresume" in self.settings["options"] \
1110 + and os.path.exists(config_protect_link_resume):
1111 + print \
1112 + "Resume point detected, skipping config_profile_link operation..."
1113 + else:
1114 + # TODO: zmedico and I discussed making this a directory and pushing
1115 + # in a parent file, as well as other user-specified configuration.
1116 + print "Configuring profile link..."
1117 + cmd("rm -f "+self.settings["chroot_path"]+"/etc/portage/make.profile",\
1118 + "Error zapping profile link",env=self.env)
1119 + cmd("mkdir -p "+self.settings["chroot_path"]+"/etc/portage/")
1120 + cmd("ln -sf ../.." + self.settings["portdir"] + "/profiles/" + \
1121 + self.settings["target_profile"]+" "+\
1122 + self.settings["chroot_path"]+"/etc/portage/make.profile",\
1123 + "Error creating profile link",env=self.env)
1124 + touch(config_protect_link_resume)
1125 +
1126 + def setup_confdir(self):
1127 + setup_confdir_resume = pjoin(self.settings["autoresume_path"],
1128 + "setup_confdir")
1129 + if "autoresume" in self.settings["options"] \
1130 + and os.path.exists(setup_confdir_resume):
1131 + print "Resume point detected, skipping setup_confdir operation..."
1132 + else:
1133 + if "portage_confdir" in self.settings:
1134 + print "Configuring /etc/portage..."
1135 + cmd("rsync -a "+self.settings["portage_confdir"]+"/ "+\
1136 + self.settings["chroot_path"]+"/etc/portage/",\
1137 + "Error copying /etc/portage",env=self.env)
1138 + touch(setup_confdir_resume)
1139 +
1140 + def portage_overlay(self):
1141 + """ We copy the contents of our overlays to /usr/local/portage """
1142 + if "portage_overlay" in self.settings:
1143 + for x in self.settings["portage_overlay"]:
1144 + if os.path.exists(x):
1145 + print "Copying overlay dir " +x
1146 + cmd("mkdir -p "+self.settings["chroot_path"]+\
1147 + self.settings["local_overlay"],\
1148 + "Could not make portage_overlay dir",env=self.env)
1149 + cmd("cp -R "+x+"/* "+self.settings["chroot_path"]+\
1150 + self.settings["local_overlay"],\
1151 + "Could not copy portage_overlay",env=self.env)
1152 +
1153 + def root_overlay(self):
1154 + """ Copy over the root_overlay """
1155 + if self.settings["spec_prefix"]+"/root_overlay" in self.settings:
1156 + for x in self.settings[self.settings["spec_prefix"]+\
1157 + "/root_overlay"]:
1158 + if os.path.exists(x):
1159 + print "Copying root_overlay: "+x
1160 + cmd("rsync -a "+x+"/ "+\
1161 + self.settings["chroot_path"],\
1162 + self.settings["spec_prefix"]+"/root_overlay: "+x+\
1163 + " copy failed.",env=self.env)
1164 +
1165 + def base_dirs(self):
1166 + pass
1167 +
1168 + def bind(self):
1169 + for x in self.mounts:
1170 + #print "bind(); x =", x
1171 + target = normpath(self.settings["chroot_path"] + self.target_mounts[x])
1172 + if not os.path.exists(target):
1173 + os.makedirs(target, 0755)
1174 +
1175 + if not os.path.exists(self.mountmap[x]):
1176 + if self.mountmap[x] not in ["tmpfs", "shmfs"]:
1177 + os.makedirs(self.mountmap[x], 0755)
1178 +
1179 + src=self.mountmap[x]
1180 + #print "bind(); src =", src
1181 + if "snapcache" in self.settings["options"] and x == "portdir":
1182 + self.snapshot_lock_object.read_lock()
1183 + if os.uname()[0] == "FreeBSD":
1184 + if src == "/dev":
1185 + cmd = "mount -t devfs none " + target
1186 + retval=os.system(cmd)
1187 + else:
1188 + cmd = "mount_nullfs " + src + " " + target
1189 + retval=os.system(cmd)
1190 + else:
1191 + if src == "tmpfs":
1192 + if "var_tmpfs_portage" in self.settings:
1193 + cmd = "mount -t tmpfs -o size=" + \
1194 + self.settings["var_tmpfs_portage"] + "G " + \
1195 + src + " " + target
1196 + retval=os.system(cmd)
1197 + elif src == "shmfs":
1198 + cmd = "mount -t tmpfs -o noexec,nosuid,nodev shm " + target
1199 + retval=os.system(cmd)
1200 + else:
1201 + cmd = "mount --bind " + src + " " + target
1202 + #print "bind(); cmd =", cmd
1203 + retval=os.system(cmd)
1204 + if retval!=0:
1205 + self.unbind()
1206 + raise CatalystError,"Couldn't bind mount " + src
1207 +
1208 + def unbind(self):
1209 + ouch=0
1210 + mypath=self.settings["chroot_path"]
1211 + myrevmounts=self.mounts[:]
1212 + myrevmounts.reverse()
1213 + """ Unmount in reverse order for nested bind-mounts """
1214 + for x in myrevmounts:
1215 + target = normpath(mypath + self.target_mounts[x])
1216 + if not os.path.exists(target):
1217 + continue
1218 +
1219 + if not ismount(target):
1220 + continue
1221 +
1222 + retval=os.system("umount " + target)
1223 +
1224 + if retval!=0:
1225 + warn("First attempt to unmount: " + target + " failed.")
1226 + warn("Killing any pids still running in the chroot")
1227 +
1228 + self.kill_chroot_pids()
1229 +
1230 + retval2 = os.system("umount " + target)
1231 + if retval2!=0:
1232 + ouch=1
1233 + warn("Couldn't umount bind mount: " + target)
1234 +
1235 + if "snapcache" in self.settings["options"] and x == "/usr/portage":
1236 + try:
1237 + """
1238 + It's possible the snapshot lock object isn't created yet.
1239 + This is because mount safety check calls unbind before the
1240 + target is fully initialized
1241 + """
1242 + self.snapshot_lock_object.unlock()
1243 + except:
1244 + pass
1245 + if ouch:
1246 + """
1247 + if any bind mounts really failed, then we need to raise
1248 + this to potentially prevent an upcoming bash stage cleanup script
1249 + from wiping our bind mounts.
1250 + """
1251 + raise CatalystError,\
1252 + "Couldn't umount one or more bind-mounts; aborting for safety."
1253 +
1254 + def chroot_setup(self):
1255 + self.makeconf=read_makeconf(self.settings["chroot_path"]+\
1256 + "/etc/portage/make.conf")
1257 + self.override_cbuild()
1258 + self.override_chost()
1259 + self.override_cflags()
1260 + self.override_cxxflags()
1261 + self.override_ldflags()
1262 + chroot_setup_resume = pjoin(self.settings["autoresume_path"],
1263 + "chroot_setup")
1264 + if "autoresume" in self.settings["options"] \
1265 + and os.path.exists(chroot_setup_resume):
1266 + print "Resume point detected, skipping chroot_setup operation..."
1267 + else:
1268 + print "Setting up chroot..."
1269 +
1270 + #self.makeconf=read_makeconf(self.settings["chroot_path"]+"/etc/portage/make.conf")
1271 +
1272 + cmd("cp /etc/resolv.conf " + self.settings["chroot_path"] + "/etc/",
1273 + "Could not copy resolv.conf into place.",env=self.env)
1274 +
1275 + """ Copy over the envscript, if applicable """
1276 + if "envscript" in self.settings:
1277 + if not os.path.exists(self.settings["envscript"]):
1278 + raise CatalystError,\
1279 + "Can't find envscript "+self.settings["envscript"]
1280 +
1281 + print "\nWarning!!!!"
1282 + print "\tOverriding certain env variables may cause catastrophic failure."
1283 + print "\tIf your build fails look here first as the possible problem."
1284 + print "\tCatalyst assumes you know what you are doing when setting"
1285 + print "\t\tthese variables."
1286 + print "\tCatalyst Maintainers use VERY minimal envscripts if used at all"
1287 + print "\tYou have been warned\n"
1288 +
1289 + cmd("cp "+self.settings["envscript"]+" "+\
1290 + self.settings["chroot_path"]+"/tmp/envscript",\
1291 + "Could not copy envscript into place.",env=self.env)
1292 +
1293 + """
1294 + Copy over /etc/hosts from the host in case there are any
1295 + specialties in there
1296 + """
1297 + if os.path.exists(self.settings["chroot_path"]+"/etc/hosts"):
1298 + cmd("mv "+self.settings["chroot_path"]+"/etc/hosts "+\
1299 + self.settings["chroot_path"]+"/etc/hosts.catalyst",\
1300 + "Could not backup /etc/hosts",env=self.env)
1301 + cmd("cp /etc/hosts "+self.settings["chroot_path"]+"/etc/hosts",\
1302 + "Could not copy /etc/hosts",env=self.env)
1303 +
1304 + """ Modify and write out make.conf (for the chroot) """
1305 + cmd("rm -f "+self.settings["chroot_path"]+"/etc/portage/make.conf",\
1306 + "Could not remove "+self.settings["chroot_path"]+\
1307 + "/etc/portage/make.conf",env=self.env)
1308 + myf=open(self.settings["chroot_path"]+"/etc/portage/make.conf","w")
1309 + myf.write("# These settings were set by the catalyst build script that automatically\n# built this stage.\n")
1310 + myf.write("# Please consult /usr/share/portage/config/make.conf.example for a more\n# detailed example.\n")
1311 + if "CFLAGS" in self.settings:
1312 + myf.write('CFLAGS="'+self.settings["CFLAGS"]+'"\n')
1313 + if "CXXFLAGS" in self.settings:
1314 + if self.settings["CXXFLAGS"]!=self.settings["CFLAGS"]:
1315 + myf.write('CXXFLAGS="'+self.settings["CXXFLAGS"]+'"\n')
1316 + else:
1317 + myf.write('CXXFLAGS="${CFLAGS}"\n')
1318 + else:
1319 + myf.write('CXXFLAGS="${CFLAGS}"\n')
1320 +
1321 + if "LDFLAGS" in self.settings:
1322 + myf.write("# LDFLAGS is unsupported. USE AT YOUR OWN RISK!\n")
1323 + myf.write('LDFLAGS="'+self.settings["LDFLAGS"]+'"\n')
1324 + if "CBUILD" in self.settings:
1325 + 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")
1326 + myf.write('CBUILD="'+self.settings["CBUILD"]+'"\n')
1327 +
1328 + 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")
1329 + myf.write('CHOST="'+self.settings["CHOST"]+'"\n')
1330 +
1331 + """ Figure out what our USE vars are for building """
1332 + myusevars=[]
1333 + if "HOSTUSE" in self.settings:
1334 + myusevars.extend(self.settings["HOSTUSE"])
1335 +
1336 + if "use" in self.settings:
1337 + myusevars.extend(self.settings["use"])
1338 +
1339 + if myusevars:
1340 + myf.write("# These are the USE flags that were used in addition to what is provided by the\n# profile used for building.\n")
1341 + myusevars = sorted(set(myusevars))
1342 + myf.write('USE="'+string.join(myusevars)+'"\n')
1343 + if '-*' in myusevars:
1344 + print "\nWarning!!! "
1345 + print "\tThe use of -* in "+self.settings["spec_prefix"]+\
1346 + "/use will cause portage to ignore"
1347 + print "\tpackage.use in the profile and portage_confdir. You've been warned!"
1348 +
1349 + myf.write('PORTDIR="%s"\n' % self.settings['portdir'])
1350 + myf.write('DISTDIR="%s"\n' % self.settings['distdir'])
1351 + myf.write('PKGDIR="%s"\n' % self.settings['packagedir'])
1352 +
1353 + """ Setup the portage overlay """
1354 + if "portage_overlay" in self.settings:
1355 + myf.write('PORTDIR_OVERLAY="/usr/local/portage"\n')
1356 +
1357 + myf.close()
1358 + cmd("cp "+self.settings["chroot_path"]+"/etc/portage/make.conf "+\
1359 + self.settings["chroot_path"]+"/etc/portage/make.conf.catalyst",\
1360 + "Could not backup /etc/portage/make.conf",env=self.env)
1361 + touch(chroot_setup_resume)
1362 +
1363 + def fsscript(self):
1364 + fsscript_resume = pjoin(self.settings["autoresume_path"], "fsscript")
1365 + if "autoresume" in self.settings["options"] \
1366 + and os.path.exists(fsscript_resume):
1367 + print "Resume point detected, skipping fsscript operation..."
1368 + else:
1369 + if "fsscript" in self.settings:
1370 + if os.path.exists(self.settings["controller_file"]):
1371 + cmd(self.settings["controller_file"]+\
1372 + " fsscript","fsscript script failed.",env=self.env)
1373 + touch(fsscript_resume)
1374 +
1375 + def rcupdate(self):
1376 + rcupdate_resume = pjoin(self.settings["autoresume_path"], "rcupdate")
1377 + if "autoresume" in self.settings["options"] \
1378 + and os.path.exists(rcupdate_resume):
1379 + print "Resume point detected, skipping rcupdate operation..."
1380 + else:
1381 + if os.path.exists(self.settings["controller_file"]):
1382 + cmd(self.settings["controller_file"]+" rc-update",\
1383 + "rc-update script failed.",env=self.env)
1384 + touch(rcupdate_resume)
1385 +
1386 + def clean(self):
1387 + clean_resume = pjoin(self.settings["autoresume_path"], "clean")
1388 + if "autoresume" in self.settings["options"] \
1389 + and os.path.exists(clean_resume):
1390 + print "Resume point detected, skipping clean operation..."
1391 + else:
1392 + for x in self.settings["cleanables"]:
1393 + print "Cleaning chroot: "+x+"... "
1394 + cmd("rm -rf "+self.settings["destpath"]+x,"Couldn't clean "+\
1395 + x,env=self.env)
1396 +
1397 + """ Put /etc/hosts back into place """
1398 + if os.path.exists(self.settings["chroot_path"]+"/etc/hosts.catalyst"):
1399 + cmd("mv -f "+self.settings["chroot_path"]+"/etc/hosts.catalyst "+\
1400 + self.settings["chroot_path"]+"/etc/hosts",\
1401 + "Could not replace /etc/hosts",env=self.env)
1402 +
1403 + """ Remove our overlay """
1404 + if os.path.exists(self.settings["chroot_path"] + self.settings["local_overlay"]):
1405 + cmd("rm -rf " + self.settings["chroot_path"] + self.settings["local_overlay"],
1406 + "Could not remove " + self.settings["local_overlay"], env=self.env)
1407 + cmd("sed -i '/^PORTDIR_OVERLAY/d' "+self.settings["chroot_path"]+\
1408 + "/etc/portage/make.conf",\
1409 + "Could not remove PORTDIR_OVERLAY from make.conf",env=self.env)
1410 +
1411 + """ Clean up old and obsoleted files in /etc """
1412 + if os.path.exists(self.settings["stage_path"]+"/etc"):
1413 + cmd("find "+self.settings["stage_path"]+\
1414 + "/etc -maxdepth 1 -name \"*-\" | xargs rm -f",\
1415 + "Could not remove stray files in /etc",env=self.env)
1416 +
1417 + if os.path.exists(self.settings["controller_file"]):
1418 + cmd(self.settings["controller_file"]+" clean",\
1419 + "clean script failed.",env=self.env)
1420 + touch(clean_resume)
1421 +
1422 + def empty(self):
1423 + empty_resume = pjoin(self.settings["autoresume_path"], "empty")
1424 + if "autoresume" in self.settings["options"] \
1425 + and os.path.exists(empty_resume):
1426 + print "Resume point detected, skipping empty operation..."
1427 + else:
1428 + if self.settings["spec_prefix"]+"/empty" in self.settings:
1429 + if type(self.settings[self.settings["spec_prefix"]+\
1430 + "/empty"])==types.StringType:
1431 + self.settings[self.settings["spec_prefix"]+"/empty"]=\
1432 + self.settings[self.settings["spec_prefix"]+\
1433 + "/empty"].split()
1434 + for x in self.settings[self.settings["spec_prefix"]+"/empty"]:
1435 + myemp=self.settings["destpath"]+x
1436 + if not os.path.isdir(myemp) or os.path.islink(myemp):
1437 + print x,"not a directory or does not exist, skipping 'empty' operation."
1438 + continue
1439 + print "Emptying directory",x
1440 + """
1441 + stat the dir, delete the dir, recreate the dir and set
1442 + the proper perms and ownership
1443 + """
1444 + mystat=os.stat(myemp)
1445 + shutil.rmtree(myemp)
1446 + os.makedirs(myemp,0755)
1447 + os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
1448 + os.chmod(myemp,mystat[ST_MODE])
1449 + touch(empty_resume)
1450 +
1451 + def remove(self):
1452 + remove_resume = pjoin(self.settings["autoresume_path"], "remove")
1453 + if "autoresume" in self.settings["options"] \
1454 + and os.path.exists(remove_resume):
1455 + print "Resume point detected, skipping remove operation..."
1456 + else:
1457 + if self.settings["spec_prefix"]+"/rm" in self.settings:
1458 + for x in self.settings[self.settings["spec_prefix"]+"/rm"]:
1459 + """
1460 + We're going to shell out for all these cleaning
1461 + operations, so we get easy glob handling.
1462 + """
1463 + print "livecd: removing "+x
1464 + os.system("rm -rf "+self.settings["chroot_path"]+x)
1465 + try:
1466 + if os.path.exists(self.settings["controller_file"]):
1467 + cmd(self.settings["controller_file"]+\
1468 + " clean","Clean failed.",env=self.env)
1469 + touch(remove_resume)
1470 + except:
1471 + self.unbind()
1472 + raise
1473 +
1474 + def preclean(self):
1475 + preclean_resume = pjoin(self.settings["autoresume_path"], "preclean")
1476 + if "autoresume" in self.settings["options"] \
1477 + and os.path.exists(preclean_resume):
1478 + print "Resume point detected, skipping preclean operation..."
1479 + else:
1480 + try:
1481 + if os.path.exists(self.settings["controller_file"]):
1482 + cmd(self.settings["controller_file"]+\
1483 + " preclean","preclean script failed.",env=self.env)
1484 + touch(preclean_resume)
1485 +
1486 + except:
1487 + self.unbind()
1488 + raise CatalystError, "Build failed, could not execute preclean"
1489 +
1490 + def capture(self):
1491 + capture_resume = pjoin(self.settings["autoresume_path"], "capture")
1492 + if "autoresume" in self.settings["options"] \
1493 + and os.path.exists(capture_resume):
1494 + print "Resume point detected, skipping capture operation..."
1495 + else:
1496 + """ Capture target in a tarball """
1497 + mypath=self.settings["target_path"].split("/")
1498 + """ Remove filename from path """
1499 + mypath=string.join(mypath[:-1],"/")
1500 +
1501 + """ Now make sure path exists """
1502 + if not os.path.exists(mypath):
1503 + os.makedirs(mypath)
1504 +
1505 + print "Creating stage tarball..."
1506 +
1507 + cmd("tar -I lbzip2 -cpf "+self.settings["target_path"]+" -C "+\
1508 + self.settings["stage_path"]+" .",\
1509 + "Couldn't create stage tarball",env=self.env)
1510 +
1511 + self.gen_contents_file(self.settings["target_path"])
1512 + self.gen_digest_file(self.settings["target_path"])
1513 +
1514 + touch(capture_resume)
1515 +
1516 + def run_local(self):
1517 + run_local_resume = pjoin(self.settings["autoresume_path"], "run_local")
1518 + if "autoresume" in self.settings["options"] \
1519 + and os.path.exists(run_local_resume):
1520 + print "Resume point detected, skipping run_local operation..."
1521 + else:
1522 + try:
1523 + if os.path.exists(self.settings["controller_file"]):
1524 + cmd(self.settings["controller_file"]+" run",\
1525 + "run script failed.",env=self.env)
1526 + touch(run_local_resume)
1527 +
1528 + except CatalystError:
1529 + self.unbind()
1530 + raise CatalystError,"Stage build aborting due to error."
1531 +
1532 + def setup_environment(self):
1533 + """
1534 + Modify the current environment. This is an ugly hack that should be
1535 + fixed. We need this to use the os.system() call since we can't
1536 + specify our own environ
1537 + """
1538 + #print "setup_environment(); settings =", list(self.settings)
1539 + for x in list(self.settings):
1540 + #print "setup_environment(); processing:", x
1541 + if x == "options":
1542 + #self.env['clst_' + x] = ' '.join(self.settings[x])
1543 + for opt in self.settings[x]:
1544 + self.env['clst_' + opt.upper()] = "true"
1545 + continue
1546 + """ Sanitize var names by doing "s|/-.|_|g" """
1547 + varname="clst_"+string.replace(x,"/","_")
1548 + varname=string.replace(varname,"-","_")
1549 + varname=string.replace(varname,".","_")
1550 + if type(self.settings[x])==types.StringType:
1551 + """ Prefix to prevent namespace clashes """
1552 + #os.environ[varname]=self.settings[x]
1553 + self.env[varname]=self.settings[x]
1554 + elif type(self.settings[x])==types.ListType:
1555 + #os.environ[varname]=string.join(self.settings[x])
1556 + self.env[varname]=string.join(self.settings[x])
1557 + elif type(self.settings[x])==types.BooleanType:
1558 + if self.settings[x]:
1559 + self.env[varname]="true"
1560 + else:
1561 + self.env[varname]="false"
1562 + if "makeopts" in self.settings:
1563 + self.env["MAKEOPTS"]=self.settings["makeopts"]
1564 +
1565 + def run(self):
1566 + self.chroot_lock.write_lock()
1567 +
1568 + """ Kill any pids in the chroot "" """
1569 + self.kill_chroot_pids()
1570 +
1571 + """ Check for mounts right away and abort if we cannot unmount them """
1572 + self.mount_safety_check()
1573 +
1574 + if "clear-autoresume" in self.settings["options"]:
1575 + self.clear_autoresume()
1576 +
1577 + if "purgetmponly" in self.settings["options"]:
1578 + self.purge()
1579 + return
1580 +
1581 + if "PURGEONLY" in self.settings:
1582 + self.purge()
1583 + return
1584 +
1585 + if "purge" in self.settings["options"]:
1586 + self.purge()
1587 +
1588 + for x in self.settings["action_sequence"]:
1589 + print "--- Running action sequence: "+x
1590 + sys.stdout.flush()
1591 + try:
1592 + apply(getattr(self,x))
1593 + except:
1594 + self.mount_safety_check()
1595 + raise
1596 +
1597 + self.chroot_lock.unlock()
1598 +
1599 + def unmerge(self):
1600 + unmerge_resume = pjoin(self.settings["autoresume_path"], "unmerge")
1601 + if "autoresume" in self.settings["options"] \
1602 + and os.path.exists(unmerge_resume):
1603 + print "Resume point detected, skipping unmerge operation..."
1604 + else:
1605 + if self.settings["spec_prefix"]+"/unmerge" in self.settings:
1606 + if type(self.settings[self.settings["spec_prefix"]+\
1607 + "/unmerge"])==types.StringType:
1608 + self.settings[self.settings["spec_prefix"]+"/unmerge"]=\
1609 + [self.settings[self.settings["spec_prefix"]+"/unmerge"]]
1610 + myunmerge=\
1611 + self.settings[self.settings["spec_prefix"]+"/unmerge"][:]
1612 +
1613 + for x in range(0,len(myunmerge)):
1614 + """
1615 + Surround args with quotes for passing to bash, allows
1616 + things like "<" to remain intact
1617 + """
1618 + myunmerge[x]="'"+myunmerge[x]+"'"
1619 + myunmerge=string.join(myunmerge)
1620 +
1621 + """ Before cleaning, unmerge stuff """
1622 + try:
1623 + cmd(self.settings["controller_file"]+\
1624 + " unmerge "+ myunmerge,"Unmerge script failed.",\
1625 + env=self.env)
1626 + print "unmerge shell script"
1627 + except CatalystError:
1628 + self.unbind()
1629 + raise
1630 + touch(unmerge_resume)
1631 +
1632 + def target_setup(self):
1633 + target_setup_resume = pjoin(self.settings["autoresume_path"],
1634 + "target_setup")
1635 + if "autoresume" in self.settings["options"] \
1636 + and os.path.exists(target_setup_resume):
1637 + print "Resume point detected, skipping target_setup operation..."
1638 + else:
1639 + print "Setting up filesystems per filesystem type"
1640 + cmd(self.settings["controller_file"]+\
1641 + " target_image_setup "+ self.settings["target_path"],\
1642 + "target_image_setup script failed.",env=self.env)
1643 + touch(target_setup_resume)
1644 +
1645 + def setup_overlay(self):
1646 + setup_overlay_resume = pjoin(self.settings["autoresume_path"],
1647 + "setup_overlay")
1648 + if "autoresume" in self.settings["options"] \
1649 + and os.path.exists(setup_overlay_resume):
1650 + print "Resume point detected, skipping setup_overlay operation..."
1651 + else:
1652 + if self.settings["spec_prefix"]+"/overlay" in self.settings:
1653 + for x in self.settings[self.settings["spec_prefix"]+"/overlay"]:
1654 + if os.path.exists(x):
1655 + cmd("rsync -a "+x+"/ "+\
1656 + self.settings["target_path"],\
1657 + self.settings["spec_prefix"]+"overlay: "+x+\
1658 + " copy failed.",env=self.env)
1659 + touch(setup_overlay_resume)
1660 +
1661 + def create_iso(self):
1662 + create_iso_resume = pjoin(self.settings["autoresume_path"], "create_iso")
1663 + if "autoresume" in self.settings["options"] \
1664 + and os.path.exists(create_iso_resume):
1665 + print "Resume point detected, skipping create_iso operation..."
1666 + else:
1667 + """ Create the ISO """
1668 + if "iso" in self.settings:
1669 + cmd(self.settings["controller_file"]+" iso "+\
1670 + self.settings["iso"],"ISO creation script failed.",\
1671 + env=self.env)
1672 + self.gen_contents_file(self.settings["iso"])
1673 + self.gen_digest_file(self.settings["iso"])
1674 + touch(create_iso_resume)
1675 + else:
1676 + print "WARNING: livecd/iso was not defined."
1677 + print "An ISO Image will not be created."
1678 +
1679 + def build_packages(self):
1680 + build_packages_resume = pjoin(self.settings["autoresume_path"],
1681 + "build_packages")
1682 + if "autoresume" in self.settings["options"] \
1683 + and os.path.exists(build_packages_resume):
1684 + print "Resume point detected, skipping build_packages operation..."
1685 + else:
1686 + if self.settings["spec_prefix"]+"/packages" in self.settings:
1687 + if "autoresume" in self.settings["options"] \
1688 + and os.path.exists(self.settings["autoresume_path"]+\
1689 + "build_packages"):
1690 + print "Resume point detected, skipping build_packages operation..."
1691 + else:
1692 + mypack=\
1693 + list_bashify(self.settings[self.settings["spec_prefix"]\
1694 + +"/packages"])
1695 + try:
1696 + cmd(self.settings["controller_file"]+\
1697 + " build_packages "+mypack,\
1698 + "Error in attempt to build packages",env=self.env)
1699 + touch(build_packages_resume)
1700 + except CatalystError:
1701 + self.unbind()
1702 + raise CatalystError,self.settings["spec_prefix"]+\
1703 + "build aborting due to error."
1704 +
1705 + def build_kernel(self):
1706 + '''Build all configured kernels'''
1707 + build_kernel_resume = pjoin(self.settings["autoresume_path"],
1708 + "build_kernel")
1709 + if "autoresume" in self.settings["options"] \
1710 + and os.path.exists(build_kernel_resume):
1711 + print "Resume point detected, skipping build_kernel operation..."
1712 + else:
1713 + if "boot/kernel" in self.settings:
1714 + try:
1715 + mynames=self.settings["boot/kernel"]
1716 + if type(mynames)==types.StringType:
1717 + mynames=[mynames]
1718 + """
1719 + Execute the script that sets up the kernel build environment
1720 + """
1721 + cmd(self.settings["controller_file"]+\
1722 + " pre-kmerge ","Runscript pre-kmerge failed",\
1723 + env=self.env)
1724 + for kname in mynames:
1725 + self._build_kernel(kname=kname)
1726 + touch(build_kernel_resume)
1727 + except CatalystError:
1728 + self.unbind()
1729 + raise CatalystError,\
1730 + "build aborting due to kernel build error."
1731 +
1732 + def _build_kernel(self, kname):
1733 + "Build a single configured kernel by name"
1734 + kname_resume = pjoin(self.settings["autoresume_path"],
1735 + "build_kernel_" + kname)
1736 + if "autoresume" in self.settings["options"] \
1737 + and os.path.exists(kname_resume):
1738 + print "Resume point detected, skipping build_kernel for "+kname+" operation..."
1739 + return
1740 + self._copy_kernel_config(kname=kname)
1741 +
1742 + """
1743 + If we need to pass special options to the bootloader
1744 + for this kernel put them into the environment
1745 + """
1746 + if "boot/kernel/"+kname+"/kernelopts" in self.settings:
1747 + myopts=self.settings["boot/kernel/"+kname+\
1748 + "/kernelopts"]
1749 +
1750 + if type(myopts) != types.StringType:
1751 + myopts = string.join(myopts)
1752 + self.env[kname+"_kernelopts"]=myopts
1753 +
1754 + else:
1755 + self.env[kname+"_kernelopts"]=""
1756 +
1757 + if "boot/kernel/"+kname+"/extraversion" not in self.settings:
1758 + self.settings["boot/kernel/"+kname+\
1759 + "/extraversion"]=""
1760 +
1761 + self.env["clst_kextraversion"]=\
1762 + self.settings["boot/kernel/"+kname+\
1763 + "/extraversion"]
1764 +
1765 + self._copy_initramfs_overlay(kname=kname)
1766 +
1767 + """ Execute the script that builds the kernel """
1768 + cmd("/bin/bash "+self.settings["controller_file"]+\
1769 + " kernel "+kname,\
1770 + "Runscript kernel build failed",env=self.env)
1771 +
1772 + if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings:
1773 + if os.path.exists(self.settings["chroot_path"]+\
1774 + "/tmp/initramfs_overlay/"):
1775 + print "Cleaning up temporary overlay dir"
1776 + cmd("rm -R "+self.settings["chroot_path"]+\
1777 + "/tmp/initramfs_overlay/",env=self.env)
1778 +
1779 + touch(kname_resume)
1780 +
1781 + """
1782 + Execute the script that cleans up the kernel build
1783 + environment
1784 + """
1785 + cmd("/bin/bash "+self.settings["controller_file"]+\
1786 + " post-kmerge ",
1787 + "Runscript post-kmerge failed",env=self.env)
1788 +
1789 + def _copy_kernel_config(self, kname):
1790 + if "boot/kernel/"+kname+"/config" in self.settings:
1791 + if not os.path.exists(self.settings["boot/kernel/"+kname+"/config"]):
1792 + self.unbind()
1793 + raise CatalystError,\
1794 + "Can't find kernel config: "+\
1795 + self.settings["boot/kernel/"+kname+\
1796 + "/config"]
1797 +
1798 + try:
1799 + cmd("cp "+self.settings["boot/kernel/"+kname+\
1800 + "/config"]+" "+\
1801 + self.settings["chroot_path"]+"/var/tmp/"+\
1802 + kname+".config",\
1803 + "Couldn't copy kernel config: "+\
1804 + self.settings["boot/kernel/"+kname+\
1805 + "/config"],env=self.env)
1806 +
1807 + except CatalystError:
1808 + self.unbind()
1809 +
1810 + def _copy_initramfs_overlay(self, kname):
1811 + if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings:
1812 + if os.path.exists(self.settings["boot/kernel/"+\
1813 + kname+"/initramfs_overlay"]):
1814 + print "Copying initramfs_overlay dir "+\
1815 + self.settings["boot/kernel/"+kname+\
1816 + "/initramfs_overlay"]
1817 +
1818 + cmd("mkdir -p "+\
1819 + self.settings["chroot_path"]+\
1820 + "/tmp/initramfs_overlay/"+\
1821 + self.settings["boot/kernel/"+kname+\
1822 + "/initramfs_overlay"],env=self.env)
1823 +
1824 + cmd("cp -R "+self.settings["boot/kernel/"+\
1825 + kname+"/initramfs_overlay"]+"/* "+\
1826 + self.settings["chroot_path"]+\
1827 + "/tmp/initramfs_overlay/"+\
1828 + self.settings["boot/kernel/"+kname+\
1829 + "/initramfs_overlay"],env=self.env)
1830 +
1831 + def bootloader(self):
1832 + bootloader_resume = pjoin(self.settings["autoresume_path"], "bootloader")
1833 + if "autoresume" in self.settings["options"] \
1834 + and os.path.exists(bootloader_resume):
1835 + print "Resume point detected, skipping bootloader operation..."
1836 + else:
1837 + try:
1838 + cmd(self.settings["controller_file"]+\
1839 + " bootloader " + self.settings["target_path"],\
1840 + "Bootloader script failed.",env=self.env)
1841 + touch(bootloader_resume)
1842 + except CatalystError:
1843 + self.unbind()
1844 + raise CatalystError,"Script aborting due to error."
1845 +
1846 + def livecd_update(self):
1847 + livecd_update_resume = pjoin(self.settings["autoresume_path"],
1848 + "livecd_update")
1849 + if "autoresume" in self.settings["options"] \
1850 + and os.path.exists(livecd_update_resume):
1851 + print "Resume point detected, skipping build_packages operation..."
1852 + else:
1853 + try:
1854 + cmd(self.settings["controller_file"]+\
1855 + " livecd-update","livecd-update failed.",env=self.env)
1856 + touch(livecd_update_resume)
1857 +
1858 + except CatalystError:
1859 + self.unbind()
1860 + raise CatalystError,"build aborting due to livecd_update error."
1861 +
1862 +# vim: ts=4 sw=4 sta et sts=4 ai
1863 diff --git a/catalyst/base/targetbase.py b/catalyst/base/targetbase.py
1864 new file mode 100644
1865 index 0000000..e0c03df
1866 --- /dev/null
1867 +++ b/catalyst/base/targetbase.py
1868 @@ -0,0 +1,15 @@
1869 +import os
1870 +
1871 +from catalyst.support import *
1872 +
1873 +class TargetBase(object):
1874 + """
1875 + The toplevel class for all targets. This is about as generic as we get.
1876 + """
1877 + def __init__(self, myspec, addlargs):
1878 + addl_arg_parse(myspec,addlargs,self.required_values,self.valid_values)
1879 + self.settings=myspec
1880 + self.env = {
1881 + 'PATH': '/bin:/sbin:/usr/bin:/usr/sbin',
1882 + 'TERM': os.getenv('TERM', 'dumb'),
1883 + }
1884 diff --git a/catalyst/targets/clearbase.py b/catalyst/targets/clearbase.py
1885 deleted file mode 100644
1886 index 8519acc..0000000
1887 --- a/catalyst/targets/clearbase.py
1888 +++ /dev/null
1889 @@ -1,115 +0,0 @@
1890 -
1891 -import os
1892 -import shutil
1893 -from stat import ST_UID, ST_GID, ST_MODE
1894 -
1895 -
1896 -from catalyst.support import cmd, countdown
1897 -
1898 -
1899 -class ClearBase(object):
1900 - """
1901 - This class does all of clearing after task completion
1902 - """
1903 - def __init__(self, myspec):
1904 - self.settings = myspec
1905 -
1906 -
1907 -
1908 - def clear_autoresume(self):
1909 - """ Clean resume points since they are no longer needed """
1910 - if "autoresume" in self.settings["options"]:
1911 - print "Removing AutoResume Points: ..."
1912 - myemp=self.settings["autoresume_path"]
1913 - if os.path.isdir(myemp):
1914 - if "autoresume" in self.settings["options"]:
1915 - print "Emptying directory",myemp
1916 - """
1917 - stat the dir, delete the dir, recreate the dir and set
1918 - the proper perms and ownership
1919 - """
1920 - mystat=os.stat(myemp)
1921 - if os.uname()[0] == "FreeBSD":
1922 - cmd("chflags -R noschg "+myemp,\
1923 - "Could not remove immutable flag for file "\
1924 - +myemp)
1925 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env-self.env)
1926 - shutil.rmtree(myemp)
1927 - os.makedirs(myemp,0755)
1928 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
1929 - os.chmod(myemp,mystat[ST_MODE])
1930 -
1931 -
1932 - def clear_chroot(self):
1933 - myemp=self.settings["chroot_path"]
1934 - if os.path.isdir(myemp):
1935 - print "Emptying directory",myemp
1936 - """
1937 - stat the dir, delete the dir, recreate the dir and set
1938 - the proper perms and ownership
1939 - """
1940 - mystat=os.stat(myemp)
1941 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
1942 - """ There's no easy way to change flags recursively in python """
1943 - if os.uname()[0] == "FreeBSD":
1944 - os.system("chflags -R noschg "+myemp)
1945 - shutil.rmtree(myemp)
1946 - os.makedirs(myemp,0755)
1947 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
1948 - os.chmod(myemp,mystat[ST_MODE])
1949 -
1950 -
1951 - def clear_packages(self):
1952 - if "pkgcache" in self.settings["options"]:
1953 - print "purging the pkgcache ..."
1954 -
1955 - myemp=self.settings["pkgcache_path"]
1956 - if os.path.isdir(myemp):
1957 - print "Emptying directory",myemp
1958 - """
1959 - stat the dir, delete the dir, recreate the dir and set
1960 - the proper perms and ownership
1961 - """
1962 - mystat=os.stat(myemp)
1963 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
1964 - shutil.rmtree(myemp)
1965 - os.makedirs(myemp,0755)
1966 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
1967 - os.chmod(myemp,mystat[ST_MODE])
1968 -
1969 -
1970 - def clear_kerncache(self):
1971 - if "kerncache" in self.settings["options"]:
1972 - print "purging the kerncache ..."
1973 -
1974 - myemp=self.settings["kerncache_path"]
1975 - if os.path.isdir(myemp):
1976 - print "Emptying directory",myemp
1977 - """
1978 - stat the dir, delete the dir, recreate the dir and set
1979 - the proper perms and ownership
1980 - """
1981 - mystat=os.stat(myemp)
1982 - #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
1983 - shutil.rmtree(myemp)
1984 - os.makedirs(myemp,0755)
1985 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
1986 - os.chmod(myemp,mystat[ST_MODE])
1987 -
1988 -
1989 - def purge(self):
1990 - countdown(10,"Purging Caches ...")
1991 - if any(k in self.settings["options"] for k in ("purge","purgeonly","purgetmponly")):
1992 - print "clearing autoresume ..."
1993 - self.clear_autoresume()
1994 -
1995 - print "clearing chroot ..."
1996 - self.clear_chroot()
1997 -
1998 - if "PURGETMPONLY" not in self.settings:
1999 - print "clearing package cache ..."
2000 - self.clear_packages()
2001 -
2002 - print "clearing kerncache ..."
2003 - self.clear_kerncache()
2004 -
2005 diff --git a/catalyst/targets/embedded_target.py b/catalyst/targets/embedded_target.py
2006 index 7cee7a6..528d545 100644
2007 --- a/catalyst/targets/embedded_target.py
2008 +++ b/catalyst/targets/embedded_target.py
2009 @@ -10,12 +10,12 @@ ROOT=/tmp/submerge emerge --something foo bar .
2010 """
2011 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
2012
2013 -import os,string,imp,types,shutil
2014 -from catalyst.support import *
2015 -from generic_stage_target import *
2016 -from stat import *
2017
2018 -class embedded_target(generic_stage_target):
2019 +from catalyst.support import normpath
2020 +
2021 +from catalyst.base.stagebase import StageBase
2022 +
2023 +class embedded_target(StageBase):
2024 """
2025 Builder class for embedded target
2026 """
2027 @@ -27,7 +27,7 @@ class embedded_target(generic_stage_target):
2028 if "embedded/fs-type" in addlargs:
2029 self.valid_values.append("embedded/fs-ops")
2030
2031 - generic_stage_target.__init__(self,spec,addlargs)
2032 + StageBase.__init__(self,spec,addlargs)
2033 self.set_build_kernel_vars(addlargs)
2034
2035 def set_action_sequence(self):
2036 diff --git a/catalyst/targets/genbase.py b/catalyst/targets/genbase.py
2037 deleted file mode 100644
2038 index e818781..0000000
2039 --- a/catalyst/targets/genbase.py
2040 +++ /dev/null
2041 @@ -1,58 +0,0 @@
2042 -
2043 -
2044 -import os
2045 -
2046 -
2047 -class GenBase(object):
2048 - """
2049 - This class does generation of the contents and digests files.
2050 - """
2051 - def __init__(self,myspec):
2052 - self.settings = myspec
2053 -
2054 -
2055 - def gen_contents_file(self,file):
2056 - if os.path.exists(file+".CONTENTS"):
2057 - os.remove(file+".CONTENTS")
2058 - if "contents" in self.settings:
2059 - contents_map = self.settings["contents_map"]
2060 - if os.path.exists(file):
2061 - myf=open(file+".CONTENTS","w")
2062 - keys={}
2063 - for i in self.settings["contents"].split():
2064 - keys[i]=1
2065 - array=keys.keys()
2066 - array.sort()
2067 - for j in array:
2068 - contents = contents_map.generate_contents(file, j,
2069 - verbose="VERBOSE" in self.settings)
2070 - if contents:
2071 - myf.write(contents)
2072 - myf.close()
2073 -
2074 - def gen_digest_file(self,file):
2075 - if os.path.exists(file+".DIGESTS"):
2076 - os.remove(file+".DIGESTS")
2077 - if "digests" in self.settings:
2078 - hash_map = self.settings["hash_map"]
2079 - if os.path.exists(file):
2080 - myf=open(file+".DIGESTS","w")
2081 - keys={}
2082 - for i in self.settings["digests"].split():
2083 - keys[i]=1
2084 - array=keys.keys()
2085 - array.sort()
2086 - for f in [file, file+'.CONTENTS']:
2087 - if os.path.exists(f):
2088 - if "all" in array:
2089 - for k in list(hash_map.hash_map):
2090 - hash = hash_map.generate_hash(f,hash_=k,
2091 - verbose = "VERBOSE" in self.settings)
2092 - myf.write(hash)
2093 - else:
2094 - for j in array:
2095 - hash = hash_map.generate_hash(f,hash_=j,
2096 - verbose = "VERBOSE" in self.settings)
2097 - myf.write(hash)
2098 - myf.close()
2099 -
2100 diff --git a/catalyst/targets/generic_stage_target.py b/catalyst/targets/generic_stage_target.py
2101 deleted file mode 100644
2102 index 296eee3..0000000
2103 --- a/catalyst/targets/generic_stage_target.py
2104 +++ /dev/null
2105 @@ -1,1630 +0,0 @@
2106 -
2107 -import os
2108 -import string
2109 -import imp
2110 -import types
2111 -import shutil
2112 -import sys
2113 -from stat import ST_UID, ST_GID, ST_MODE
2114 -
2115 -# for convienience
2116 -pjoin = os.path.join
2117 -
2118 -from catalyst.defaults import (SOURCE_MOUNT_DEFAULTS, TARGET_MOUNT_DEFAULTS,
2119 - PORT_LOGDIR_CLEAN)
2120 -from catalyst.support import (CatalystError, msg, file_locate, normpath,
2121 - touch, cmd, warn, list_bashify, read_makeconf, read_from_clst, ismount)
2122 -from catalyst.targets.targetbase import TargetBase
2123 -from catalyst.targets.clearbase import ClearBase
2124 -from catalyst.targets.genbase import GenBase
2125 -from catalyst.lock import LockDir
2126 -
2127 -
2128 -class generic_stage_target(TargetBase, ClearBase, GenBase):
2129 - """
2130 - This class does all of the chroot setup, copying of files, etc. It is
2131 - the driver class for pretty much everything that Catalyst does.
2132 - """
2133 - def __init__(self,myspec,addlargs):
2134 - self.required_values.extend(["version_stamp","target","subarch",\
2135 - "rel_type","profile","snapshot","source_subpath"])
2136 -
2137 - self.valid_values.extend(["version_stamp","target","subarch",\
2138 - "rel_type","profile","snapshot","source_subpath","portage_confdir",\
2139 - "cflags","cxxflags","ldflags","cbuild","hostuse","portage_overlay",\
2140 - "distcc_hosts","makeopts","pkgcache_path","kerncache_path"])
2141 -
2142 - self.set_valid_build_kernel_vars(addlargs)
2143 - TargetBase.__init__(self, myspec, addlargs)
2144 - GenBase.__init__(self, myspec)
2145 - ClearBase.__init__(self, myspec)
2146 -
2147 - """
2148 - The semantics of subarchmap and machinemap changed a bit in 2.0.3 to
2149 - work better with vapier's CBUILD stuff. I've removed the "monolithic"
2150 - machinemap from this file and split up its contents amongst the
2151 - various arch/foo.py files.
2152 -
2153 - When register() is called on each module in the arch/ dir, it now
2154 - returns a tuple instead of acting on the subarchmap dict that is
2155 - passed to it. The tuple contains the values that were previously
2156 - added to subarchmap as well as a new list of CHOSTs that go along
2157 - with that arch. This allows us to build machinemap on the fly based
2158 - on the keys in subarchmap and the values of the 2nd list returned
2159 - (tmpmachinemap).
2160 -
2161 - Also, after talking with vapier. I have a slightly better idea of what
2162 - certain variables are used for and what they should be set to. Neither
2163 - 'buildarch' or 'hostarch' are used directly, so their value doesn't
2164 - really matter. They are just compared to determine if we are
2165 - cross-compiling. Because of this, they are just set to the name of the
2166 - module in arch/ that the subarch is part of to make things simpler.
2167 - The entire build process is still based off of 'subarch' like it was
2168 - previously. -agaffney
2169 - """
2170 -
2171 - self.archmap = {}
2172 - self.subarchmap = {}
2173 - machinemap = {}
2174 - arch_dir = self.settings["PythonDir"] + "/arch/"
2175 - for x in [x[:-3] for x in os.listdir(arch_dir) if x.endswith(".py")]:
2176 - if x == "__init__":
2177 - continue
2178 - try:
2179 - fh=open(arch_dir + x + ".py")
2180 - """
2181 - This next line loads the plugin as a module and assigns it to
2182 - archmap[x]
2183 - """
2184 - self.archmap[x]=imp.load_module(x,fh,"../arch/" + x + ".py",
2185 - (".py", "r", imp.PY_SOURCE))
2186 - """
2187 - This next line registers all the subarches supported in the
2188 - plugin
2189 - """
2190 - tmpsubarchmap, tmpmachinemap = self.archmap[x].register()
2191 - self.subarchmap.update(tmpsubarchmap)
2192 - for machine in tmpmachinemap:
2193 - machinemap[machine] = x
2194 - for subarch in tmpsubarchmap:
2195 - machinemap[subarch] = x
2196 - fh.close()
2197 - except IOError:
2198 - """
2199 - This message should probably change a bit, since everything in
2200 - the dir should load just fine. If it doesn't, it's probably a
2201 - syntax error in the module
2202 - """
2203 - msg("Can't find/load " + x + ".py plugin in " + arch_dir)
2204 -
2205 - if "chost" in self.settings:
2206 - hostmachine = self.settings["chost"].split("-")[0]
2207 - if hostmachine not in machinemap:
2208 - raise CatalystError, "Unknown host machine type "+hostmachine
2209 - self.settings["hostarch"]=machinemap[hostmachine]
2210 - else:
2211 - hostmachine = self.settings["subarch"]
2212 - if hostmachine in machinemap:
2213 - hostmachine = machinemap[hostmachine]
2214 - self.settings["hostarch"]=hostmachine
2215 - if "cbuild" in self.settings:
2216 - buildmachine = self.settings["cbuild"].split("-")[0]
2217 - else:
2218 - buildmachine = os.uname()[4]
2219 - if buildmachine not in machinemap:
2220 - raise CatalystError, "Unknown build machine type "+buildmachine
2221 - self.settings["buildarch"]=machinemap[buildmachine]
2222 - self.settings["crosscompile"]=(self.settings["hostarch"]!=\
2223 - self.settings["buildarch"])
2224 -
2225 - """ Call arch constructor, pass our settings """
2226 - try:
2227 - self.arch=self.subarchmap[self.settings["subarch"]](self.settings)
2228 - except KeyError:
2229 - print "Invalid subarch: "+self.settings["subarch"]
2230 - print "Choose one of the following:",
2231 - for x in self.subarchmap:
2232 - print x,
2233 - print
2234 - sys.exit(2)
2235 -
2236 - print "Using target:",self.settings["target"]
2237 - """ Print a nice informational message """
2238 - if self.settings["buildarch"]==self.settings["hostarch"]:
2239 - print "Building natively for",self.settings["hostarch"]
2240 - elif self.settings["crosscompile"]:
2241 - print "Cross-compiling on",self.settings["buildarch"],\
2242 - "for different machine type",self.settings["hostarch"]
2243 - else:
2244 - print "Building on",self.settings["buildarch"],\
2245 - "for alternate personality type",self.settings["hostarch"]
2246 -
2247 - """ This must be set first as other set_ options depend on this """
2248 - self.set_spec_prefix()
2249 -
2250 - """ Define all of our core variables """
2251 - self.set_target_profile()
2252 - self.set_target_subpath()
2253 - self.set_source_subpath()
2254 -
2255 - """ Set paths """
2256 - self.set_snapshot_path()
2257 - self.set_root_path()
2258 - self.set_source_path()
2259 - self.set_snapcache_path()
2260 - self.set_chroot_path()
2261 - self.set_autoresume_path()
2262 - self.set_dest_path()
2263 - self.set_stage_path()
2264 - self.set_target_path()
2265 -
2266 - self.set_controller_file()
2267 - self.set_action_sequence()
2268 - self.set_use()
2269 - self.set_cleanables()
2270 - self.set_iso_volume_id()
2271 - self.set_build_kernel_vars()
2272 - self.set_fsscript()
2273 - self.set_install_mask()
2274 - self.set_rcadd()
2275 - self.set_rcdel()
2276 - self.set_cdtar()
2277 - self.set_fstype()
2278 - self.set_fsops()
2279 - self.set_iso()
2280 - self.set_packages()
2281 - self.set_rm()
2282 - self.set_linuxrc()
2283 - self.set_busybox_config()
2284 - self.set_overlay()
2285 - self.set_portage_overlay()
2286 - self.set_root_overlay()
2287 -
2288 - """
2289 - This next line checks to make sure that the specified variables exist
2290 - on disk.
2291 - """
2292 - #pdb.set_trace()
2293 - file_locate(self.settings,["source_path","snapshot_path","distdir"],\
2294 - expand=0)
2295 - """ If we are using portage_confdir, check that as well. """
2296 - if "portage_confdir" in self.settings:
2297 - file_locate(self.settings,["portage_confdir"],expand=0)
2298 -
2299 - """ Setup our mount points """
2300 - # initialize our target mounts.
2301 - self.target_mounts = TARGET_MOUNT_DEFAULTS.copy()
2302 -
2303 - self.mounts = ["proc", "dev", "portdir", "distdir", "port_tmpdir"]
2304 - # initialize our source mounts
2305 - self.mountmap = SOURCE_MOUNT_DEFAULTS.copy()
2306 - # update them from settings
2307 - self.mountmap["distdir"] = self.settings["distdir"]
2308 - if "snapcache" not in self.settings["options"]:
2309 - self.mounts.remove("portdir")
2310 - self.mountmap["portdir"] = None
2311 - else:
2312 - self.mountmap["portdir"] = normpath("/".join([
2313 - self.settings["snapshot_cache_path"],
2314 - self.settings["repo_name"],
2315 - ]))
2316 - if os.uname()[0] == "Linux":
2317 - self.mounts.append("devpts")
2318 - self.mounts.append("shm")
2319 -
2320 - self.set_mounts()
2321 -
2322 - """
2323 - Configure any user specified options (either in catalyst.conf or on
2324 - the command line).
2325 - """
2326 - if "pkgcache" in self.settings["options"]:
2327 - self.set_pkgcache_path()
2328 - print "Location of the package cache is "+\
2329 - self.settings["pkgcache_path"]
2330 - self.mounts.append("packagedir")
2331 - self.mountmap["packagedir"] = self.settings["pkgcache_path"]
2332 -
2333 - if "kerncache" in self.settings["options"]:
2334 - self.set_kerncache_path()
2335 - print "Location of the kerncache is "+\
2336 - self.settings["kerncache_path"]
2337 - self.mounts.append("kerncache")
2338 - self.mountmap["kerncache"] = self.settings["kerncache_path"]
2339 -
2340 - if "ccache" in self.settings["options"]:
2341 - if "CCACHE_DIR" in os.environ:
2342 - ccdir=os.environ["CCACHE_DIR"]
2343 - del os.environ["CCACHE_DIR"]
2344 - else:
2345 - ccdir="/root/.ccache"
2346 - if not os.path.isdir(ccdir):
2347 - raise CatalystError,\
2348 - "Compiler cache support can't be enabled (can't find "+\
2349 - ccdir+")"
2350 - self.mounts.append("ccache")
2351 - self.mountmap["ccache"] = ccdir
2352 - """ for the chroot: """
2353 - self.env["CCACHE_DIR"] = self.target_mounts["ccache"]
2354 -
2355 - if "icecream" in self.settings["options"]:
2356 - self.mounts.append("icecream")
2357 - self.mountmap["icecream"] = self.settings["icecream"]
2358 - self.env["PATH"] = self.target_mounts["icecream"] + ":" + \
2359 - self.env["PATH"]
2360 -
2361 - if "port_logdir" in self.settings:
2362 - self.mounts.append("port_logdir")
2363 - self.mountmap["port_logdir"] = self.settings["port_logdir"]
2364 - self.env["PORT_LOGDIR"] = self.settings["port_logdir"]
2365 - self.env["PORT_LOGDIR_CLEAN"] = PORT_LOGDIR_CLEAN
2366 -
2367 - def override_cbuild(self):
2368 - if "CBUILD" in self.makeconf:
2369 - self.settings["CBUILD"]=self.makeconf["CBUILD"]
2370 -
2371 - def override_chost(self):
2372 - if "CHOST" in self.makeconf:
2373 - self.settings["CHOST"]=self.makeconf["CHOST"]
2374 -
2375 - def override_cflags(self):
2376 - if "CFLAGS" in self.makeconf:
2377 - self.settings["CFLAGS"]=self.makeconf["CFLAGS"]
2378 -
2379 - def override_cxxflags(self):
2380 - if "CXXFLAGS" in self.makeconf:
2381 - self.settings["CXXFLAGS"]=self.makeconf["CXXFLAGS"]
2382 -
2383 - def override_ldflags(self):
2384 - if "LDFLAGS" in self.makeconf:
2385 - self.settings["LDFLAGS"]=self.makeconf["LDFLAGS"]
2386 -
2387 - def set_install_mask(self):
2388 - if "install_mask" in self.settings:
2389 - if type(self.settings["install_mask"])!=types.StringType:
2390 - self.settings["install_mask"]=\
2391 - string.join(self.settings["install_mask"])
2392 -
2393 - def set_spec_prefix(self):
2394 - self.settings["spec_prefix"]=self.settings["target"]
2395 -
2396 - def set_target_profile(self):
2397 - self.settings["target_profile"]=self.settings["profile"]
2398 -
2399 - def set_target_subpath(self):
2400 - self.settings["target_subpath"]=self.settings["rel_type"]+"/"+\
2401 - self.settings["target"]+"-"+self.settings["subarch"]+"-"+\
2402 - self.settings["version_stamp"]
2403 -
2404 - def set_source_subpath(self):
2405 - if type(self.settings["source_subpath"])!=types.StringType:
2406 - raise CatalystError,\
2407 - "source_subpath should have been a string. Perhaps you have something wrong in your spec file?"
2408 -
2409 - def set_pkgcache_path(self):
2410 - if "pkgcache_path" in self.settings:
2411 - if type(self.settings["pkgcache_path"])!=types.StringType:
2412 - self.settings["pkgcache_path"]=\
2413 - normpath(string.join(self.settings["pkgcache_path"]))
2414 - else:
2415 - self.settings["pkgcache_path"]=\
2416 - normpath(self.settings["storedir"]+"/packages/"+\
2417 - self.settings["target_subpath"]+"/")
2418 -
2419 - def set_kerncache_path(self):
2420 - if "kerncache_path" in self.settings:
2421 - if type(self.settings["kerncache_path"])!=types.StringType:
2422 - self.settings["kerncache_path"]=\
2423 - normpath(string.join(self.settings["kerncache_path"]))
2424 - else:
2425 - self.settings["kerncache_path"]=normpath(self.settings["storedir"]+\
2426 - "/kerncache/"+self.settings["target_subpath"]+"/")
2427 -
2428 - def set_target_path(self):
2429 - self.settings["target_path"]=normpath(self.settings["storedir"]+\
2430 - "/builds/"+self.settings["target_subpath"]+".tar.bz2")
2431 - setup_target_path_resume = pjoin(self.settings["autoresume_path"],
2432 - "setup_target_path")
2433 - if "autoresume" in self.settings["options"] and \
2434 - os.path.exists(setup_target_path_resume):
2435 - print \
2436 - "Resume point detected, skipping target path setup operation..."
2437 - else:
2438 - """ First clean up any existing target stuff """
2439 - # XXX WTF are we removing the old tarball before we start building the
2440 - # XXX new one? If the build fails, you don't want to be left with
2441 - # XXX nothing at all
2442 -# if os.path.isfile(self.settings["target_path"]):
2443 -# cmd("rm -f "+self.settings["target_path"],\
2444 -# "Could not remove existing file: "\
2445 -# +self.settings["target_path"],env=self.env)
2446 - touch(setup_target_path_resume)
2447 -
2448 - if not os.path.exists(self.settings["storedir"]+"/builds/"):
2449 - os.makedirs(self.settings["storedir"]+"/builds/")
2450 -
2451 - def set_fsscript(self):
2452 - if self.settings["spec_prefix"]+"/fsscript" in self.settings:
2453 - self.settings["fsscript"]=\
2454 - self.settings[self.settings["spec_prefix"]+"/fsscript"]
2455 - del self.settings[self.settings["spec_prefix"]+"/fsscript"]
2456 -
2457 - def set_rcadd(self):
2458 - if self.settings["spec_prefix"]+"/rcadd" in self.settings:
2459 - self.settings["rcadd"]=\
2460 - self.settings[self.settings["spec_prefix"]+"/rcadd"]
2461 - del self.settings[self.settings["spec_prefix"]+"/rcadd"]
2462 -
2463 - def set_rcdel(self):
2464 - if self.settings["spec_prefix"]+"/rcdel" in self.settings:
2465 - self.settings["rcdel"]=\
2466 - self.settings[self.settings["spec_prefix"]+"/rcdel"]
2467 - del self.settings[self.settings["spec_prefix"]+"/rcdel"]
2468 -
2469 - def set_cdtar(self):
2470 - if self.settings["spec_prefix"]+"/cdtar" in self.settings:
2471 - self.settings["cdtar"]=\
2472 - normpath(self.settings[self.settings["spec_prefix"]+"/cdtar"])
2473 - del self.settings[self.settings["spec_prefix"]+"/cdtar"]
2474 -
2475 - def set_iso(self):
2476 - if self.settings["spec_prefix"]+"/iso" in self.settings:
2477 - if self.settings[self.settings["spec_prefix"]+"/iso"].startswith('/'):
2478 - self.settings["iso"]=\
2479 - normpath(self.settings[self.settings["spec_prefix"]+"/iso"])
2480 - else:
2481 - # This automatically prepends the build dir to the ISO output path
2482 - # if it doesn't start with a /
2483 - self.settings["iso"] = normpath(self.settings["storedir"] + \
2484 - "/builds/" + self.settings["rel_type"] + "/" + \
2485 - self.settings[self.settings["spec_prefix"]+"/iso"])
2486 - del self.settings[self.settings["spec_prefix"]+"/iso"]
2487 -
2488 - def set_fstype(self):
2489 - if self.settings["spec_prefix"]+"/fstype" in self.settings:
2490 - self.settings["fstype"]=\
2491 - self.settings[self.settings["spec_prefix"]+"/fstype"]
2492 - del self.settings[self.settings["spec_prefix"]+"/fstype"]
2493 -
2494 - if "fstype" not in self.settings:
2495 - self.settings["fstype"]="normal"
2496 - for x in self.valid_values:
2497 - if x == self.settings["spec_prefix"]+"/fstype":
2498 - print "\n"+self.settings["spec_prefix"]+\
2499 - "/fstype is being set to the default of \"normal\"\n"
2500 -
2501 - def set_fsops(self):
2502 - if "fstype" in self.settings:
2503 - self.valid_values.append("fsops")
2504 - if self.settings["spec_prefix"]+"/fsops" in self.settings:
2505 - self.settings["fsops"]=\
2506 - self.settings[self.settings["spec_prefix"]+"/fsops"]
2507 - del self.settings[self.settings["spec_prefix"]+"/fsops"]
2508 -
2509 - def set_source_path(self):
2510 - if "seedcache" in self.settings["options"]\
2511 - and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+\
2512 - self.settings["source_subpath"]+"/")):
2513 - self.settings["source_path"]=normpath(self.settings["storedir"]+\
2514 - "/tmp/"+self.settings["source_subpath"]+"/")
2515 - else:
2516 - self.settings["source_path"]=normpath(self.settings["storedir"]+\
2517 - "/builds/"+self.settings["source_subpath"]+".tar.bz2")
2518 - if os.path.isfile(self.settings["source_path"]):
2519 - # XXX: Is this even necessary if the previous check passes?
2520 - if os.path.exists(self.settings["source_path"]):
2521 - self.settings["source_path_hash"] = \
2522 - self.settings["hash_map"].generate_hash(
2523 - self.settings["source_path"],
2524 - hash_ = self.settings["hash_function"],
2525 - verbose = False)
2526 - print "Source path set to "+self.settings["source_path"]
2527 - if os.path.isdir(self.settings["source_path"]):
2528 - print "\tIf this is not desired, remove this directory or turn off"
2529 - print "\tseedcache in the options of catalyst.conf the source path"
2530 - print "\twill then be "+\
2531 - normpath(self.settings["storedir"]+"/builds/"+\
2532 - self.settings["source_subpath"]+".tar.bz2\n")
2533 -
2534 - def set_dest_path(self):
2535 - if "root_path" in self.settings:
2536 - self.settings["destpath"]=normpath(self.settings["chroot_path"]+\
2537 - self.settings["root_path"])
2538 - else:
2539 - self.settings["destpath"]=normpath(self.settings["chroot_path"])
2540 -
2541 - def set_cleanables(self):
2542 - self.settings["cleanables"]=["/etc/resolv.conf","/var/tmp/*","/tmp/*",\
2543 - "/root/*", self.settings["portdir"]]
2544 -
2545 - def set_snapshot_path(self):
2546 - self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
2547 - "/snapshots/" + self.settings["snapshot_name"] +
2548 - self.settings["snapshot"] + ".tar.xz")
2549 -
2550 - if os.path.exists(self.settings["snapshot_path"]):
2551 - self.settings["snapshot_path_hash"] = \
2552 - self.settings["hash_map"].generate_hash(
2553 - self.settings["snapshot_path"],
2554 - hash_ = self.settings["hash_function"],
2555 - verbose = False)
2556 - else:
2557 - self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
2558 - "/snapshots/" + self.settings["snapshot_name"] +
2559 - self.settings["snapshot"] + ".tar.bz2")
2560 -
2561 - if os.path.exists(self.settings["snapshot_path"]):
2562 - self.settings["snapshot_path_hash"] = \
2563 - self.settings["hash_map"].generate_hash(
2564 - self.settings["snapshot_path"],
2565 - hash_ = self.settings["hash_function"],
2566 - verbose = False)
2567 -
2568 - def set_snapcache_path(self):
2569 - if "snapcache" in self.settings["options"]:
2570 - self.settings["snapshot_cache_path"] = \
2571 - normpath(self.settings["snapshot_cache"] + "/" +
2572 - self.settings["snapshot"])
2573 - self.snapcache_lock=\
2574 - LockDir(self.settings["snapshot_cache_path"])
2575 - print "Caching snapshot to "+self.settings["snapshot_cache_path"]
2576 -
2577 - def set_chroot_path(self):
2578 - """
2579 - NOTE: the trailing slash has been removed
2580 - Things *could* break if you don't use a proper join()
2581 - """
2582 - self.settings["chroot_path"]=normpath(self.settings["storedir"]+\
2583 - "/tmp/"+self.settings["target_subpath"])
2584 - self.chroot_lock=LockDir(self.settings["chroot_path"])
2585 -
2586 - def set_autoresume_path(self):
2587 - self.settings["autoresume_path"] = normpath(pjoin(
2588 - self.settings["storedir"], "tmp", self.settings["rel_type"],
2589 - ".autoresume-%s-%s-%s"
2590 - %(self.settings["target"], self.settings["subarch"],
2591 - self.settings["version_stamp"])
2592 - ))
2593 - if "autoresume" in self.settings["options"]:
2594 - print "The autoresume path is " + self.settings["autoresume_path"]
2595 - if not os.path.exists(self.settings["autoresume_path"]):
2596 - os.makedirs(self.settings["autoresume_path"],0755)
2597 -
2598 - def set_controller_file(self):
2599 - self.settings["controller_file"]=normpath(self.settings["sharedir"]+\
2600 - "/targets/"+self.settings["target"]+"/"+self.settings["target"]+\
2601 - "-controller.sh")
2602 -
2603 - def set_iso_volume_id(self):
2604 - if self.settings["spec_prefix"]+"/volid" in self.settings:
2605 - self.settings["iso_volume_id"]=\
2606 - self.settings[self.settings["spec_prefix"]+"/volid"]
2607 - if len(self.settings["iso_volume_id"])>32:
2608 - raise CatalystError,\
2609 - "ISO volume ID must not exceed 32 characters."
2610 - else:
2611 - self.settings["iso_volume_id"]="catalyst "+self.settings["snapshot"]
2612 -
2613 - def set_action_sequence(self):
2614 - """ Default action sequence for run method """
2615 - self.settings["action_sequence"]=["unpack","unpack_snapshot",\
2616 - "setup_confdir","portage_overlay",\
2617 - "base_dirs","bind","chroot_setup","setup_environment",\
2618 - "run_local","preclean","unbind","clean"]
2619 -# if "TARBALL" in self.settings or \
2620 -# "fetch" not in self.settings["options"]:
2621 - if "fetch" not in self.settings["options"]:
2622 - self.settings["action_sequence"].append("capture")
2623 - self.settings["action_sequence"].append("clear_autoresume")
2624 -
2625 - def set_use(self):
2626 - if self.settings["spec_prefix"]+"/use" in self.settings:
2627 - self.settings["use"]=\
2628 - self.settings[self.settings["spec_prefix"]+"/use"]
2629 - del self.settings[self.settings["spec_prefix"]+"/use"]
2630 - if "use" not in self.settings:
2631 - self.settings["use"]=""
2632 - if type(self.settings["use"])==types.StringType:
2633 - self.settings["use"]=self.settings["use"].split()
2634 -
2635 - # Force bindist when options ask for it
2636 - if "BINDIST" in self.settings:
2637 - self.settings["use"].append("bindist")
2638 -
2639 - def set_stage_path(self):
2640 - self.settings["stage_path"]=normpath(self.settings["chroot_path"])
2641 -
2642 - def set_mounts(self):
2643 - pass
2644 -
2645 - def set_packages(self):
2646 - pass
2647 -
2648 - def set_rm(self):
2649 - if self.settings["spec_prefix"]+"/rm" in self.settings:
2650 - if type(self.settings[self.settings["spec_prefix"]+\
2651 - "/rm"])==types.StringType:
2652 - self.settings[self.settings["spec_prefix"]+"/rm"]=\
2653 - self.settings[self.settings["spec_prefix"]+"/rm"].split()
2654 -
2655 - def set_linuxrc(self):
2656 - if self.settings["spec_prefix"]+"/linuxrc" in self.settings:
2657 - if type(self.settings[self.settings["spec_prefix"]+\
2658 - "/linuxrc"])==types.StringType:
2659 - self.settings["linuxrc"]=\
2660 - self.settings[self.settings["spec_prefix"]+"/linuxrc"]
2661 - del self.settings[self.settings["spec_prefix"]+"/linuxrc"]
2662 -
2663 - def set_busybox_config(self):
2664 - if self.settings["spec_prefix"]+"/busybox_config" in self.settings:
2665 - if type(self.settings[self.settings["spec_prefix"]+\
2666 - "/busybox_config"])==types.StringType:
2667 - self.settings["busybox_config"]=\
2668 - self.settings[self.settings["spec_prefix"]+"/busybox_config"]
2669 - del self.settings[self.settings["spec_prefix"]+"/busybox_config"]
2670 -
2671 - def set_portage_overlay(self):
2672 - if "portage_overlay" in self.settings:
2673 - if type(self.settings["portage_overlay"])==types.StringType:
2674 - self.settings["portage_overlay"]=\
2675 - self.settings["portage_overlay"].split()
2676 - print "portage_overlay directories are set to: \""+\
2677 - string.join(self.settings["portage_overlay"])+"\""
2678 -
2679 - def set_overlay(self):
2680 - if self.settings["spec_prefix"]+"/overlay" in self.settings:
2681 - if type(self.settings[self.settings["spec_prefix"]+\
2682 - "/overlay"])==types.StringType:
2683 - self.settings[self.settings["spec_prefix"]+"/overlay"]=\
2684 - self.settings[self.settings["spec_prefix"]+\
2685 - "/overlay"].split()
2686 -
2687 - def set_root_overlay(self):
2688 - if self.settings["spec_prefix"]+"/root_overlay" in self.settings:
2689 - if type(self.settings[self.settings["spec_prefix"]+\
2690 - "/root_overlay"])==types.StringType:
2691 - self.settings[self.settings["spec_prefix"]+"/root_overlay"]=\
2692 - self.settings[self.settings["spec_prefix"]+\
2693 - "/root_overlay"].split()
2694 -
2695 - def set_root_path(self):
2696 - """ ROOT= variable for emerges """
2697 - self.settings["root_path"]="/"
2698 -
2699 - def set_valid_build_kernel_vars(self,addlargs):
2700 - if "boot/kernel" in addlargs:
2701 - if type(addlargs["boot/kernel"])==types.StringType:
2702 - loopy=[addlargs["boot/kernel"]]
2703 - else:
2704 - loopy=addlargs["boot/kernel"]
2705 -
2706 - for x in loopy:
2707 - self.valid_values.append("boot/kernel/"+x+"/aliases")
2708 - self.valid_values.append("boot/kernel/"+x+"/config")
2709 - self.valid_values.append("boot/kernel/"+x+"/console")
2710 - self.valid_values.append("boot/kernel/"+x+"/extraversion")
2711 - self.valid_values.append("boot/kernel/"+x+"/gk_action")
2712 - self.valid_values.append("boot/kernel/"+x+"/gk_kernargs")
2713 - self.valid_values.append("boot/kernel/"+x+"/initramfs_overlay")
2714 - self.valid_values.append("boot/kernel/"+x+"/machine_type")
2715 - self.valid_values.append("boot/kernel/"+x+"/sources")
2716 - self.valid_values.append("boot/kernel/"+x+"/softlevel")
2717 - self.valid_values.append("boot/kernel/"+x+"/use")
2718 - self.valid_values.append("boot/kernel/"+x+"/packages")
2719 - if "boot/kernel/"+x+"/packages" in addlargs:
2720 - if type(addlargs["boot/kernel/"+x+\
2721 - "/packages"])==types.StringType:
2722 - addlargs["boot/kernel/"+x+"/packages"]=\
2723 - [addlargs["boot/kernel/"+x+"/packages"]]
2724 -
2725 - def set_build_kernel_vars(self):
2726 - if self.settings["spec_prefix"]+"/gk_mainargs" in self.settings:
2727 - self.settings["gk_mainargs"]=\
2728 - self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
2729 - del self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
2730 -
2731 - def kill_chroot_pids(self):
2732 - print "Checking for processes running in chroot and killing them."
2733 -
2734 - """
2735 - Force environment variables to be exported so script can see them
2736 - """
2737 - self.setup_environment()
2738 -
2739 - if os.path.exists(self.settings["sharedir"]+\
2740 - "/targets/support/kill-chroot-pids.sh"):
2741 - cmd("/bin/bash "+self.settings["sharedir"]+\
2742 - "/targets/support/kill-chroot-pids.sh",\
2743 - "kill-chroot-pids script failed.",env=self.env)
2744 -
2745 - def mount_safety_check(self):
2746 - """
2747 - Check and verify that none of our paths in mypath are mounted. We don't
2748 - want to clean up with things still mounted, and this allows us to check.
2749 - Returns 1 on ok, 0 on "something is still mounted" case.
2750 - """
2751 -
2752 - if not os.path.exists(self.settings["chroot_path"]):
2753 - return
2754 -
2755 - print "self.mounts =", self.mounts
2756 - for x in self.mounts:
2757 - target = normpath(self.settings["chroot_path"] + self.target_mounts[x])
2758 - print "mount_safety_check() x =", x, target
2759 - if not os.path.exists(target):
2760 - continue
2761 -
2762 - if ismount(target):
2763 - """ Something is still mounted "" """
2764 - try:
2765 - print target + " is still mounted; performing auto-bind-umount...",
2766 - """ Try to umount stuff ourselves """
2767 - self.unbind()
2768 - if ismount(target):
2769 - raise CatalystError, "Auto-unbind failed for " + target
2770 - else:
2771 - print "Auto-unbind successful..."
2772 - except CatalystError:
2773 - raise CatalystError, "Unable to auto-unbind " + target
2774 -
2775 - def unpack(self):
2776 - unpack=True
2777 -
2778 - unpack_resume = pjoin(self.settings["autoresume_path"], "unpack")
2779 - clst_unpack_hash=read_from_clst(unpack_resume)
2780 -
2781 - if "seedcache" in self.settings["options"]:
2782 - if os.path.isdir(self.settings["source_path"]):
2783 - """ SEEDCACHE Is a directory, use rsync """
2784 - unpack_cmd="rsync -a --delete "+self.settings["source_path"]+\
2785 - " "+self.settings["chroot_path"]
2786 - display_msg="\nStarting rsync from "+\
2787 - self.settings["source_path"]+"\nto "+\
2788 - self.settings["chroot_path"]+\
2789 - " (This may take some time) ...\n"
2790 - error_msg="Rsync of "+self.settings["source_path"]+" to "+\
2791 - self.settings["chroot_path"]+" failed."
2792 - else:
2793 - """ SEEDCACHE is a not a directory, try untar'ing """
2794 - print "Referenced SEEDCACHE does not appear to be a directory, trying to untar..."
2795 - display_msg="\nStarting tar extract from "+\
2796 - self.settings["source_path"]+"\nto "+\
2797 - self.settings["chroot_path"]+\
2798 - " (This may take some time) ...\n"
2799 - if "bz2" == self.settings["chroot_path"][-3:]:
2800 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
2801 - self.settings["chroot_path"]
2802 - else:
2803 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
2804 - self.settings["chroot_path"]
2805 - error_msg="Tarball extraction of "+\
2806 - self.settings["source_path"]+" to "+\
2807 - self.settings["chroot_path"]+" failed."
2808 - else:
2809 - """ No SEEDCACHE, use tar """
2810 - display_msg="\nStarting tar extract from "+\
2811 - self.settings["source_path"]+"\nto "+\
2812 - self.settings["chroot_path"]+\
2813 - " (This may take some time) ...\n"
2814 - if "bz2" == self.settings["chroot_path"][-3:]:
2815 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
2816 - self.settings["chroot_path"]
2817 - else:
2818 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["source_path"]+" -C "+\
2819 - self.settings["chroot_path"]
2820 - error_msg="Tarball extraction of "+self.settings["source_path"]+\
2821 - " to "+self.settings["chroot_path"]+" failed."
2822 -
2823 - if "autoresume" in self.settings["options"]:
2824 - if os.path.isdir(self.settings["source_path"]) \
2825 - and os.path.exists(unpack_resume):
2826 - """ Autoresume is valid, SEEDCACHE is valid """
2827 - unpack=False
2828 - invalid_snapshot=False
2829 -
2830 - elif os.path.isfile(self.settings["source_path"]) \
2831 - and self.settings["source_path_hash"]==clst_unpack_hash:
2832 - """ Autoresume is valid, tarball is valid """
2833 - unpack=False
2834 - invalid_snapshot=True
2835 -
2836 - elif os.path.isdir(self.settings["source_path"]) \
2837 - and not os.path.exists(unpack_resume):
2838 - """ Autoresume is invalid, SEEDCACHE """
2839 - unpack=True
2840 - invalid_snapshot=False
2841 -
2842 - elif os.path.isfile(self.settings["source_path"]) \
2843 - and self.settings["source_path_hash"]!=clst_unpack_hash:
2844 - """ Autoresume is invalid, tarball """
2845 - unpack=True
2846 - invalid_snapshot=True
2847 - else:
2848 - """ No autoresume, SEEDCACHE """
2849 - if "seedcache" in self.settings["options"]:
2850 - """ SEEDCACHE so let's run rsync and let it clean up """
2851 - if os.path.isdir(self.settings["source_path"]):
2852 - unpack=True
2853 - invalid_snapshot=False
2854 - elif os.path.isfile(self.settings["source_path"]):
2855 - """ Tarball so unpack and remove anything already there """
2856 - unpack=True
2857 - invalid_snapshot=True
2858 - """ No autoresume, no SEEDCACHE """
2859 - else:
2860 - """ Tarball so unpack and remove anything already there """
2861 - if os.path.isfile(self.settings["source_path"]):
2862 - unpack=True
2863 - invalid_snapshot=True
2864 - elif os.path.isdir(self.settings["source_path"]):
2865 - """ We should never reach this, so something is very wrong """
2866 - raise CatalystError,\
2867 - "source path is a dir but seedcache is not enabled"
2868 -
2869 - if unpack:
2870 - self.mount_safety_check()
2871 -
2872 - if invalid_snapshot:
2873 - if "autoresume" in self.settings["options"]:
2874 - print "No Valid Resume point detected, cleaning up..."
2875 -
2876 - self.clear_autoresume()
2877 - self.clear_chroot()
2878 -
2879 - if not os.path.exists(self.settings["chroot_path"]):
2880 - os.makedirs(self.settings["chroot_path"])
2881 -
2882 - if not os.path.exists(self.settings["chroot_path"]+"/tmp"):
2883 - os.makedirs(self.settings["chroot_path"]+"/tmp",1777)
2884 -
2885 - if "pkgcache" in self.settings["options"]:
2886 - if not os.path.exists(self.settings["pkgcache_path"]):
2887 - os.makedirs(self.settings["pkgcache_path"],0755)
2888 -
2889 - if "kerncache" in self.settings["options"]:
2890 - if not os.path.exists(self.settings["kerncache_path"]):
2891 - os.makedirs(self.settings["kerncache_path"],0755)
2892 -
2893 - print display_msg
2894 - cmd(unpack_cmd,error_msg,env=self.env)
2895 -
2896 - if "source_path_hash" in self.settings:
2897 - myf=open(unpack_resume,"w")
2898 - myf.write(self.settings["source_path_hash"])
2899 - myf.close()
2900 - else:
2901 - touch(unpack_resume)
2902 - else:
2903 - print "Resume point detected, skipping unpack operation..."
2904 -
2905 - def unpack_snapshot(self):
2906 - unpack=True
2907 - unpack_portage_resume = pjoin(self.settings["autoresume_path"],
2908 - "unpack_portage")
2909 - snapshot_hash=read_from_clst(unpack_portage_resume)
2910 -
2911 - if "snapcache" in self.settings["options"]:
2912 - snapshot_cache_hash=\
2913 - read_from_clst(self.settings["snapshot_cache_path"] + "/" +
2914 - "catalyst-hash")
2915 - destdir=self.settings["snapshot_cache_path"]
2916 - if "bz2" == self.settings["chroot_path"][-3:]:
2917 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["snapshot_path"]+" -C "+destdir
2918 - else:
2919 - unpack_cmd="tar xpf "+self.settings["snapshot_path"]+" -C "+destdir
2920 - unpack_errmsg="Error unpacking snapshot"
2921 - cleanup_msg="Cleaning up invalid snapshot cache at \n\t"+\
2922 - self.settings["snapshot_cache_path"]+\
2923 - " (This can take a long time)..."
2924 - cleanup_errmsg="Error removing existing snapshot cache directory."
2925 - self.snapshot_lock_object=self.snapcache_lock
2926 -
2927 - if self.settings["snapshot_path_hash"]==snapshot_cache_hash:
2928 - print "Valid snapshot cache, skipping unpack of portage tree..."
2929 - unpack=False
2930 - else:
2931 - destdir = normpath(self.settings["chroot_path"] + self.settings["portdir"])
2932 - cleanup_errmsg="Error removing existing snapshot directory."
2933 - cleanup_msg=\
2934 - "Cleaning up existing portage tree (This can take a long time)..."
2935 - if "bz2" == self.settings["chroot_path"][-3:]:
2936 - unpack_cmd="tar -I lbzip2 -xpf "+self.settings["snapshot_path"]+" -C "+\
2937 - self.settings["chroot_path"]+"/usr"
2938 - else:
2939 - unpack_cmd="tar xpf "+self.settings["snapshot_path"]+" -C "+\
2940 - self.settings["chroot_path"]+"/usr"
2941 - unpack_errmsg="Error unpacking snapshot"
2942 -
2943 - if "autoresume" in self.settings["options"] \
2944 - and os.path.exists(self.settings["chroot_path"]+\
2945 - self.settings["portdir"]) \
2946 - and os.path.exists(unpack_portage_resume) \
2947 - and self.settings["snapshot_path_hash"] == snapshot_hash:
2948 - print \
2949 - "Valid Resume point detected, skipping unpack of portage tree..."
2950 - unpack=False
2951 -
2952 - if unpack:
2953 - if "snapcache" in self.settings["options"]:
2954 - self.snapshot_lock_object.write_lock()
2955 - if os.path.exists(destdir):
2956 - print cleanup_msg
2957 - cleanup_cmd="rm -rf "+destdir
2958 - cmd(cleanup_cmd,cleanup_errmsg,env=self.env)
2959 - if not os.path.exists(destdir):
2960 - os.makedirs(destdir,0755)
2961 -
2962 - print "Unpacking portage tree (This can take a long time) ..."
2963 - cmd(unpack_cmd,unpack_errmsg,env=self.env)
2964 -
2965 - if "snapcache" in self.settings["options"]:
2966 - myf=open(self.settings["snapshot_cache_path"] +
2967 - "/" + "catalyst-hash","w")
2968 - myf.write(self.settings["snapshot_path_hash"])
2969 - myf.close()
2970 - else:
2971 - print "Setting snapshot autoresume point"
2972 - myf=open(unpack_portage_resume,"w")
2973 - myf.write(self.settings["snapshot_path_hash"])
2974 - myf.close()
2975 -
2976 - if "snapcache" in self.settings["options"]:
2977 - self.snapshot_lock_object.unlock()
2978 -
2979 - def config_profile_link(self):
2980 - config_protect_link_resume = pjoin(self.settings["autoresume_path"],
2981 - "config_profile_link")
2982 - if "autoresume" in self.settings["options"] \
2983 - and os.path.exists(config_protect_link_resume):
2984 - print \
2985 - "Resume point detected, skipping config_profile_link operation..."
2986 - else:
2987 - # TODO: zmedico and I discussed making this a directory and pushing
2988 - # in a parent file, as well as other user-specified configuration.
2989 - print "Configuring profile link..."
2990 - cmd("rm -f "+self.settings["chroot_path"]+"/etc/portage/make.profile",\
2991 - "Error zapping profile link",env=self.env)
2992 - cmd("mkdir -p "+self.settings["chroot_path"]+"/etc/portage/")
2993 - cmd("ln -sf ../.." + self.settings["portdir"] + "/profiles/" + \
2994 - self.settings["target_profile"]+" "+\
2995 - self.settings["chroot_path"]+"/etc/portage/make.profile",\
2996 - "Error creating profile link",env=self.env)
2997 - touch(config_protect_link_resume)
2998 -
2999 - def setup_confdir(self):
3000 - setup_confdir_resume = pjoin(self.settings["autoresume_path"],
3001 - "setup_confdir")
3002 - if "autoresume" in self.settings["options"] \
3003 - and os.path.exists(setup_confdir_resume):
3004 - print "Resume point detected, skipping setup_confdir operation..."
3005 - else:
3006 - if "portage_confdir" in self.settings:
3007 - print "Configuring /etc/portage..."
3008 - cmd("rsync -a "+self.settings["portage_confdir"]+"/ "+\
3009 - self.settings["chroot_path"]+"/etc/portage/",\
3010 - "Error copying /etc/portage",env=self.env)
3011 - touch(setup_confdir_resume)
3012 -
3013 - def portage_overlay(self):
3014 - """ We copy the contents of our overlays to /usr/local/portage """
3015 - if "portage_overlay" in self.settings:
3016 - for x in self.settings["portage_overlay"]:
3017 - if os.path.exists(x):
3018 - print "Copying overlay dir " +x
3019 - cmd("mkdir -p "+self.settings["chroot_path"]+\
3020 - self.settings["local_overlay"],\
3021 - "Could not make portage_overlay dir",env=self.env)
3022 - cmd("cp -R "+x+"/* "+self.settings["chroot_path"]+\
3023 - self.settings["local_overlay"],\
3024 - "Could not copy portage_overlay",env=self.env)
3025 -
3026 - def root_overlay(self):
3027 - """ Copy over the root_overlay """
3028 - if self.settings["spec_prefix"]+"/root_overlay" in self.settings:
3029 - for x in self.settings[self.settings["spec_prefix"]+\
3030 - "/root_overlay"]:
3031 - if os.path.exists(x):
3032 - print "Copying root_overlay: "+x
3033 - cmd("rsync -a "+x+"/ "+\
3034 - self.settings["chroot_path"],\
3035 - self.settings["spec_prefix"]+"/root_overlay: "+x+\
3036 - " copy failed.",env=self.env)
3037 -
3038 - def base_dirs(self):
3039 - pass
3040 -
3041 - def bind(self):
3042 - for x in self.mounts:
3043 - #print "bind(); x =", x
3044 - target = normpath(self.settings["chroot_path"] + self.target_mounts[x])
3045 - if not os.path.exists(target):
3046 - os.makedirs(target, 0755)
3047 -
3048 - if not os.path.exists(self.mountmap[x]):
3049 - if self.mountmap[x] not in ["tmpfs", "shmfs"]:
3050 - os.makedirs(self.mountmap[x], 0755)
3051 -
3052 - src=self.mountmap[x]
3053 - #print "bind(); src =", src
3054 - if "snapcache" in self.settings["options"] and x == "portdir":
3055 - self.snapshot_lock_object.read_lock()
3056 - if os.uname()[0] == "FreeBSD":
3057 - if src == "/dev":
3058 - cmd = "mount -t devfs none " + target
3059 - retval=os.system(cmd)
3060 - else:
3061 - cmd = "mount_nullfs " + src + " " + target
3062 - retval=os.system(cmd)
3063 - else:
3064 - if src == "tmpfs":
3065 - if "var_tmpfs_portage" in self.settings:
3066 - cmd = "mount -t tmpfs -o size=" + \
3067 - self.settings["var_tmpfs_portage"] + "G " + \
3068 - src + " " + target
3069 - retval=os.system(cmd)
3070 - elif src == "shmfs":
3071 - cmd = "mount -t tmpfs -o noexec,nosuid,nodev shm " + target
3072 - retval=os.system(cmd)
3073 - else:
3074 - cmd = "mount --bind " + src + " " + target
3075 - #print "bind(); cmd =", cmd
3076 - retval=os.system(cmd)
3077 - if retval!=0:
3078 - self.unbind()
3079 - raise CatalystError,"Couldn't bind mount " + src
3080 -
3081 - def unbind(self):
3082 - ouch=0
3083 - mypath=self.settings["chroot_path"]
3084 - myrevmounts=self.mounts[:]
3085 - myrevmounts.reverse()
3086 - """ Unmount in reverse order for nested bind-mounts """
3087 - for x in myrevmounts:
3088 - target = normpath(mypath + self.target_mounts[x])
3089 - if not os.path.exists(target):
3090 - continue
3091 -
3092 - if not ismount(target):
3093 - continue
3094 -
3095 - retval=os.system("umount " + target)
3096 -
3097 - if retval!=0:
3098 - warn("First attempt to unmount: " + target + " failed.")
3099 - warn("Killing any pids still running in the chroot")
3100 -
3101 - self.kill_chroot_pids()
3102 -
3103 - retval2 = os.system("umount " + target)
3104 - if retval2!=0:
3105 - ouch=1
3106 - warn("Couldn't umount bind mount: " + target)
3107 -
3108 - if "snapcache" in self.settings["options"] and x == "/usr/portage":
3109 - try:
3110 - """
3111 - It's possible the snapshot lock object isn't created yet.
3112 - This is because mount safety check calls unbind before the
3113 - target is fully initialized
3114 - """
3115 - self.snapshot_lock_object.unlock()
3116 - except:
3117 - pass
3118 - if ouch:
3119 - """
3120 - if any bind mounts really failed, then we need to raise
3121 - this to potentially prevent an upcoming bash stage cleanup script
3122 - from wiping our bind mounts.
3123 - """
3124 - raise CatalystError,\
3125 - "Couldn't umount one or more bind-mounts; aborting for safety."
3126 -
3127 - def chroot_setup(self):
3128 - self.makeconf=read_makeconf(self.settings["chroot_path"]+\
3129 - "/etc/portage/make.conf")
3130 - self.override_cbuild()
3131 - self.override_chost()
3132 - self.override_cflags()
3133 - self.override_cxxflags()
3134 - self.override_ldflags()
3135 - chroot_setup_resume = pjoin(self.settings["autoresume_path"],
3136 - "chroot_setup")
3137 - if "autoresume" in self.settings["options"] \
3138 - and os.path.exists(chroot_setup_resume):
3139 - print "Resume point detected, skipping chroot_setup operation..."
3140 - else:
3141 - print "Setting up chroot..."
3142 -
3143 - #self.makeconf=read_makeconf(self.settings["chroot_path"]+"/etc/portage/make.conf")
3144 -
3145 - cmd("cp /etc/resolv.conf " + self.settings["chroot_path"] + "/etc/",
3146 - "Could not copy resolv.conf into place.",env=self.env)
3147 -
3148 - """ Copy over the envscript, if applicable """
3149 - if "envscript" in self.settings:
3150 - if not os.path.exists(self.settings["envscript"]):
3151 - raise CatalystError,\
3152 - "Can't find envscript "+self.settings["envscript"]
3153 -
3154 - print "\nWarning!!!!"
3155 - print "\tOverriding certain env variables may cause catastrophic failure."
3156 - print "\tIf your build fails look here first as the possible problem."
3157 - print "\tCatalyst assumes you know what you are doing when setting"
3158 - print "\t\tthese variables."
3159 - print "\tCatalyst Maintainers use VERY minimal envscripts if used at all"
3160 - print "\tYou have been warned\n"
3161 -
3162 - cmd("cp "+self.settings["envscript"]+" "+\
3163 - self.settings["chroot_path"]+"/tmp/envscript",\
3164 - "Could not copy envscript into place.",env=self.env)
3165 -
3166 - """
3167 - Copy over /etc/hosts from the host in case there are any
3168 - specialties in there
3169 - """
3170 - if os.path.exists(self.settings["chroot_path"]+"/etc/hosts"):
3171 - cmd("mv "+self.settings["chroot_path"]+"/etc/hosts "+\
3172 - self.settings["chroot_path"]+"/etc/hosts.catalyst",\
3173 - "Could not backup /etc/hosts",env=self.env)
3174 - cmd("cp /etc/hosts "+self.settings["chroot_path"]+"/etc/hosts",\
3175 - "Could not copy /etc/hosts",env=self.env)
3176 -
3177 - """ Modify and write out make.conf (for the chroot) """
3178 - cmd("rm -f "+self.settings["chroot_path"]+"/etc/portage/make.conf",\
3179 - "Could not remove "+self.settings["chroot_path"]+\
3180 - "/etc/portage/make.conf",env=self.env)
3181 - myf=open(self.settings["chroot_path"]+"/etc/portage/make.conf","w")
3182 - myf.write("# These settings were set by the catalyst build script that automatically\n# built this stage.\n")
3183 - myf.write("# Please consult /usr/share/portage/config/make.conf.example for a more\n# detailed example.\n")
3184 - if "CFLAGS" in self.settings:
3185 - myf.write('CFLAGS="'+self.settings["CFLAGS"]+'"\n')
3186 - if "CXXFLAGS" in self.settings:
3187 - if self.settings["CXXFLAGS"]!=self.settings["CFLAGS"]:
3188 - myf.write('CXXFLAGS="'+self.settings["CXXFLAGS"]+'"\n')
3189 - else:
3190 - myf.write('CXXFLAGS="${CFLAGS}"\n')
3191 - else:
3192 - myf.write('CXXFLAGS="${CFLAGS}"\n')
3193 -
3194 - if "LDFLAGS" in self.settings:
3195 - myf.write("# LDFLAGS is unsupported. USE AT YOUR OWN RISK!\n")
3196 - myf.write('LDFLAGS="'+self.settings["LDFLAGS"]+'"\n')
3197 - if "CBUILD" in self.settings:
3198 - 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")
3199 - myf.write('CBUILD="'+self.settings["CBUILD"]+'"\n')
3200 -
3201 - 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")
3202 - myf.write('CHOST="'+self.settings["CHOST"]+'"\n')
3203 -
3204 - """ Figure out what our USE vars are for building """
3205 - myusevars=[]
3206 - if "HOSTUSE" in self.settings:
3207 - myusevars.extend(self.settings["HOSTUSE"])
3208 -
3209 - if "use" in self.settings:
3210 - myusevars.extend(self.settings["use"])
3211 -
3212 - if myusevars:
3213 - myf.write("# These are the USE flags that were used in addition to what is provided by the\n# profile used for building.\n")
3214 - myusevars = sorted(set(myusevars))
3215 - myf.write('USE="'+string.join(myusevars)+'"\n')
3216 - if '-*' in myusevars:
3217 - print "\nWarning!!! "
3218 - print "\tThe use of -* in "+self.settings["spec_prefix"]+\
3219 - "/use will cause portage to ignore"
3220 - print "\tpackage.use in the profile and portage_confdir. You've been warned!"
3221 -
3222 - myf.write('PORTDIR="%s"\n' % self.settings['portdir'])
3223 - myf.write('DISTDIR="%s"\n' % self.settings['distdir'])
3224 - myf.write('PKGDIR="%s"\n' % self.settings['packagedir'])
3225 -
3226 - """ Setup the portage overlay """
3227 - if "portage_overlay" in self.settings:
3228 - myf.write('PORTDIR_OVERLAY="/usr/local/portage"\n')
3229 -
3230 - myf.close()
3231 - cmd("cp "+self.settings["chroot_path"]+"/etc/portage/make.conf "+\
3232 - self.settings["chroot_path"]+"/etc/portage/make.conf.catalyst",\
3233 - "Could not backup /etc/portage/make.conf",env=self.env)
3234 - touch(chroot_setup_resume)
3235 -
3236 - def fsscript(self):
3237 - fsscript_resume = pjoin(self.settings["autoresume_path"], "fsscript")
3238 - if "autoresume" in self.settings["options"] \
3239 - and os.path.exists(fsscript_resume):
3240 - print "Resume point detected, skipping fsscript operation..."
3241 - else:
3242 - if "fsscript" in self.settings:
3243 - if os.path.exists(self.settings["controller_file"]):
3244 - cmd(self.settings["controller_file"]+\
3245 - " fsscript","fsscript script failed.",env=self.env)
3246 - touch(fsscript_resume)
3247 -
3248 - def rcupdate(self):
3249 - rcupdate_resume = pjoin(self.settings["autoresume_path"], "rcupdate")
3250 - if "autoresume" in self.settings["options"] \
3251 - and os.path.exists(rcupdate_resume):
3252 - print "Resume point detected, skipping rcupdate operation..."
3253 - else:
3254 - if os.path.exists(self.settings["controller_file"]):
3255 - cmd(self.settings["controller_file"]+" rc-update",\
3256 - "rc-update script failed.",env=self.env)
3257 - touch(rcupdate_resume)
3258 -
3259 - def clean(self):
3260 - clean_resume = pjoin(self.settings["autoresume_path"], "clean")
3261 - if "autoresume" in self.settings["options"] \
3262 - and os.path.exists(clean_resume):
3263 - print "Resume point detected, skipping clean operation..."
3264 - else:
3265 - for x in self.settings["cleanables"]:
3266 - print "Cleaning chroot: "+x+"... "
3267 - cmd("rm -rf "+self.settings["destpath"]+x,"Couldn't clean "+\
3268 - x,env=self.env)
3269 -
3270 - """ Put /etc/hosts back into place """
3271 - if os.path.exists(self.settings["chroot_path"]+"/etc/hosts.catalyst"):
3272 - cmd("mv -f "+self.settings["chroot_path"]+"/etc/hosts.catalyst "+\
3273 - self.settings["chroot_path"]+"/etc/hosts",\
3274 - "Could not replace /etc/hosts",env=self.env)
3275 -
3276 - """ Remove our overlay """
3277 - if os.path.exists(self.settings["chroot_path"] + self.settings["local_overlay"]):
3278 - cmd("rm -rf " + self.settings["chroot_path"] + self.settings["local_overlay"],
3279 - "Could not remove " + self.settings["local_overlay"], env=self.env)
3280 - cmd("sed -i '/^PORTDIR_OVERLAY/d' "+self.settings["chroot_path"]+\
3281 - "/etc/portage/make.conf",\
3282 - "Could not remove PORTDIR_OVERLAY from make.conf",env=self.env)
3283 -
3284 - """ Clean up old and obsoleted files in /etc """
3285 - if os.path.exists(self.settings["stage_path"]+"/etc"):
3286 - cmd("find "+self.settings["stage_path"]+\
3287 - "/etc -maxdepth 1 -name \"*-\" | xargs rm -f",\
3288 - "Could not remove stray files in /etc",env=self.env)
3289 -
3290 - if os.path.exists(self.settings["controller_file"]):
3291 - cmd(self.settings["controller_file"]+" clean",\
3292 - "clean script failed.",env=self.env)
3293 - touch(clean_resume)
3294 -
3295 - def empty(self):
3296 - empty_resume = pjoin(self.settings["autoresume_path"], "empty")
3297 - if "autoresume" in self.settings["options"] \
3298 - and os.path.exists(empty_resume):
3299 - print "Resume point detected, skipping empty operation..."
3300 - else:
3301 - if self.settings["spec_prefix"]+"/empty" in self.settings:
3302 - if type(self.settings[self.settings["spec_prefix"]+\
3303 - "/empty"])==types.StringType:
3304 - self.settings[self.settings["spec_prefix"]+"/empty"]=\
3305 - self.settings[self.settings["spec_prefix"]+\
3306 - "/empty"].split()
3307 - for x in self.settings[self.settings["spec_prefix"]+"/empty"]:
3308 - myemp=self.settings["destpath"]+x
3309 - if not os.path.isdir(myemp) or os.path.islink(myemp):
3310 - print x,"not a directory or does not exist, skipping 'empty' operation."
3311 - continue
3312 - print "Emptying directory",x
3313 - """
3314 - stat the dir, delete the dir, recreate the dir and set
3315 - the proper perms and ownership
3316 - """
3317 - mystat=os.stat(myemp)
3318 - shutil.rmtree(myemp)
3319 - os.makedirs(myemp,0755)
3320 - os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
3321 - os.chmod(myemp,mystat[ST_MODE])
3322 - touch(empty_resume)
3323 -
3324 - def remove(self):
3325 - remove_resume = pjoin(self.settings["autoresume_path"], "remove")
3326 - if "autoresume" in self.settings["options"] \
3327 - and os.path.exists(remove_resume):
3328 - print "Resume point detected, skipping remove operation..."
3329 - else:
3330 - if self.settings["spec_prefix"]+"/rm" in self.settings:
3331 - for x in self.settings[self.settings["spec_prefix"]+"/rm"]:
3332 - """
3333 - We're going to shell out for all these cleaning
3334 - operations, so we get easy glob handling.
3335 - """
3336 - print "livecd: removing "+x
3337 - os.system("rm -rf "+self.settings["chroot_path"]+x)
3338 - try:
3339 - if os.path.exists(self.settings["controller_file"]):
3340 - cmd(self.settings["controller_file"]+\
3341 - " clean","Clean failed.",env=self.env)
3342 - touch(remove_resume)
3343 - except:
3344 - self.unbind()
3345 - raise
3346 -
3347 - def preclean(self):
3348 - preclean_resume = pjoin(self.settings["autoresume_path"], "preclean")
3349 - if "autoresume" in self.settings["options"] \
3350 - and os.path.exists(preclean_resume):
3351 - print "Resume point detected, skipping preclean operation..."
3352 - else:
3353 - try:
3354 - if os.path.exists(self.settings["controller_file"]):
3355 - cmd(self.settings["controller_file"]+\
3356 - " preclean","preclean script failed.",env=self.env)
3357 - touch(preclean_resume)
3358 -
3359 - except:
3360 - self.unbind()
3361 - raise CatalystError, "Build failed, could not execute preclean"
3362 -
3363 - def capture(self):
3364 - capture_resume = pjoin(self.settings["autoresume_path"], "capture")
3365 - if "autoresume" in self.settings["options"] \
3366 - and os.path.exists(capture_resume):
3367 - print "Resume point detected, skipping capture operation..."
3368 - else:
3369 - """ Capture target in a tarball """
3370 - mypath=self.settings["target_path"].split("/")
3371 - """ Remove filename from path """
3372 - mypath=string.join(mypath[:-1],"/")
3373 -
3374 - """ Now make sure path exists """
3375 - if not os.path.exists(mypath):
3376 - os.makedirs(mypath)
3377 -
3378 - print "Creating stage tarball..."
3379 -
3380 - cmd("tar -I lbzip2 -cpf "+self.settings["target_path"]+" -C "+\
3381 - self.settings["stage_path"]+" .",\
3382 - "Couldn't create stage tarball",env=self.env)
3383 -
3384 - self.gen_contents_file(self.settings["target_path"])
3385 - self.gen_digest_file(self.settings["target_path"])
3386 -
3387 - touch(capture_resume)
3388 -
3389 - def run_local(self):
3390 - run_local_resume = pjoin(self.settings["autoresume_path"], "run_local")
3391 - if "autoresume" in self.settings["options"] \
3392 - and os.path.exists(run_local_resume):
3393 - print "Resume point detected, skipping run_local operation..."
3394 - else:
3395 - try:
3396 - if os.path.exists(self.settings["controller_file"]):
3397 - cmd(self.settings["controller_file"]+" run",\
3398 - "run script failed.",env=self.env)
3399 - touch(run_local_resume)
3400 -
3401 - except CatalystError:
3402 - self.unbind()
3403 - raise CatalystError,"Stage build aborting due to error."
3404 -
3405 - def setup_environment(self):
3406 - """
3407 - Modify the current environment. This is an ugly hack that should be
3408 - fixed. We need this to use the os.system() call since we can't
3409 - specify our own environ
3410 - """
3411 - #print "setup_environment(); settings =", list(self.settings)
3412 - for x in list(self.settings):
3413 - #print "setup_environment(); processing:", x
3414 - if x == "options":
3415 - #self.env['clst_' + x] = ' '.join(self.settings[x])
3416 - for opt in self.settings[x]:
3417 - self.env['clst_' + opt.upper()] = "true"
3418 - continue
3419 - """ Sanitize var names by doing "s|/-.|_|g" """
3420 - varname="clst_"+string.replace(x,"/","_")
3421 - varname=string.replace(varname,"-","_")
3422 - varname=string.replace(varname,".","_")
3423 - if type(self.settings[x])==types.StringType:
3424 - """ Prefix to prevent namespace clashes """
3425 - #os.environ[varname]=self.settings[x]
3426 - self.env[varname]=self.settings[x]
3427 - elif type(self.settings[x])==types.ListType:
3428 - #os.environ[varname]=string.join(self.settings[x])
3429 - self.env[varname]=string.join(self.settings[x])
3430 - elif type(self.settings[x])==types.BooleanType:
3431 - if self.settings[x]:
3432 - self.env[varname]="true"
3433 - else:
3434 - self.env[varname]="false"
3435 - if "makeopts" in self.settings:
3436 - self.env["MAKEOPTS"]=self.settings["makeopts"]
3437 -
3438 - def run(self):
3439 - self.chroot_lock.write_lock()
3440 -
3441 - """ Kill any pids in the chroot "" """
3442 - self.kill_chroot_pids()
3443 -
3444 - """ Check for mounts right away and abort if we cannot unmount them """
3445 - self.mount_safety_check()
3446 -
3447 - if "clear-autoresume" in self.settings["options"]:
3448 - self.clear_autoresume()
3449 -
3450 - if "purgetmponly" in self.settings["options"]:
3451 - self.purge()
3452 - return
3453 -
3454 - if "PURGEONLY" in self.settings:
3455 - self.purge()
3456 - return
3457 -
3458 - if "purge" in self.settings["options"]:
3459 - self.purge()
3460 -
3461 - for x in self.settings["action_sequence"]:
3462 - print "--- Running action sequence: "+x
3463 - sys.stdout.flush()
3464 - try:
3465 - apply(getattr(self,x))
3466 - except:
3467 - self.mount_safety_check()
3468 - raise
3469 -
3470 - self.chroot_lock.unlock()
3471 -
3472 - def unmerge(self):
3473 - unmerge_resume = pjoin(self.settings["autoresume_path"], "unmerge")
3474 - if "autoresume" in self.settings["options"] \
3475 - and os.path.exists(unmerge_resume):
3476 - print "Resume point detected, skipping unmerge operation..."
3477 - else:
3478 - if self.settings["spec_prefix"]+"/unmerge" in self.settings:
3479 - if type(self.settings[self.settings["spec_prefix"]+\
3480 - "/unmerge"])==types.StringType:
3481 - self.settings[self.settings["spec_prefix"]+"/unmerge"]=\
3482 - [self.settings[self.settings["spec_prefix"]+"/unmerge"]]
3483 - myunmerge=\
3484 - self.settings[self.settings["spec_prefix"]+"/unmerge"][:]
3485 -
3486 - for x in range(0,len(myunmerge)):
3487 - """
3488 - Surround args with quotes for passing to bash, allows
3489 - things like "<" to remain intact
3490 - """
3491 - myunmerge[x]="'"+myunmerge[x]+"'"
3492 - myunmerge=string.join(myunmerge)
3493 -
3494 - """ Before cleaning, unmerge stuff """
3495 - try:
3496 - cmd(self.settings["controller_file"]+\
3497 - " unmerge "+ myunmerge,"Unmerge script failed.",\
3498 - env=self.env)
3499 - print "unmerge shell script"
3500 - except CatalystError:
3501 - self.unbind()
3502 - raise
3503 - touch(unmerge_resume)
3504 -
3505 - def target_setup(self):
3506 - target_setup_resume = pjoin(self.settings["autoresume_path"],
3507 - "target_setup")
3508 - if "autoresume" in self.settings["options"] \
3509 - and os.path.exists(target_setup_resume):
3510 - print "Resume point detected, skipping target_setup operation..."
3511 - else:
3512 - print "Setting up filesystems per filesystem type"
3513 - cmd(self.settings["controller_file"]+\
3514 - " target_image_setup "+ self.settings["target_path"],\
3515 - "target_image_setup script failed.",env=self.env)
3516 - touch(target_setup_resume)
3517 -
3518 - def setup_overlay(self):
3519 - setup_overlay_resume = pjoin(self.settings["autoresume_path"],
3520 - "setup_overlay")
3521 - if "autoresume" in self.settings["options"] \
3522 - and os.path.exists(setup_overlay_resume):
3523 - print "Resume point detected, skipping setup_overlay operation..."
3524 - else:
3525 - if self.settings["spec_prefix"]+"/overlay" in self.settings:
3526 - for x in self.settings[self.settings["spec_prefix"]+"/overlay"]:
3527 - if os.path.exists(x):
3528 - cmd("rsync -a "+x+"/ "+\
3529 - self.settings["target_path"],\
3530 - self.settings["spec_prefix"]+"overlay: "+x+\
3531 - " copy failed.",env=self.env)
3532 - touch(setup_overlay_resume)
3533 -
3534 - def create_iso(self):
3535 - create_iso_resume = pjoin(self.settings["autoresume_path"], "create_iso")
3536 - if "autoresume" in self.settings["options"] \
3537 - and os.path.exists(create_iso_resume):
3538 - print "Resume point detected, skipping create_iso operation..."
3539 - else:
3540 - """ Create the ISO """
3541 - if "iso" in self.settings:
3542 - cmd(self.settings["controller_file"]+" iso "+\
3543 - self.settings["iso"],"ISO creation script failed.",\
3544 - env=self.env)
3545 - self.gen_contents_file(self.settings["iso"])
3546 - self.gen_digest_file(self.settings["iso"])
3547 - touch(create_iso_resume)
3548 - else:
3549 - print "WARNING: livecd/iso was not defined."
3550 - print "An ISO Image will not be created."
3551 -
3552 - def build_packages(self):
3553 - build_packages_resume = pjoin(self.settings["autoresume_path"],
3554 - "build_packages")
3555 - if "autoresume" in self.settings["options"] \
3556 - and os.path.exists(build_packages_resume):
3557 - print "Resume point detected, skipping build_packages operation..."
3558 - else:
3559 - if self.settings["spec_prefix"]+"/packages" in self.settings:
3560 - if "autoresume" in self.settings["options"] \
3561 - and os.path.exists(self.settings["autoresume_path"]+\
3562 - "build_packages"):
3563 - print "Resume point detected, skipping build_packages operation..."
3564 - else:
3565 - mypack=\
3566 - list_bashify(self.settings[self.settings["spec_prefix"]\
3567 - +"/packages"])
3568 - try:
3569 - cmd(self.settings["controller_file"]+\
3570 - " build_packages "+mypack,\
3571 - "Error in attempt to build packages",env=self.env)
3572 - touch(build_packages_resume)
3573 - except CatalystError:
3574 - self.unbind()
3575 - raise CatalystError,self.settings["spec_prefix"]+\
3576 - "build aborting due to error."
3577 -
3578 - def build_kernel(self):
3579 - '''Build all configured kernels'''
3580 - build_kernel_resume = pjoin(self.settings["autoresume_path"],
3581 - "build_kernel")
3582 - if "autoresume" in self.settings["options"] \
3583 - and os.path.exists(build_kernel_resume):
3584 - print "Resume point detected, skipping build_kernel operation..."
3585 - else:
3586 - if "boot/kernel" in self.settings:
3587 - try:
3588 - mynames=self.settings["boot/kernel"]
3589 - if type(mynames)==types.StringType:
3590 - mynames=[mynames]
3591 - """
3592 - Execute the script that sets up the kernel build environment
3593 - """
3594 - cmd(self.settings["controller_file"]+\
3595 - " pre-kmerge ","Runscript pre-kmerge failed",\
3596 - env=self.env)
3597 - for kname in mynames:
3598 - self._build_kernel(kname=kname)
3599 - touch(build_kernel_resume)
3600 - except CatalystError:
3601 - self.unbind()
3602 - raise CatalystError,\
3603 - "build aborting due to kernel build error."
3604 -
3605 - def _build_kernel(self, kname):
3606 - "Build a single configured kernel by name"
3607 - kname_resume = pjoin(self.settings["autoresume_path"],
3608 - "build_kernel_" + kname)
3609 - if "autoresume" in self.settings["options"] \
3610 - and os.path.exists(kname_resume):
3611 - print "Resume point detected, skipping build_kernel for "+kname+" operation..."
3612 - return
3613 - self._copy_kernel_config(kname=kname)
3614 -
3615 - """
3616 - If we need to pass special options to the bootloader
3617 - for this kernel put them into the environment
3618 - """
3619 - if "boot/kernel/"+kname+"/kernelopts" in self.settings:
3620 - myopts=self.settings["boot/kernel/"+kname+\
3621 - "/kernelopts"]
3622 -
3623 - if type(myopts) != types.StringType:
3624 - myopts = string.join(myopts)
3625 - self.env[kname+"_kernelopts"]=myopts
3626 -
3627 - else:
3628 - self.env[kname+"_kernelopts"]=""
3629 -
3630 - if "boot/kernel/"+kname+"/extraversion" not in self.settings:
3631 - self.settings["boot/kernel/"+kname+\
3632 - "/extraversion"]=""
3633 -
3634 - self.env["clst_kextraversion"]=\
3635 - self.settings["boot/kernel/"+kname+\
3636 - "/extraversion"]
3637 -
3638 - self._copy_initramfs_overlay(kname=kname)
3639 -
3640 - """ Execute the script that builds the kernel """
3641 - cmd("/bin/bash "+self.settings["controller_file"]+\
3642 - " kernel "+kname,\
3643 - "Runscript kernel build failed",env=self.env)
3644 -
3645 - if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings:
3646 - if os.path.exists(self.settings["chroot_path"]+\
3647 - "/tmp/initramfs_overlay/"):
3648 - print "Cleaning up temporary overlay dir"
3649 - cmd("rm -R "+self.settings["chroot_path"]+\
3650 - "/tmp/initramfs_overlay/",env=self.env)
3651 -
3652 - touch(kname_resume)
3653 -
3654 - """
3655 - Execute the script that cleans up the kernel build
3656 - environment
3657 - """
3658 - cmd("/bin/bash "+self.settings["controller_file"]+\
3659 - " post-kmerge ",
3660 - "Runscript post-kmerge failed",env=self.env)
3661 -
3662 - def _copy_kernel_config(self, kname):
3663 - if "boot/kernel/"+kname+"/config" in self.settings:
3664 - if not os.path.exists(self.settings["boot/kernel/"+kname+"/config"]):
3665 - self.unbind()
3666 - raise CatalystError,\
3667 - "Can't find kernel config: "+\
3668 - self.settings["boot/kernel/"+kname+\
3669 - "/config"]
3670 -
3671 - try:
3672 - cmd("cp "+self.settings["boot/kernel/"+kname+\
3673 - "/config"]+" "+\
3674 - self.settings["chroot_path"]+"/var/tmp/"+\
3675 - kname+".config",\
3676 - "Couldn't copy kernel config: "+\
3677 - self.settings["boot/kernel/"+kname+\
3678 - "/config"],env=self.env)
3679 -
3680 - except CatalystError:
3681 - self.unbind()
3682 -
3683 - def _copy_initramfs_overlay(self, kname):
3684 - if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings:
3685 - if os.path.exists(self.settings["boot/kernel/"+\
3686 - kname+"/initramfs_overlay"]):
3687 - print "Copying initramfs_overlay dir "+\
3688 - self.settings["boot/kernel/"+kname+\
3689 - "/initramfs_overlay"]
3690 -
3691 - cmd("mkdir -p "+\
3692 - self.settings["chroot_path"]+\
3693 - "/tmp/initramfs_overlay/"+\
3694 - self.settings["boot/kernel/"+kname+\
3695 - "/initramfs_overlay"],env=self.env)
3696 -
3697 - cmd("cp -R "+self.settings["boot/kernel/"+\
3698 - kname+"/initramfs_overlay"]+"/* "+\
3699 - self.settings["chroot_path"]+\
3700 - "/tmp/initramfs_overlay/"+\
3701 - self.settings["boot/kernel/"+kname+\
3702 - "/initramfs_overlay"],env=self.env)
3703 -
3704 - def bootloader(self):
3705 - bootloader_resume = pjoin(self.settings["autoresume_path"], "bootloader")
3706 - if "autoresume" in self.settings["options"] \
3707 - and os.path.exists(bootloader_resume):
3708 - print "Resume point detected, skipping bootloader operation..."
3709 - else:
3710 - try:
3711 - cmd(self.settings["controller_file"]+\
3712 - " bootloader " + self.settings["target_path"],\
3713 - "Bootloader script failed.",env=self.env)
3714 - touch(bootloader_resume)
3715 - except CatalystError:
3716 - self.unbind()
3717 - raise CatalystError,"Script aborting due to error."
3718 -
3719 - def livecd_update(self):
3720 - livecd_update_resume = pjoin(self.settings["autoresume_path"],
3721 - "livecd_update")
3722 - if "autoresume" in self.settings["options"] \
3723 - and os.path.exists(livecd_update_resume):
3724 - print "Resume point detected, skipping build_packages operation..."
3725 - else:
3726 - try:
3727 - cmd(self.settings["controller_file"]+\
3728 - " livecd-update","livecd-update failed.",env=self.env)
3729 - touch(livecd_update_resume)
3730 -
3731 - except CatalystError:
3732 - self.unbind()
3733 - raise CatalystError,"build aborting due to livecd_update error."
3734 -
3735 -# vim: ts=4 sw=4 sta et sts=4 ai
3736 diff --git a/catalyst/targets/grp_target.py b/catalyst/targets/grp_target.py
3737 index 033db75..deba80a 100644
3738 --- a/catalyst/targets/grp_target.py
3739 +++ b/catalyst/targets/grp_target.py
3740 @@ -3,11 +3,18 @@ Gentoo Reference Platform (GRP) target
3741 """
3742 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
3743
3744 -import os,types,glob
3745 -from catalyst.support import *
3746 -from generic_stage_target import *
3747 +import os
3748 +import types
3749 +import glob
3750
3751 -class grp_target(generic_stage_target):
3752 +
3753 +from catalyst.support import (CatalystError, normpath,
3754 + touch, cmd, list_bashify)
3755 +
3756 +from catalyst.base.stagebase import StageBase
3757 +
3758 +
3759 +class grp_target(StageBase):
3760 """
3761 The builder class for GRP (Gentoo Reference Platform) builds.
3762 """
3763 @@ -32,7 +39,7 @@ class grp_target(generic_stage_target):
3764 self.required_values.append("grp/"+x+"/packages")
3765 self.required_values.append("grp/"+x+"/type")
3766
3767 - generic_stage_target.__init__(self,spec,addlargs)
3768 + StageBase.__init__(self,spec,addlargs)
3769
3770 def set_target_path(self):
3771 self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
3772 @@ -62,16 +69,15 @@ class grp_target(generic_stage_target):
3773 raise CatalystError,"GRP build aborting due to error."
3774
3775 def set_use(self):
3776 - generic_stage_target.set_use(self)
3777 - if "BINDIST" in self.settings:
3778 - if "use" in self.settings:
3779 - self.settings["use"].append("bindist")
3780 - else:
3781 - self.settings["use"]=["bindist"]
3782 + StageBase.set_use(self)
3783 + if "use" in self.settings:
3784 + self.settings["use"].append("bindist")
3785 + else:
3786 + self.settings["use"]=["bindist"]
3787
3788 def set_mounts(self):
3789 - self.mounts.append("/tmp/grp")
3790 - self.mountmap["/tmp/grp"]=self.settings["target_path"]
3791 + self.mounts.append("/tmp/grp")
3792 + self.mountmap["/tmp/grp"]=self.settings["target_path"]
3793
3794 def generate_digests(self):
3795 for pkgset in self.settings["grp"]:
3796 @@ -108,7 +114,7 @@ class grp_target(generic_stage_target):
3797 self.gen_digest_file(normpath(destdir+"/"+i))
3798
3799 def set_action_sequence(self):
3800 - self.settings["action_sequence"]=["unpack","unpack_snapshot",\
3801 + self.settings["action_sequence"]=["unpack","unpack_snapshot",\
3802 "config_profile_link","setup_confdir","portage_overlay","bind","chroot_setup",\
3803 "setup_environment","run_local","unbind",\
3804 "generate_digests","clear_autoresume"]
3805 diff --git a/catalyst/targets/livecd_stage1_target.py b/catalyst/targets/livecd_stage1_target.py
3806 index 6273c9e..a19f4ac 100644
3807 --- a/catalyst/targets/livecd_stage1_target.py
3808 +++ b/catalyst/targets/livecd_stage1_target.py
3809 @@ -3,10 +3,17 @@ LiveCD stage1 target
3810 """
3811 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
3812
3813 -from catalyst.support import *
3814 -from generic_stage_target import *
3815 +import os
3816 +import types
3817 +import string
3818
3819 -class livecd_stage1_target(generic_stage_target):
3820 +from catalyst.support import (normpath,
3821 + touch, cmd)
3822 +
3823 +from catalyst.base.stagebase import StageBase
3824 +
3825 +
3826 +class livecd_stage1_target(StageBase):
3827 """
3828 Builder class for LiveCD stage1.
3829 """
3830 @@ -15,7 +22,7 @@ class livecd_stage1_target(generic_stage_target):
3831 self.valid_values=self.required_values[:]
3832
3833 self.valid_values.extend(["livecd/use"])
3834 - generic_stage_target.__init__(self,spec,addlargs)
3835 + StageBase.__init__(self,spec,addlargs)
3836
3837 def set_action_sequence(self):
3838 self.settings["action_sequence"]=["unpack","unpack_snapshot",\
3839 @@ -45,7 +52,7 @@ class livecd_stage1_target(generic_stage_target):
3840 self.settings["spec_prefix"]="livecd"
3841
3842 def set_use(self):
3843 - generic_stage_target.set_use(self)
3844 + StageBase.set_use(self)
3845 if "use" in self.settings:
3846 self.settings["use"].append("livecd")
3847 if "BINDIST" in self.settings:
3848 @@ -56,7 +63,7 @@ class livecd_stage1_target(generic_stage_target):
3849 self.settings["use"].append("bindist")
3850
3851 def set_packages(self):
3852 - generic_stage_target.set_packages(self)
3853 + StageBase.set_packages(self)
3854 if self.settings["spec_prefix"]+"/packages" in self.settings:
3855 if type(self.settings[self.settings["spec_prefix"]+"/packages"]) == types.StringType:
3856 self.settings[self.settings["spec_prefix"]+"/packages"] = \
3857 @@ -68,7 +75,7 @@ class livecd_stage1_target(generic_stage_target):
3858 if type(self.settings["pkgcache_path"]) != types.StringType:
3859 self.settings["pkgcache_path"]=normpath(string.join(self.settings["pkgcache_path"]))
3860 else:
3861 - generic_stage_target.set_pkgcache_path(self)
3862 + StageBase.set_pkgcache_path(self)
3863
3864 def register(foo):
3865 foo.update({"livecd-stage1":livecd_stage1_target})
3866 diff --git a/catalyst/targets/livecd_stage2_target.py b/catalyst/targets/livecd_stage2_target.py
3867 index 11b1219..e7ae212 100644
3868 --- a/catalyst/targets/livecd_stage2_target.py
3869 +++ b/catalyst/targets/livecd_stage2_target.py
3870 @@ -3,11 +3,14 @@ LiveCD stage2 target, builds upon previous LiveCD stage1 tarball
3871 """
3872 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
3873
3874 -import os,string,types,stat,shutil
3875 -from catalyst.support import *
3876 -from generic_stage_target import *
3877 +import os
3878
3879 -class livecd_stage2_target(generic_stage_target):
3880 +from catalyst.support import (normpath, file_locate, CatalystError, cmd,
3881 + read_from_clst, touch)
3882 +from catalyst.base.stagebase import StageBase
3883 +
3884 +
3885 +class livecd_stage2_target(StageBase):
3886 """
3887 Builder class for a LiveCD stage2 build.
3888 """
3889 @@ -26,7 +29,7 @@ class livecd_stage2_target(generic_stage_target):
3890 "livecd/fstype","livecd/fsops","livecd/linuxrc","livecd/bootargs",\
3891 "gamecd/conf","livecd/xdm","livecd/xsession","livecd/volid"])
3892
3893 - generic_stage_target.__init__(self,spec,addlargs)
3894 + StageBase.__init__(self,spec,addlargs)
3895 if "livecd/type" not in self.settings:
3896 self.settings["livecd/type"] = "generic-livecd"
3897
3898 diff --git a/catalyst/targets/netboot2_target.py b/catalyst/targets/netboot2_target.py
3899 index ea07d76..987afd8 100644
3900 --- a/catalyst/targets/netboot2_target.py
3901 +++ b/catalyst/targets/netboot2_target.py
3902 @@ -3,11 +3,18 @@ netboot target, version 2
3903 """
3904 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
3905
3906 -import os,string,types
3907 -from catalyst.support import *
3908 -from generic_stage_target import *
3909 +import os
3910 +import types
3911 +import shutil
3912 +from stat import ST_UID, ST_GID, ST_MODE
3913
3914 -class netboot2_target(generic_stage_target):
3915 +from catalyst.support import (CatalystError, normpath,
3916 + touch, cmd, list_bashify)
3917 +
3918 +from catalyst.base.stagebase import StageBase
3919 +
3920 +
3921 +class netboot2_target(StageBase):
3922 """
3923 Builder class for a netboot build, version 2
3924 """
3925 @@ -38,7 +45,7 @@ class netboot2_target(generic_stage_target):
3926 except:
3927 raise CatalystError,"configuration error in netboot2/packages."
3928
3929 - generic_stage_target.__init__(self,spec,addlargs)
3930 + StageBase.__init__(self,spec,addlargs)
3931 self.set_build_kernel_vars()
3932 self.settings["merge_path"]=normpath("/tmp/image/")
3933
3934 diff --git a/catalyst/targets/netboot_target.py b/catalyst/targets/netboot_target.py
3935 index ae1eb04..c880289 100644
3936 --- a/catalyst/targets/netboot_target.py
3937 +++ b/catalyst/targets/netboot_target.py
3938 @@ -3,11 +3,16 @@ netboot target, version 1
3939 """
3940 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
3941
3942 -import os,string,types
3943 -from catalyst.support import *
3944 -from generic_stage_target import *
3945 +import os
3946 +import types
3947
3948 -class netboot_target(generic_stage_target):
3949 +from catalyst.support import (CatalystError, normpath,
3950 + cmd, list_bashify, file_locate)
3951 +
3952 +from catalyst.base.stagebase import StageBase
3953 +
3954 +
3955 +class netboot_target(StageBase):
3956 """
3957 Builder class for a netboot build.
3958 """
3959 @@ -36,7 +41,7 @@ class netboot_target(generic_stage_target):
3960 except:
3961 raise CatalystError,"configuration error in netboot/packages."
3962
3963 - generic_stage_target.__init__(self,spec,addlargs)
3964 + StageBase.__init__(self,spec,addlargs)
3965 self.set_build_kernel_vars(addlargs)
3966 if "netboot/busybox_config" in addlargs:
3967 file_locate(self.settings, ["netboot/busybox_config"])
3968 diff --git a/catalyst/targets/snapshot_target.py b/catalyst/targets/snapshot_target.py
3969 index 3289bbd..337ff1d 100644
3970 --- a/catalyst/targets/snapshot_target.py
3971 +++ b/catalyst/targets/snapshot_target.py
3972 @@ -8,8 +8,8 @@ from stat import ST_UID, ST_GID, ST_MODE
3973
3974
3975 from catalyst.support import normpath, cmd
3976 -from catalyst.targets.targetbase import TargetBase
3977 -from catalyst.targets.genbase import GenBase
3978 +from catalyst.base.targetbase import TargetBase
3979 +from catalyst.base.genbase import GenBase
3980
3981 class snapshot_target(TargetBase, GenBase):
3982 """
3983 diff --git a/catalyst/targets/stage1_target.py b/catalyst/targets/stage1_target.py
3984 index 8d5a674..0a36432 100644
3985 --- a/catalyst/targets/stage1_target.py
3986 +++ b/catalyst/targets/stage1_target.py
3987 @@ -3,10 +3,13 @@ stage1 target
3988 """
3989 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
3990
3991 -from catalyst.support import *
3992 -from generic_stage_target import *
3993 +import os
3994
3995 -class stage1_target(generic_stage_target):
3996 +from catalyst.support import normpath, list_to_string
3997 +from catalyst.base.stagebase import StageBase
3998 +
3999 +
4000 +class stage1_target(StageBase):
4001 """
4002 Builder class for a stage1 installation tarball build.
4003 """
4004 @@ -14,7 +17,7 @@ class stage1_target(generic_stage_target):
4005 self.required_values=[]
4006 self.valid_values=["chost"]
4007 self.valid_values.extend(["update_seed","update_seed_command"])
4008 - generic_stage_target.__init__(self,spec,addlargs)
4009 + StageBase.__init__(self,spec,addlargs)
4010
4011 def set_stage_path(self):
4012 self.settings["stage_path"]=normpath(self.settings["chroot_path"]+self.settings["root_path"])
4013 @@ -26,11 +29,11 @@ class stage1_target(generic_stage_target):
4014 print "stage1 root path is "+self.settings["root_path"]
4015
4016 def set_cleanables(self):
4017 - generic_stage_target.set_cleanables(self)
4018 + StageBase.set_cleanables(self)
4019 self.settings["cleanables"].extend([\
4020 "/usr/share/zoneinfo", "/etc/portage/package*"])
4021
4022 - # XXX: How do these override_foo() functions differ from the ones in generic_stage_target and why aren't they in stage3_target?
4023 + # XXX: How do these override_foo() functions differ from the ones in StageBase and why aren't they in stage3_target?
4024
4025 def override_chost(self):
4026 if "chost" in self.settings:
4027 @@ -49,7 +52,7 @@ class stage1_target(generic_stage_target):
4028 self.settings["LDFLAGS"]=list_to_string(self.settings["ldflags"])
4029
4030 def set_portage_overlay(self):
4031 - generic_stage_target.set_portage_overlay(self)
4032 + StageBase.set_portage_overlay(self)
4033 if "portage_overlay" in self.settings:
4034 print "\nWARNING !!!!!"
4035 print "\tUsing an portage overlay for earlier stages could cause build issues."
4036 diff --git a/catalyst/targets/stage2_target.py b/catalyst/targets/stage2_target.py
4037 index 94d4a1e..783d42e 100644
4038 --- a/catalyst/targets/stage2_target.py
4039 +++ b/catalyst/targets/stage2_target.py
4040 @@ -3,17 +3,20 @@ stage2 target, builds upon previous stage1 tarball
4041 """
4042 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
4043
4044 -from catalyst.support import *
4045 -from generic_stage_target import *
4046 +import os
4047
4048 -class stage2_target(generic_stage_target):
4049 +from catalyst.support import normpath, list_to_string
4050 +from catalyst.base.stagebase import StageBase
4051 +
4052 +
4053 +class stage2_target(StageBase):
4054 """
4055 Builder class for a stage2 installation tarball build.
4056 """
4057 def __init__(self,spec,addlargs):
4058 self.required_values=[]
4059 self.valid_values=["chost"]
4060 - generic_stage_target.__init__(self,spec,addlargs)
4061 + StageBase.__init__(self,spec,addlargs)
4062
4063 def set_source_path(self):
4064 if "seedcache" in self.settings["options"] and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")):
4065 @@ -34,7 +37,7 @@ class stage2_target(generic_stage_target):
4066 print "\tthe source path will then be "+normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2\n")
4067
4068 # XXX: How do these override_foo() functions differ from the ones in
4069 - # generic_stage_target and why aren't they in stage3_target?
4070 + # StageBase and why aren't they in stage3_target?
4071
4072 def override_chost(self):
4073 if "chost" in self.settings:
4074 @@ -53,7 +56,7 @@ class stage2_target(generic_stage_target):
4075 self.settings["LDFLAGS"]=list_to_string(self.settings["ldflags"])
4076
4077 def set_portage_overlay(self):
4078 - generic_stage_target.set_portage_overlay(self)
4079 + StageBase.set_portage_overlay(self)
4080 if "portage_overlay" in self.settings:
4081 print "\nWARNING !!!!!"
4082 print "\tUsing an portage overlay for earlier stages could cause build issues."
4083 diff --git a/catalyst/targets/stage3_target.py b/catalyst/targets/stage3_target.py
4084 index 89edd66..28021b1 100644
4085 --- a/catalyst/targets/stage3_target.py
4086 +++ b/catalyst/targets/stage3_target.py
4087 @@ -3,20 +3,20 @@ stage3 target, builds upon previous stage2/stage3 tarball
4088 """
4089 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
4090
4091 -from catalyst.support import *
4092 -from generic_stage_target import *
4093 +from catalyst.base.stagebase import StageBase
4094
4095 -class stage3_target(generic_stage_target):
4096 +
4097 +class stage3_target(StageBase):
4098 """
4099 Builder class for a stage3 installation tarball build.
4100 """
4101 def __init__(self,spec,addlargs):
4102 self.required_values=[]
4103 self.valid_values=[]
4104 - generic_stage_target.__init__(self,spec,addlargs)
4105 + StageBase.__init__(self,spec,addlargs)
4106
4107 def set_portage_overlay(self):
4108 - generic_stage_target.set_portage_overlay(self)
4109 + StageBase.set_portage_overlay(self)
4110 if "portage_overlay" in self.settings:
4111 print "\nWARNING !!!!!"
4112 print "\tUsing an overlay for earlier stages could cause build issues."
4113 @@ -24,7 +24,7 @@ class stage3_target(generic_stage_target):
4114 print "\tDont say we did not warn you\n"
4115
4116 def set_cleanables(self):
4117 - generic_stage_target.set_cleanables(self)
4118 + StageBase.set_cleanables(self)
4119
4120 def register(foo):
4121 foo.update({"stage3":stage3_target})
4122 diff --git a/catalyst/targets/stage4_target.py b/catalyst/targets/stage4_target.py
4123 index e2b8a79..0d725c7 100644
4124 --- a/catalyst/targets/stage4_target.py
4125 +++ b/catalyst/targets/stage4_target.py
4126 @@ -3,10 +3,10 @@ stage4 target, builds upon previous stage3/stage4 tarball
4127 """
4128 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
4129
4130 -from catalyst.support import *
4131 -from generic_stage_target import *
4132 +from catalyst.base.stagebase import StageBase
4133
4134 -class stage4_target(generic_stage_target):
4135 +
4136 +class stage4_target(StageBase):
4137 """
4138 Builder class for stage4.
4139 """
4140 @@ -18,7 +18,7 @@ class stage4_target(generic_stage_target):
4141 "stage4/gk_mainargs","splash_theme",\
4142 "portage_overlay","stage4/rcadd","stage4/rcdel",\
4143 "stage4/linuxrc","stage4/unmerge","stage4/rm","stage4/empty"])
4144 - generic_stage_target.__init__(self,spec,addlargs)
4145 + StageBase.__init__(self,spec,addlargs)
4146
4147 def set_cleanables(self):
4148 self.settings["cleanables"]=["/var/tmp/*","/tmp/*"]
4149 diff --git a/catalyst/targets/targetbase.py b/catalyst/targets/targetbase.py
4150 deleted file mode 100644
4151 index e0c03df..0000000
4152 --- a/catalyst/targets/targetbase.py
4153 +++ /dev/null
4154 @@ -1,15 +0,0 @@
4155 -import os
4156 -
4157 -from catalyst.support import *
4158 -
4159 -class TargetBase(object):
4160 - """
4161 - The toplevel class for all targets. This is about as generic as we get.
4162 - """
4163 - def __init__(self, myspec, addlargs):
4164 - addl_arg_parse(myspec,addlargs,self.required_values,self.valid_values)
4165 - self.settings=myspec
4166 - self.env = {
4167 - 'PATH': '/bin:/sbin:/usr/bin:/usr/sbin',
4168 - 'TERM': os.getenv('TERM', 'dumb'),
4169 - }
4170 diff --git a/catalyst/targets/tinderbox_target.py b/catalyst/targets/tinderbox_target.py
4171 index ea11d3f..1e245f2 100644
4172 --- a/catalyst/targets/tinderbox_target.py
4173 +++ b/catalyst/targets/tinderbox_target.py
4174 @@ -3,10 +3,13 @@ Tinderbox target
4175 """
4176 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
4177
4178 -from catalyst.support import *
4179 -from generic_stage_target import *
4180 +import os
4181
4182 -class tinderbox_target(generic_stage_target):
4183 +from catalyst.support import cmd, list_bashify, CatalystError
4184 +from catalyst.base.stagebase import StageBase
4185 +
4186 +
4187 +class tinderbox_target(StageBase):
4188 """
4189 Builder class for the tinderbox target
4190 """
4191 @@ -14,7 +17,7 @@ class tinderbox_target(generic_stage_target):
4192 self.required_values=["tinderbox/packages"]
4193 self.valid_values=self.required_values[:]
4194 self.valid_values.extend(["tinderbox/use"])
4195 - generic_stage_target.__init__(self,spec,addlargs)
4196 + StageBase.__init__(self,spec,addlargs)
4197
4198 def run_local(self):
4199 # tinderbox
4200 --
4201 2.1.0