1 |
commit: a1c2785438593104d7c3d2ec20dd4fb25cb19884 |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jun 1 06:23:46 2013 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jan 1 05:58:07 2015 +0000 |
6 |
URL: http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=a1c27854 |
7 |
|
8 |
Create AutoResume class to handle all file creation, deletion... |
9 |
|
10 |
Create catalyst/base/resume.py. |
11 |
Migrate all auto_resume operations to using the new class. |
12 |
|
13 |
--- |
14 |
catalyst/base/clearbase.py | 21 +---- |
15 |
catalyst/base/resume.py | 166 ++++++++++++++++++++++++++++++++++++++ |
16 |
catalyst/base/stagebase.py | 156 +++++++++++++++-------------------- |
17 |
catalyst/targets/grp.py | 4 +- |
18 |
catalyst/targets/livecd_stage1.py | 4 +- |
19 |
catalyst/targets/livecd_stage2.py | 14 ++-- |
20 |
catalyst/targets/netboot2.py | 19 +++-- |
21 |
7 files changed, 250 insertions(+), 134 deletions(-) |
22 |
|
23 |
diff --git a/catalyst/base/clearbase.py b/catalyst/base/clearbase.py |
24 |
index 8462a3c..0ebe299 100644 |
25 |
--- a/catalyst/base/clearbase.py |
26 |
+++ b/catalyst/base/clearbase.py |
27 |
@@ -13,31 +13,14 @@ class ClearBase(object): |
28 |
""" |
29 |
def __init__(self, myspec): |
30 |
self.settings = myspec |
31 |
- |
32 |
+ self.resume = None |
33 |
|
34 |
|
35 |
def clear_autoresume(self): |
36 |
""" Clean resume points since they are no longer needed """ |
37 |
if "autoresume" in self.settings["options"]: |
38 |
print "Removing AutoResume Points: ..." |
39 |
- myemp=self.settings["autoresume_path"] |
40 |
- if os.path.isdir(myemp): |
41 |
- if "autoresume" in self.settings["options"]: |
42 |
- print "Emptying directory",myemp |
43 |
- """ |
44 |
- stat the dir, delete the dir, recreate the dir and set |
45 |
- the proper perms and ownership |
46 |
- """ |
47 |
- mystat=os.stat(myemp) |
48 |
- if os.uname()[0] == "FreeBSD": |
49 |
- cmd("chflags -R noschg "+myemp,\ |
50 |
- "Could not remove immutable flag for file "\ |
51 |
- +myemp) |
52 |
- #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env-self.env) |
53 |
- shutil.rmtree(myemp) |
54 |
- ensure_dirs(myemp, 0755) |
55 |
- os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) |
56 |
- os.chmod(myemp,mystat[ST_MODE]) |
57 |
+ self.resume.clear_all() |
58 |
|
59 |
|
60 |
def clear_chroot(self): |
61 |
|
62 |
diff --git a/catalyst/base/resume.py b/catalyst/base/resume.py |
63 |
new file mode 100644 |
64 |
index 0000000..e42c7dc |
65 |
--- /dev/null |
66 |
+++ b/catalyst/base/resume.py |
67 |
@@ -0,0 +1,166 @@ |
68 |
+#!/usr/bin/python |
69 |
+ |
70 |
+# Maintained in full by: |
71 |
+# Catalyst Team <catalyst@g.o> |
72 |
+# Release Engineering Team <releng@g.o> |
73 |
+# Copyright 2013 Brian Dolbec <dolsen@g.o> |
74 |
+ |
75 |
+'''resume.py |
76 |
+ |
77 |
+Performs autoresume tracking file operations such as |
78 |
+set, unset, is_set, is_unset, enabled, clear_all |
79 |
+''' |
80 |
+ |
81 |
+import os |
82 |
+import shutil |
83 |
+from stat import ST_UID, ST_GID, ST_MODE |
84 |
+import traceback |
85 |
+ |
86 |
+from catalyst.fileops import ensure_dirs, pjoin, listdir_files |
87 |
+from catalyst.support import touch |
88 |
+ |
89 |
+ |
90 |
+class AutoResumeError(Exception): |
91 |
+ def __init__(self, message, print_traceback=False): |
92 |
+ if message: |
93 |
+ if print_traceback: |
94 |
+ (type,value)=sys.exc_info()[:2] |
95 |
+ if value!=None: |
96 |
+ print |
97 |
+ print "Traceback values found. listing..." |
98 |
+ print traceback.print_exc(file=sys.stdout) |
99 |
+ print "!!! catalyst: AutoResumeError " + message |
100 |
+ print |
101 |
+ |
102 |
+ |
103 |
+class AutoResume(object): |
104 |
+ '''Class for tracking and handling all aspects of |
105 |
+ the autoresume option and related files. |
106 |
+ ''' |
107 |
+ |
108 |
+ |
109 |
+ def __init__(self, basedir, mode=0755): |
110 |
+ self.basedir = basedir |
111 |
+ ensure_dirs(basedir, mode=mode, fatal=True) |
112 |
+ self._points = {} |
113 |
+ self._init_points_() |
114 |
+ |
115 |
+ |
116 |
+ def _init_points_(self): |
117 |
+ '''Internal function which reads the autoresume directory and |
118 |
+ for existing autoresume points and adds them to our _points variable |
119 |
+ ''' |
120 |
+ existing = listdir_files(self.basedir, False) |
121 |
+ for point in existing: |
122 |
+ self._points[point] = pjoin(self.basedir, point) |
123 |
+ |
124 |
+ |
125 |
+ def enable(self, point, data=None): |
126 |
+ '''Sets the resume point 'ON' |
127 |
+ |
128 |
+ @param point: string. name of the resume point to enable |
129 |
+ @param data: string of information to store, or None |
130 |
+ @return boolean |
131 |
+ ''' |
132 |
+ if point in self._points and not data: |
133 |
+ return True |
134 |
+ fname = pjoin(self.basedir, point) |
135 |
+ if data: |
136 |
+ with open(fname,"w") as myf: |
137 |
+ myf.write(data) |
138 |
+ else: |
139 |
+ try: |
140 |
+ touch(fname) |
141 |
+ self._points[point] = fname |
142 |
+ except Exception as e: |
143 |
+ print AutoResumeError(str(e)) |
144 |
+ return False |
145 |
+ return True |
146 |
+ |
147 |
+ |
148 |
+ def get(self, point, no_lf=True): |
149 |
+ '''Gets any data stored inside a resume point |
150 |
+ |
151 |
+ @param point: string. name of the resume point to enable |
152 |
+ @return data: string of information stored, or None |
153 |
+ ''' |
154 |
+ if point in self._points: |
155 |
+ try: |
156 |
+ with open(self._points[point], 'r') as myf: |
157 |
+ data = myf.read() |
158 |
+ if data and no_lf: |
159 |
+ data = data.replace('\n', '') |
160 |
+ except OSError as e: |
161 |
+ print AutoResumeError(str(e)) |
162 |
+ return None |
163 |
+ return data |
164 |
+ return None |
165 |
+ |
166 |
+ |
167 |
+ def disable(self, point): |
168 |
+ '''Sets the resume point 'OFF' |
169 |
+ |
170 |
+ @param point: string. name of the resume point to disable |
171 |
+ @return boolean |
172 |
+ ''' |
173 |
+ if point not in self._points: |
174 |
+ return True |
175 |
+ try: |
176 |
+ os.unlink(self._points[point]) |
177 |
+ self._points.pop(point) |
178 |
+ except Exception as e: |
179 |
+ print AutoResumeError(str(e)) |
180 |
+ return False |
181 |
+ return True |
182 |
+ |
183 |
+ |
184 |
+ def is_enabled(self, point): |
185 |
+ '''Returns True if the resume point 'ON' |
186 |
+ |
187 |
+ @param point: string. name of the resume point enabled |
188 |
+ @return boolean |
189 |
+ ''' |
190 |
+ return point in self._points |
191 |
+ |
192 |
+ |
193 |
+ def is_disabled(self, point): |
194 |
+ '''Returns True if the resume point 'OFF' |
195 |
+ |
196 |
+ @param point: string. name of the resume point not enabled |
197 |
+ @return boolean |
198 |
+ ''' |
199 |
+ return point not in self._points |
200 |
+ |
201 |
+ |
202 |
+ @property |
203 |
+ def enabled(self): |
204 |
+ '''Returns a list of enabled points |
205 |
+ ''' |
206 |
+ return list(self._points) |
207 |
+ |
208 |
+ |
209 |
+ def clear_all(self): |
210 |
+ '''Clear all active resume points |
211 |
+ |
212 |
+ @return boolean |
213 |
+ ''' |
214 |
+ try: |
215 |
+ print "Emptying directory---", self.basedir |
216 |
+ """ |
217 |
+ stat the dir, delete the dir, recreate the dir and set |
218 |
+ the proper perms and ownership |
219 |
+ """ |
220 |
+ mystat=os.stat(self.basedir) |
221 |
+ if os.uname()[0] == "FreeBSD": |
222 |
+ cmd("chflags -R noschg " + self.basedir,\ |
223 |
+ "Could not remove immutable flag for file "\ |
224 |
+ + self.basedir) |
225 |
+ shutil.rmtree(self.basedir) |
226 |
+ ensure_dirs(self.basedir, 0755) |
227 |
+ os.chown(self.basedir,mystat[ST_UID],mystat[ST_GID]) |
228 |
+ os.chmod(self.basedir,mystat[ST_MODE]) |
229 |
+ self._points = {} |
230 |
+ except Exception as e: |
231 |
+ print AutoResumeError(str(e)) |
232 |
+ return False |
233 |
+ return True |
234 |
|
235 |
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py |
236 |
index 40c7362..f3cb3e3 100644 |
237 |
--- a/catalyst/base/stagebase.py |
238 |
+++ b/catalyst/base/stagebase.py |
239 |
@@ -19,6 +19,7 @@ from catalyst.base.clearbase import ClearBase |
240 |
from catalyst.base.genbase import GenBase |
241 |
from catalyst.lock import LockDir |
242 |
from catalyst.fileops import ensure_dirs, pjoin |
243 |
+from catalyst.base.resume import AutoResume |
244 |
|
245 |
|
246 |
class StageBase(TargetBase, ClearBase, GenBase): |
247 |
@@ -323,10 +324,8 @@ class StageBase(TargetBase, ClearBase, GenBase): |
248 |
def set_target_path(self): |
249 |
self.settings["target_path"]=normpath(self.settings["storedir"]+\ |
250 |
"/builds/"+self.settings["target_subpath"]+".tar.bz2") |
251 |
- setup_target_path_resume = pjoin(self.settings["autoresume_path"], |
252 |
- "setup_target_path") |
253 |
- if "autoresume" in self.settings["options"] and \ |
254 |
- os.path.exists(setup_target_path_resume): |
255 |
+ if "autoresume" in self.settings["options"]\ |
256 |
+ and self.resume.is_enabled("setup_target_path"): |
257 |
print \ |
258 |
"Resume point detected, skipping target path setup operation..." |
259 |
else: |
260 |
@@ -338,7 +337,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
261 |
# cmd("rm -f "+self.settings["target_path"],\ |
262 |
# "Could not remove existing file: "\ |
263 |
# +self.settings["target_path"],env=self.env) |
264 |
- touch(setup_target_path_resume) |
265 |
+ self.resume.enable("setup_target_path") |
266 |
|
267 |
ensure_dirs(self.settings["storedir"] + "/builds/") |
268 |
|
269 |
@@ -486,7 +485,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
270 |
)) |
271 |
if "autoresume" in self.settings["options"]: |
272 |
print "The autoresume path is " + self.settings["autoresume_path"] |
273 |
- ensure_dirs(self.settings["autoresume_path"], mode=0755) |
274 |
+ self.resume = AutoResume(self.settings["autoresume_path"], mode=0755) |
275 |
|
276 |
def set_controller_file(self): |
277 |
self.settings["controller_file"]=normpath(self.settings["sharedir"]+\ |
278 |
@@ -667,8 +666,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
279 |
def unpack(self): |
280 |
unpack=True |
281 |
|
282 |
- unpack_resume = pjoin(self.settings["autoresume_path"], "unpack") |
283 |
- clst_unpack_hash=read_from_clst(unpack_resume) |
284 |
+ clst_unpack_hash = self.resume.get("unpack") |
285 |
|
286 |
if "seedcache" in self.settings["options"]: |
287 |
if os.path.isdir(self.settings["source_path"]): |
288 |
@@ -714,7 +712,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
289 |
|
290 |
if "autoresume" in self.settings["options"]: |
291 |
if os.path.isdir(self.settings["source_path"]) \ |
292 |
- and os.path.exists(unpack_resume): |
293 |
+ and self.resume.is_enabled("unpack"): |
294 |
""" Autoresume is valid, SEEDCACHE is valid """ |
295 |
unpack=False |
296 |
invalid_snapshot=False |
297 |
@@ -726,7 +724,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
298 |
invalid_snapshot=True |
299 |
|
300 |
elif os.path.isdir(self.settings["source_path"]) \ |
301 |
- and not os.path.exists(unpack_resume): |
302 |
+ and self.resume.is_disabled("unpack"): |
303 |
""" Autoresume is invalid, SEEDCACHE """ |
304 |
unpack=True |
305 |
invalid_snapshot=False |
306 |
@@ -782,19 +780,16 @@ class StageBase(TargetBase, ClearBase, GenBase): |
307 |
cmd(unpack_cmd,error_msg,env=self.env) |
308 |
|
309 |
if "source_path_hash" in self.settings: |
310 |
- myf=open(unpack_resume,"w") |
311 |
- myf.write(self.settings["source_path_hash"]) |
312 |
- myf.close() |
313 |
+ self.resume.enable("unpack", |
314 |
+ data=self.settings["source_path_hash"]) |
315 |
else: |
316 |
- touch(unpack_resume) |
317 |
+ self.resume.enable("unpack") |
318 |
else: |
319 |
print "Resume point detected, skipping unpack operation..." |
320 |
|
321 |
def unpack_snapshot(self): |
322 |
unpack=True |
323 |
- unpack_portage_resume = pjoin(self.settings["autoresume_path"], |
324 |
- "unpack_portage") |
325 |
- snapshot_hash=read_from_clst(unpack_portage_resume) |
326 |
+ snapshot_hash = self.resume.get("unpack_portage") |
327 |
|
328 |
if "snapcache" in self.settings["options"]: |
329 |
snapshot_cache_hash=\ |
330 |
@@ -831,7 +826,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
331 |
if "autoresume" in self.settings["options"] \ |
332 |
and os.path.exists(self.settings["chroot_path"]+\ |
333 |
self.settings["portdir"]) \ |
334 |
- and os.path.exists(unpack_portage_resume) \ |
335 |
+ and self.resume.is_enabled("unpack_portage") \ |
336 |
and self.settings["snapshot_path_hash"] == snapshot_hash: |
337 |
print \ |
338 |
"Valid Resume point detected, skipping unpack of portage tree..." |
339 |
@@ -856,18 +851,15 @@ class StageBase(TargetBase, ClearBase, GenBase): |
340 |
myf.close() |
341 |
else: |
342 |
print "Setting snapshot autoresume point" |
343 |
- myf=open(unpack_portage_resume,"w") |
344 |
- myf.write(self.settings["snapshot_path_hash"]) |
345 |
- myf.close() |
346 |
+ self.resume.enable("unpack_portage", |
347 |
+ data=self.settings["snapshot_path_hash"]) |
348 |
|
349 |
if "snapcache" in self.settings["options"]: |
350 |
self.snapshot_lock_object.unlock() |
351 |
|
352 |
def config_profile_link(self): |
353 |
- config_protect_link_resume = pjoin(self.settings["autoresume_path"], |
354 |
- "config_profile_link") |
355 |
if "autoresume" in self.settings["options"] \ |
356 |
- and os.path.exists(config_protect_link_resume): |
357 |
+ and self.resume.is_enabled("config_profile_link"): |
358 |
print \ |
359 |
"Resume point detected, skipping config_profile_link operation..." |
360 |
else: |
361 |
@@ -881,21 +873,20 @@ class StageBase(TargetBase, ClearBase, GenBase): |
362 |
self.settings["target_profile"]+" "+\ |
363 |
self.settings["chroot_path"]+"/etc/portage/make.profile",\ |
364 |
"Error creating profile link",env=self.env) |
365 |
- touch(config_protect_link_resume) |
366 |
+ self.resume.enable("config_profile_link") |
367 |
|
368 |
def setup_confdir(self): |
369 |
- setup_confdir_resume = pjoin(self.settings["autoresume_path"], |
370 |
- "setup_confdir") |
371 |
if "autoresume" in self.settings["options"] \ |
372 |
- and os.path.exists(setup_confdir_resume): |
373 |
+ and self.resume.is_enabled("setup_confdir"): |
374 |
print "Resume point detected, skipping setup_confdir operation..." |
375 |
else: |
376 |
if "portage_confdir" in self.settings: |
377 |
- print "Configuring /etc/portage..." |
378 |
- cmd("rsync -a "+self.settings["portage_confdir"]+"/ "+\ |
379 |
- self.settings["chroot_path"]+"/etc/portage/",\ |
380 |
- "Error copying /etc/portage",env=self.env) |
381 |
- touch(setup_confdir_resume) |
382 |
+ print "Configuring %s..." % self.settings["port_conf"] |
383 |
+ cmd("rsync -a " + self.settings["portage_confdir"] + "/ " + |
384 |
+ self.settings["chroot_path"] + self.settings["port_conf"], |
385 |
+ "Error copying %s" % self.settings["port_conf"], |
386 |
+ env=self.env) |
387 |
+ self.resume.enable("setup_confdir") |
388 |
|
389 |
def portage_overlay(self): |
390 |
""" We copy the contents of our overlays to /usr/local/portage """ |
391 |
@@ -1018,10 +1009,8 @@ class StageBase(TargetBase, ClearBase, GenBase): |
392 |
self.override_cflags() |
393 |
self.override_cxxflags() |
394 |
self.override_ldflags() |
395 |
- chroot_setup_resume = pjoin(self.settings["autoresume_path"], |
396 |
- "chroot_setup") |
397 |
if "autoresume" in self.settings["options"] \ |
398 |
- and os.path.exists(chroot_setup_resume): |
399 |
+ and self.resume.is_enabled("chroot_setup"): |
400 |
print "Resume point detected, skipping chroot_setup operation..." |
401 |
else: |
402 |
print "Setting up chroot..." |
403 |
@@ -1118,35 +1107,32 @@ class StageBase(TargetBase, ClearBase, GenBase): |
404 |
self.settings["make_conf"]) |
405 |
cmd("cp " + makepath + " " + makepath + ".catalyst",\ |
406 |
"Could not backup " + self.settings["make_conf"],env=self.env) |
407 |
- touch(self.settings["autoresume_path"]+"chroot_setup") |
408 |
+ self.resume.enable("chroot_setup") |
409 |
|
410 |
def fsscript(self): |
411 |
- fsscript_resume = pjoin(self.settings["autoresume_path"], "fsscript") |
412 |
if "autoresume" in self.settings["options"] \ |
413 |
- and os.path.exists(fsscript_resume): |
414 |
+ and self.resume.is_enabled("fsscript"): |
415 |
print "Resume point detected, skipping fsscript operation..." |
416 |
else: |
417 |
if "fsscript" in self.settings: |
418 |
if os.path.exists(self.settings["controller_file"]): |
419 |
cmd(self.settings["controller_file"]+\ |
420 |
" fsscript","fsscript script failed.",env=self.env) |
421 |
- touch(fsscript_resume) |
422 |
+ self.resume.enable("fsscript") |
423 |
|
424 |
def rcupdate(self): |
425 |
- rcupdate_resume = pjoin(self.settings["autoresume_path"], "rcupdate") |
426 |
if "autoresume" in self.settings["options"] \ |
427 |
- and os.path.exists(rcupdate_resume): |
428 |
+ and self.resume.is_enabled("rcupdate"): |
429 |
print "Resume point detected, skipping rcupdate operation..." |
430 |
else: |
431 |
if os.path.exists(self.settings["controller_file"]): |
432 |
cmd(self.settings["controller_file"]+" rc-update",\ |
433 |
"rc-update script failed.",env=self.env) |
434 |
- touch(rcupdate_resume) |
435 |
+ self.resume.enable("rcupdate") |
436 |
|
437 |
def clean(self): |
438 |
- clean_resume = pjoin(self.settings["autoresume_path"], "clean") |
439 |
if "autoresume" in self.settings["options"] \ |
440 |
- and os.path.exists(clean_resume): |
441 |
+ and self.resume.is_enabled("clean"): |
442 |
print "Resume point detected, skipping clean operation..." |
443 |
else: |
444 |
for x in self.settings["cleanables"]: |
445 |
@@ -1177,12 +1163,11 @@ class StageBase(TargetBase, ClearBase, GenBase): |
446 |
if os.path.exists(self.settings["controller_file"]): |
447 |
cmd(self.settings["controller_file"]+" clean",\ |
448 |
"clean script failed.",env=self.env) |
449 |
- touch(clean_resume) |
450 |
+ self.resume.enable("clean") |
451 |
|
452 |
def empty(self): |
453 |
- empty_resume = pjoin(self.settings["autoresume_path"], "empty") |
454 |
if "autoresume" in self.settings["options"] \ |
455 |
- and os.path.exists(empty_resume): |
456 |
+ and self.resume.is_enabled("empty"): |
457 |
print "Resume point detected, skipping empty operation..." |
458 |
else: |
459 |
if self.settings["spec_prefix"]+"/empty" in self.settings: |
460 |
@@ -1206,12 +1191,11 @@ class StageBase(TargetBase, ClearBase, GenBase): |
461 |
ensure_dirs(myemp, mode=0755) |
462 |
os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) |
463 |
os.chmod(myemp,mystat[ST_MODE]) |
464 |
- touch(empty_resume) |
465 |
+ self.resume.enable("empty") |
466 |
|
467 |
def remove(self): |
468 |
- remove_resume = pjoin(self.settings["autoresume_path"], "remove") |
469 |
if "autoresume" in self.settings["options"] \ |
470 |
- and os.path.exists(remove_resume): |
471 |
+ and self.resume.is_enabled("remove"): |
472 |
print "Resume point detected, skipping remove operation..." |
473 |
else: |
474 |
if self.settings["spec_prefix"]+"/rm" in self.settings: |
475 |
@@ -1226,31 +1210,29 @@ class StageBase(TargetBase, ClearBase, GenBase): |
476 |
if os.path.exists(self.settings["controller_file"]): |
477 |
cmd(self.settings["controller_file"]+\ |
478 |
" clean","Clean failed.",env=self.env) |
479 |
- touch(remove_resume) |
480 |
+ self.resume.enable("remove") |
481 |
except: |
482 |
self.unbind() |
483 |
raise |
484 |
|
485 |
def preclean(self): |
486 |
- preclean_resume = pjoin(self.settings["autoresume_path"], "preclean") |
487 |
if "autoresume" in self.settings["options"] \ |
488 |
- and os.path.exists(preclean_resume): |
489 |
+ and self.resume.is_enabled("preclean"): |
490 |
print "Resume point detected, skipping preclean operation..." |
491 |
else: |
492 |
try: |
493 |
if os.path.exists(self.settings["controller_file"]): |
494 |
cmd(self.settings["controller_file"]+\ |
495 |
" preclean","preclean script failed.",env=self.env) |
496 |
- touch(preclean_resume) |
497 |
+ self.resume.enable("preclean") |
498 |
|
499 |
except: |
500 |
self.unbind() |
501 |
raise CatalystError("Build failed, could not execute preclean") |
502 |
|
503 |
def capture(self): |
504 |
- capture_resume = pjoin(self.settings["autoresume_path"], "capture") |
505 |
if "autoresume" in self.settings["options"] \ |
506 |
- and os.path.exists(capture_resume): |
507 |
+ and self.resume.is_enabled("capture"): |
508 |
print "Resume point detected, skipping capture operation..." |
509 |
else: |
510 |
""" Capture target in a tarball """ |
511 |
@@ -1270,12 +1252,11 @@ class StageBase(TargetBase, ClearBase, GenBase): |
512 |
self.gen_contents_file(self.settings["target_path"]) |
513 |
self.gen_digest_file(self.settings["target_path"]) |
514 |
|
515 |
- touch(capture_resume) |
516 |
+ self.resume.enable("capture") |
517 |
|
518 |
def run_local(self): |
519 |
- run_local_resume = pjoin(self.settings["autoresume_path"], "run_local") |
520 |
if "autoresume" in self.settings["options"] \ |
521 |
- and os.path.exists(run_local_resume): |
522 |
+ and self.resume.is_enabled("run_local"): |
523 |
print "Resume point detected, skipping run_local operation..." |
524 |
else: |
525 |
try: |
526 |
@@ -1283,7 +1264,9 @@ class StageBase(TargetBase, ClearBase, GenBase): |
527 |
print "run_local() starting controller script..." |
528 |
cmd(self.settings["controller_file"]+" run",\ |
529 |
"run script failed.",env=self.env) |
530 |
- touch(run_local_resume) |
531 |
+ self.resume.enable("run_local") |
532 |
+ else: |
533 |
+ print "run_local() no controller_file found...", self.settings["controller_file"] |
534 |
|
535 |
except CatalystError: |
536 |
self.unbind() |
537 |
@@ -1359,9 +1342,8 @@ class StageBase(TargetBase, ClearBase, GenBase): |
538 |
self.chroot_lock.unlock() |
539 |
|
540 |
def unmerge(self): |
541 |
- unmerge_resume = pjoin(self.settings["autoresume_path"], "unmerge") |
542 |
if "autoresume" in self.settings["options"] \ |
543 |
- and os.path.exists(unmerge_resume): |
544 |
+ and self.resume.is_enabled("unmerge"): |
545 |
print "Resume point detected, skipping unmerge operation..." |
546 |
else: |
547 |
if self.settings["spec_prefix"]+"/unmerge" in self.settings: |
548 |
@@ -1389,26 +1371,22 @@ class StageBase(TargetBase, ClearBase, GenBase): |
549 |
except CatalystError: |
550 |
self.unbind() |
551 |
raise |
552 |
- touch(unmerge_resume) |
553 |
+ self.resume.enable("unmerge") |
554 |
|
555 |
def target_setup(self): |
556 |
- target_setup_resume = pjoin(self.settings["autoresume_path"], |
557 |
- "target_setup") |
558 |
if "autoresume" in self.settings["options"] \ |
559 |
- and os.path.exists(target_setup_resume): |
560 |
+ and self.resume.is_enabled("target_setup"): |
561 |
print "Resume point detected, skipping target_setup operation..." |
562 |
else: |
563 |
print "Setting up filesystems per filesystem type" |
564 |
cmd(self.settings["controller_file"]+\ |
565 |
" target_image_setup "+ self.settings["target_path"],\ |
566 |
"target_image_setup script failed.",env=self.env) |
567 |
- touch(target_setup_resume) |
568 |
+ self.resume.enable("target_setup") |
569 |
|
570 |
def setup_overlay(self): |
571 |
- setup_overlay_resume = pjoin(self.settings["autoresume_path"], |
572 |
- "setup_overlay") |
573 |
if "autoresume" in self.settings["options"] \ |
574 |
- and os.path.exists(setup_overlay_resume): |
575 |
+ and self.resume.is_enabled("setup_overlay"): |
576 |
print "Resume point detected, skipping setup_overlay operation..." |
577 |
else: |
578 |
if self.settings["spec_prefix"]+"/overlay" in self.settings: |
579 |
@@ -1418,12 +1396,11 @@ class StageBase(TargetBase, ClearBase, GenBase): |
580 |
self.settings["target_path"],\ |
581 |
self.settings["spec_prefix"]+"overlay: "+x+\ |
582 |
" copy failed.",env=self.env) |
583 |
- touch(setup_overlay_resume) |
584 |
+ self.resume.enable("setup_overlay") |
585 |
|
586 |
def create_iso(self): |
587 |
- create_iso_resume = pjoin(self.settings["autoresume_path"], "create_iso") |
588 |
if "autoresume" in self.settings["options"] \ |
589 |
- and os.path.exists(create_iso_resume): |
590 |
+ and self.resume.is_enabled("create_iso"): |
591 |
print "Resume point detected, skipping create_iso operation..." |
592 |
else: |
593 |
""" Create the ISO """ |
594 |
@@ -1433,7 +1410,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
595 |
env=self.env) |
596 |
self.gen_contents_file(self.settings["iso"]) |
597 |
self.gen_digest_file(self.settings["iso"]) |
598 |
- touch(create_iso_resume) |
599 |
+ self.resume.enable("create_iso") |
600 |
else: |
601 |
print "WARNING: livecd/iso was not defined." |
602 |
print "An ISO Image will not be created." |
603 |
@@ -1442,13 +1419,12 @@ class StageBase(TargetBase, ClearBase, GenBase): |
604 |
build_packages_resume = pjoin(self.settings["autoresume_path"], |
605 |
"build_packages") |
606 |
if "autoresume" in self.settings["options"] \ |
607 |
- and os.path.exists(build_packages_resume): |
608 |
+ and self.resume.is_enabled("build_packages"): |
609 |
print "Resume point detected, skipping build_packages operation..." |
610 |
else: |
611 |
if self.settings["spec_prefix"]+"/packages" in self.settings: |
612 |
if "autoresume" in self.settings["options"] \ |
613 |
- and os.path.exists(self.settings["autoresume_path"]+\ |
614 |
- "build_packages"): |
615 |
+ and self.resume.is_enabled("build_packages"): |
616 |
print "Resume point detected, skipping build_packages operation..." |
617 |
else: |
618 |
mypack=\ |
619 |
@@ -1459,6 +1435,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
620 |
" build_packages "+mypack,\ |
621 |
"Error in attempt to build packages",env=self.env) |
622 |
touch(build_packages_resume) |
623 |
+ self.resume.enable("build_packages") |
624 |
except CatalystError: |
625 |
self.unbind() |
626 |
raise CatalystError(self.settings["spec_prefix"]+\ |
627 |
@@ -1466,10 +1443,8 @@ class StageBase(TargetBase, ClearBase, GenBase): |
628 |
|
629 |
def build_kernel(self): |
630 |
'''Build all configured kernels''' |
631 |
- build_kernel_resume = pjoin(self.settings["autoresume_path"], |
632 |
- "build_kernel") |
633 |
if "autoresume" in self.settings["options"] \ |
634 |
- and os.path.exists(build_kernel_resume): |
635 |
+ and self.resume.is_enabled("build_kernel"): |
636 |
print "Resume point detected, skipping build_kernel operation..." |
637 |
else: |
638 |
if "boot/kernel" in self.settings: |
639 |
@@ -1485,7 +1460,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
640 |
env=self.env) |
641 |
for kname in mynames: |
642 |
self._build_kernel(kname=kname) |
643 |
- touch(build_kernel_resume) |
644 |
+ self.resume.enable("build_kernel") |
645 |
except CatalystError: |
646 |
self.unbind() |
647 |
raise CatalystError( |
648 |
@@ -1494,10 +1469,8 @@ class StageBase(TargetBase, ClearBase, GenBase): |
649 |
|
650 |
def _build_kernel(self, kname): |
651 |
"Build a single configured kernel by name" |
652 |
- kname_resume = pjoin(self.settings["autoresume_path"], |
653 |
- "build_kernel_" + kname) |
654 |
if "autoresume" in self.settings["options"] \ |
655 |
- and os.path.exists(kname_resume): |
656 |
+ and self.resume.is_enabled("build_kernel_"+kname): |
657 |
print "Resume point detected, skipping build_kernel for "+kname+" operation..." |
658 |
return |
659 |
self._copy_kernel_config(kname=kname) |
660 |
@@ -1539,7 +1512,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
661 |
cmd("rm -R "+self.settings["chroot_path"]+\ |
662 |
"/tmp/initramfs_overlay/",env=self.env) |
663 |
|
664 |
- touch(kname_resume) |
665 |
+ self.resume.is_enabled("build_kernel_"+kname) |
666 |
|
667 |
""" |
668 |
Execute the script that cleans up the kernel build |
669 |
@@ -1592,31 +1565,28 @@ class StageBase(TargetBase, ClearBase, GenBase): |
670 |
"/initramfs_overlay"],env=self.env) |
671 |
|
672 |
def bootloader(self): |
673 |
- bootloader_resume = pjoin(self.settings["autoresume_path"], "bootloader") |
674 |
if "autoresume" in self.settings["options"] \ |
675 |
- and os.path.exists(bootloader_resume): |
676 |
+ and self.resume.is_enabled("bootloader"): |
677 |
print "Resume point detected, skipping bootloader operation..." |
678 |
else: |
679 |
try: |
680 |
cmd(self.settings["controller_file"]+\ |
681 |
" bootloader " + self.settings["target_path"],\ |
682 |
"Bootloader script failed.",env=self.env) |
683 |
- touch(bootloader_resume) |
684 |
+ self.resume.enable("bootloader") |
685 |
except CatalystError: |
686 |
self.unbind() |
687 |
raise CatalystError("Script aborting due to error.") |
688 |
|
689 |
def livecd_update(self): |
690 |
- livecd_update_resume = pjoin(self.settings["autoresume_path"], |
691 |
- "livecd_update") |
692 |
if "autoresume" in self.settings["options"] \ |
693 |
- and os.path.exists(livecd_update_resume): |
694 |
+ and self.resume.is_enabled("livecd_update"): |
695 |
print "Resume point detected, skipping build_packages operation..." |
696 |
else: |
697 |
try: |
698 |
cmd(self.settings["controller_file"]+\ |
699 |
" livecd-update","livecd-update failed.",env=self.env) |
700 |
- touch(livecd_update_resume) |
701 |
+ self.resume.enable("livecd_update") |
702 |
|
703 |
except CatalystError: |
704 |
self.unbind() |
705 |
|
706 |
diff --git a/catalyst/targets/grp.py b/catalyst/targets/grp.py |
707 |
index a17f9bd..14cffe0 100644 |
708 |
--- a/catalyst/targets/grp.py |
709 |
+++ b/catalyst/targets/grp.py |
710 |
@@ -44,7 +44,7 @@ class grp(StageBase): |
711 |
def set_target_path(self): |
712 |
self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/") |
713 |
if "autoresume" in self.settings["options"] \ |
714 |
- and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): |
715 |
+ and self.resume.is_enabled("setup_target_path"): |
716 |
print "Resume point detected, skipping target path setup operation..." |
717 |
else: |
718 |
# first clean up any existing target stuff |
719 |
@@ -53,7 +53,7 @@ class grp(StageBase): |
720 |
#"Could not remove existing directory: "+self.settings["target_path"],env=self.env) |
721 |
ensure_dirs(self.settings["target_path"]) |
722 |
|
723 |
- touch(self.settings["autoresume_path"]+"setup_target_path") |
724 |
+ self.resume.enable("setup_target_path") |
725 |
|
726 |
def run_local(self): |
727 |
for pkgset in self.settings["grp"]: |
728 |
|
729 |
diff --git a/catalyst/targets/livecd_stage1.py b/catalyst/targets/livecd_stage1.py |
730 |
index 668960b..55859bc 100644 |
731 |
--- a/catalyst/targets/livecd_stage1.py |
732 |
+++ b/catalyst/targets/livecd_stage1.py |
733 |
@@ -35,14 +35,14 @@ class livecd_stage1(StageBase): |
734 |
def set_target_path(self): |
735 |
self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]) |
736 |
if "autoresume" in self.settings["options"] \ |
737 |
- and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): |
738 |
+ and self.resume.is_enabled("setup_target_path"): |
739 |
print "Resume point detected, skipping target path setup operation..." |
740 |
else: |
741 |
# first clean up any existing target stuff |
742 |
if os.path.exists(self.settings["target_path"]): |
743 |
cmd("rm -rf "+self.settings["target_path"],\ |
744 |
"Could not remove existing directory: "+self.settings["target_path"],env=self.env) |
745 |
- touch(self.settings["autoresume_path"]+"setup_target_path") |
746 |
+ self.resume.enable("setup_target_path") |
747 |
|
748 |
ensure_dirs(self.settings["target_path"]) |
749 |
|
750 |
|
751 |
diff --git a/catalyst/targets/livecd_stage2.py b/catalyst/targets/livecd_stage2.py |
752 |
index 94da670..973a734 100644 |
753 |
--- a/catalyst/targets/livecd_stage2.py |
754 |
+++ b/catalyst/targets/livecd_stage2.py |
755 |
@@ -55,14 +55,14 @@ class livecd_stage2(StageBase): |
756 |
def set_target_path(self): |
757 |
self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/") |
758 |
if "autoresume" in self.settings["options"] \ |
759 |
- and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): |
760 |
+ and self.resume.is_enabled("setup_target_path"): |
761 |
print "Resume point detected, skipping target path setup operation..." |
762 |
else: |
763 |
# first clean up any existing target stuff |
764 |
if os.path.isdir(self.settings["target_path"]): |
765 |
cmd("rm -rf "+self.settings["target_path"], |
766 |
"Could not remove existing directory: "+self.settings["target_path"],env=self.env) |
767 |
- touch(self.settings["autoresume_path"]+"setup_target_path") |
768 |
+ self.resume.enable("setup_target_path") |
769 |
ensure_dirs(self.settings["target_path"]) |
770 |
|
771 |
def run_local(self): |
772 |
@@ -89,7 +89,7 @@ class livecd_stage2(StageBase): |
773 |
unpack=True |
774 |
display_msg=None |
775 |
|
776 |
- clst_unpack_hash=read_from_clst(self.settings["autoresume_path"]+"unpack") |
777 |
+ clst_unpack_hash = self.resume.get("unpack") |
778 |
|
779 |
if os.path.isdir(self.settings["source_path"]): |
780 |
unpack_cmd="rsync -a --delete "+self.settings["source_path"]+" "+self.settings["chroot_path"] |
781 |
@@ -100,7 +100,7 @@ class livecd_stage2(StageBase): |
782 |
|
783 |
if "autoresume" in self.settings["options"]: |
784 |
if os.path.isdir(self.settings["source_path"]) and \ |
785 |
- os.path.exists(self.settings["autoresume_path"]+"unpack"): |
786 |
+ self.resume.is_enabled("unpack"): |
787 |
print "Resume point detected, skipping unpack operation..." |
788 |
unpack=False |
789 |
elif "source_path_hash" in self.settings: |
790 |
@@ -131,11 +131,9 @@ class livecd_stage2(StageBase): |
791 |
cmd(unpack_cmd,error_msg,env=self.env) |
792 |
|
793 |
if "source_path_hash" in self.settings: |
794 |
- myf=open(self.settings["autoresume_path"]+"unpack","w") |
795 |
- myf.write(self.settings["source_path_hash"]) |
796 |
- myf.close() |
797 |
+ self.resume.enable("unpack", data=self.settings["source_path_hash"]) |
798 |
else: |
799 |
- touch(self.settings["autoresume_path"]+"unpack") |
800 |
+ self.resume.enable("unpack") |
801 |
|
802 |
def set_action_sequence(self): |
803 |
self.settings["action_sequence"]=["unpack","unpack_snapshot",\ |
804 |
|
805 |
diff --git a/catalyst/targets/netboot2.py b/catalyst/targets/netboot2.py |
806 |
index 7edfc1f..acffb05 100644 |
807 |
--- a/catalyst/targets/netboot2.py |
808 |
+++ b/catalyst/targets/netboot2.py |
809 |
@@ -54,15 +54,14 @@ class netboot2(StageBase): |
810 |
self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+\ |
811 |
self.settings["target_subpath"]+"/") |
812 |
if "autoresume" in self.settings["options"] \ |
813 |
- and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): |
814 |
+ and self.resume.is_enabled("setup_target_path"): |
815 |
print "Resume point detected, skipping target path setup operation..." |
816 |
else: |
817 |
# first clean up any existing target stuff |
818 |
if os.path.isfile(self.settings["target_path"]): |
819 |
cmd("rm -f "+self.settings["target_path"], \ |
820 |
"Could not remove existing file: "+self.settings["target_path"],env=self.env) |
821 |
- touch(self.settings["autoresume_path"]+"setup_target_path") |
822 |
- |
823 |
+ self.resume.enable("setup_target_path") |
824 |
ensure_dirs(self.settings["storedir"]+"/builds/") |
825 |
|
826 |
def copy_files_to_image(self): |
827 |
@@ -71,7 +70,7 @@ class netboot2(StageBase): |
828 |
|
829 |
# check for autoresume point |
830 |
if "autoresume" in self.settings["options"] \ |
831 |
- and os.path.exists(self.settings["autoresume_path"]+"copy_files_to_image"): |
832 |
+ and self.resume.is_enabled("copy_files_to_image"): |
833 |
print "Resume point detected, skipping target path setup operation..." |
834 |
else: |
835 |
if "netboot2/packages" in self.settings: |
836 |
@@ -101,11 +100,11 @@ class netboot2(StageBase): |
837 |
raise CatalystError("Failed to copy files to image!", |
838 |
print_traceback=True) |
839 |
|
840 |
- touch(self.settings["autoresume_path"]+"copy_files_to_image") |
841 |
+ self.resume.enable("copy_files_to_image") |
842 |
|
843 |
def setup_overlay(self): |
844 |
if "autoresume" in self.settings["options"] \ |
845 |
- and os.path.exists(self.settings["autoresume_path"]+"setup_overlay"): |
846 |
+ and self.resume.is_enabled("setup_overlay"): |
847 |
print "Resume point detected, skipping setup_overlay operation..." |
848 |
else: |
849 |
if "netboot2/overlay" in self.settings: |
850 |
@@ -113,7 +112,7 @@ class netboot2(StageBase): |
851 |
if os.path.exists(x): |
852 |
cmd("rsync -a "+x+"/ "+\ |
853 |
self.settings["chroot_path"] + self.settings["merge_path"], "netboot2/overlay: "+x+" copy failed.",env=self.env) |
854 |
- touch(self.settings["autoresume_path"]+"setup_overlay") |
855 |
+ self.resume.enable("setup_overlay") |
856 |
|
857 |
def move_kernels(self): |
858 |
# we're done, move the kernels to builds/* |
859 |
@@ -130,7 +129,7 @@ class netboot2(StageBase): |
860 |
|
861 |
def remove(self): |
862 |
if "autoresume" in self.settings["options"] \ |
863 |
- and os.path.exists(self.settings["autoresume_path"]+"remove"): |
864 |
+ and self.resume.is_enabled("remove"): |
865 |
print "Resume point detected, skipping remove operation..." |
866 |
else: |
867 |
if self.settings["spec_prefix"]+"/rm" in self.settings: |
868 |
@@ -142,7 +141,7 @@ class netboot2(StageBase): |
869 |
|
870 |
def empty(self): |
871 |
if "autoresume" in self.settings["options"] \ |
872 |
- and os.path.exists(self.settings["autoresume_path"]+"empty"): |
873 |
+ and self.resume.is_enabled("empty"): |
874 |
print "Resume point detected, skipping empty operation..." |
875 |
else: |
876 |
if "netboot2/empty" in self.settings: |
877 |
@@ -161,7 +160,7 @@ class netboot2(StageBase): |
878 |
ensure_dirs(myemp, mode=0755) |
879 |
os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) |
880 |
os.chmod(myemp,mystat[ST_MODE]) |
881 |
- touch(self.settings["autoresume_path"]+"empty") |
882 |
+ self.resume.enable("empty") |
883 |
|
884 |
def set_action_sequence(self): |
885 |
self.settings["action_sequence"]=["unpack","unpack_snapshot","config_profile_link", |