Gentoo Archives: gentoo-catalyst

From: Brian Dolbec <dolsen@g.o>
To: gentoo-catalyst@l.g.o
Subject: [gentoo-catalyst] [PATCH] Fix autoresume file paths to only be configured once.
Date: Sun, 02 Mar 2014 23:05:44
Message-Id: 1393801535-13921-1-git-send-email-dolsen@gentoo.org
1 Use: pjoin as a shorter alias to os.path.join()
2 ---
3 catalyst/targets/generic_stage_target.py | 175 +++++++++++++++++--------------
4 1 file changed, 95 insertions(+), 80 deletions(-)
5
6 diff --git a/catalyst/targets/generic_stage_target.py b/catalyst/targets/generic_stage_target.py
7 index 2b3d7ce..095327a 100644
8 --- a/catalyst/targets/generic_stage_target.py
9 +++ b/catalyst/targets/generic_stage_target.py
10 @@ -33,6 +33,9 @@ SOURCE_MOUNTS_DEFAULTS = {
11 "shm": "shmfs",
12 }
13
14 +# for convienience
15 +pjoin = os.path.join
16 +
17
18 class generic_stage_target(generic_target):
19 """
20 @@ -334,9 +337,10 @@ class generic_stage_target(generic_target):
21 def set_target_path(self):
22 self.settings["target_path"]=normpath(self.settings["storedir"]+\
23 "/builds/"+self.settings["target_subpath"]+".tar.bz2")
24 - if "AUTORESUME" in self.settings\
25 - and os.path.exists(self.settings["autoresume_path"]+\
26 - "setup_target_path"):
27 + setup_target_path_resume = pjoin(self.settings["autoresume_path"],
28 + "setup_target_path")
29 + if "AUTORESUME" in self.settings and \
30 + os.path.exists(setup_target_path_resume):
31 print \
32 "Resume point detected, skipping target path setup operation..."
33 else:
34 @@ -348,7 +352,7 @@ class generic_stage_target(generic_target):
35 # cmd("rm -f "+self.settings["target_path"],\
36 # "Could not remove existing file: "\
37 # +self.settings["target_path"],env=self.env)
38 - touch(self.settings["autoresume_path"]+"setup_target_path")
39 + touch(setup_target_path_resume)
40
41 if not os.path.exists(self.settings["storedir"]+"/builds/"):
42 os.makedirs(self.settings["storedir"]+"/builds/")
43 @@ -484,10 +488,12 @@ class generic_stage_target(generic_target):
44 self.chroot_lock=LockDir(self.settings["chroot_path"])
45
46 def set_autoresume_path(self):
47 - self.settings["autoresume_path"]=normpath(self.settings["storedir"]+\
48 - "/tmp/"+self.settings["rel_type"]+"/"+".autoresume-"+\
49 - self.settings["target"]+"-"+self.settings["subarch"]+"-"+\
50 - self.settings["version_stamp"]+"/")
51 + self.settings["autoresume_path"] = normpath(pjoin(
52 + self.settings["storedir"], "tmp", self.settings["rel_type"],
53 + ".autoresume-%s-%s-%s"
54 + %(self.settings["target"], self.settings["subarch"],
55 + self.settings["version_stamp"])
56 + ))
57 if "AUTORESUME" in self.settings:
58 print "The autoresume path is " + self.settings["autoresume_path"]
59 if not os.path.exists(self.settings["autoresume_path"]):
60 @@ -673,8 +679,8 @@ class generic_stage_target(generic_target):
61 def unpack(self):
62 unpack=True
63
64 - clst_unpack_hash=read_from_clst(self.settings["autoresume_path"]+\
65 - "unpack")
66 + unpack_resume = pjoin(self.settings["autoresume_path"], "unpack")
67 + clst_unpack_hash=read_from_clst(unpack_resume)
68
69 if "SEEDCACHE" in self.settings:
70 if os.path.isdir(self.settings["source_path"]):
71 @@ -720,7 +726,7 @@ class generic_stage_target(generic_target):
72
73 if "AUTORESUME" in self.settings:
74 if os.path.isdir(self.settings["source_path"]) \
75 - and os.path.exists(self.settings["autoresume_path"]+"unpack"):
76 + and os.path.exists(unpack_resume):
77 """ Autoresume is valid, SEEDCACHE is valid """
78 unpack=False
79 invalid_snapshot=False
80 @@ -732,8 +738,7 @@ class generic_stage_target(generic_target):
81 invalid_snapshot=True
82
83 elif os.path.isdir(self.settings["source_path"]) \
84 - and not os.path.exists(self.settings["autoresume_path"]+\
85 - "unpack"):
86 + and not os.path.exists(unpack_resume):
87 """ Autoresume is invalid, SEEDCACHE """
88 unpack=True
89 invalid_snapshot=False
90 @@ -793,18 +798,19 @@ class generic_stage_target(generic_target):
91 cmd(unpack_cmd,error_msg,env=self.env)
92
93 if "source_path_hash" in self.settings:
94 - myf=open(self.settings["autoresume_path"]+"unpack","w")
95 + myf=open(unpack_resume,"w")
96 myf.write(self.settings["source_path_hash"])
97 myf.close()
98 else:
99 - touch(self.settings["autoresume_path"]+"unpack")
100 + touch(unpack_resume)
101 else:
102 print "Resume point detected, skipping unpack operation..."
103
104 def unpack_snapshot(self):
105 unpack=True
106 - snapshot_hash=read_from_clst(self.settings["autoresume_path"]+\
107 + unpack_portage_resume = pjoin(self.settings["autoresume_path"],
108 "unpack_portage")
109 + snapshot_hash=read_from_clst(unpack_portage_resume)
110
111 if "SNAPCACHE" in self.settings:
112 snapshot_cache_hash=\
113 @@ -841,8 +847,7 @@ class generic_stage_target(generic_target):
114 if "AUTORESUME" in self.settings \
115 and os.path.exists(self.settings["chroot_path"]+\
116 self.settings["portdir"]) \
117 - and os.path.exists(self.settings["autoresume_path"]\
118 - +"unpack_portage") \
119 + and os.path.exists(unpack_portage_resume) \
120 and self.settings["snapshot_path_hash"] == snapshot_hash:
121 print \
122 "Valid Resume point detected, skipping unpack of portage tree..."
123 @@ -868,7 +873,7 @@ class generic_stage_target(generic_target):
124 myf.close()
125 else:
126 print "Setting snapshot autoresume point"
127 - myf=open(self.settings["autoresume_path"]+"unpack_portage","w")
128 + myf=open(unpack_portage_resume,"w")
129 myf.write(self.settings["snapshot_path_hash"])
130 myf.close()
131
132 @@ -876,9 +881,10 @@ class generic_stage_target(generic_target):
133 self.snapshot_lock_object.unlock()
134
135 def config_profile_link(self):
136 + config_protect_link_resume = pjoin(self.settings["autoresume_path"],
137 + "config_profile_link")
138 if "AUTORESUME" in self.settings \
139 - and os.path.exists(self.settings["autoresume_path"]+\
140 - "config_profile_link"):
141 + and os.path.exists():
142 print \
143 "Resume point detected, skipping config_profile_link operation..."
144 else:
145 @@ -892,12 +898,13 @@ class generic_stage_target(generic_target):
146 self.settings["target_profile"]+" "+\
147 self.settings["chroot_path"]+"/etc/portage/make.profile",\
148 "Error creating profile link",env=self.env)
149 - touch(self.settings["autoresume_path"]+"config_profile_link")
150 + touch(config_protect_link_resume)
151
152 def setup_confdir(self):
153 + setup_confdir_resume = pjoin(self.settings["autoresume_path"],
154 + "setup_confdir")
155 if "AUTORESUME" in self.settings \
156 - and os.path.exists(self.settings["autoresume_path"]+\
157 - "setup_confdir"):
158 + and os.path.exists(setup_confdir_resume):
159 print "Resume point detected, skipping setup_confdir operation..."
160 else:
161 if "portage_confdir" in self.settings:
162 @@ -905,7 +912,7 @@ class generic_stage_target(generic_target):
163 cmd("rsync -a "+self.settings["portage_confdir"]+"/ "+\
164 self.settings["chroot_path"]+"/etc/portage/",\
165 "Error copying /etc/portage",env=self.env)
166 - touch(self.settings["autoresume_path"]+"setup_confdir")
167 + touch(setup_confdir_resume)
168
169 def portage_overlay(self):
170 """ We copy the contents of our overlays to /usr/local/portage """
171 @@ -1029,8 +1036,9 @@ class generic_stage_target(generic_target):
172 self.override_cflags()
173 self.override_cxxflags()
174 self.override_ldflags()
175 - if "AUTORESUME" in self.settings \
176 - and os.path.exists(self.settings["autoresume_path"]+"chroot_setup"):
177 + chroot_setup_resume = pjoin(self.settings["autoresume_path"],
178 + "chroot_setup")
179 + if "AUTORESUME" in self.settings and os.path.exists(chroot_setup_resume):
180 print "Resume point detected, skipping chroot_setup operation..."
181 else:
182 print "Setting up chroot..."
183 @@ -1126,32 +1134,34 @@ class generic_stage_target(generic_target):
184 cmd("cp "+self.settings["chroot_path"]+"/etc/portage/make.conf "+\
185 self.settings["chroot_path"]+"/etc/portage/make.conf.catalyst",\
186 "Could not backup /etc/portage/make.conf",env=self.env)
187 - touch(self.settings["autoresume_path"]+"chroot_setup")
188 + touch(chroot_setup_resume)
189
190 def fsscript(self):
191 - if "AUTORESUME" in self.settings \
192 - and os.path.exists(self.settings["autoresume_path"]+"fsscript"):
193 + fsscript_resume = pjoin(self.settings["autoresume_path"], "fsscript")
194 + if "AUTORESUME" in self.settings and os.path.exists(fsscript_resume):
195 print "Resume point detected, skipping fsscript operation..."
196 else:
197 if "fsscript" in self.settings:
198 if os.path.exists(self.settings["controller_file"]):
199 cmd("/bin/bash "+self.settings["controller_file"]+\
200 " fsscript","fsscript script failed.",env=self.env)
201 - touch(self.settings["autoresume_path"]+"fsscript")
202 + touch(fsscript_resume)
203
204 def rcupdate(self):
205 + rcupdate_resume = pjoin(self.settings["autoresume_path"], "rcupdate")
206 if "AUTORESUME" in self.settings \
207 - and os.path.exists(self.settings["autoresume_path"]+"rcupdate"):
208 + and os.path.exists(rcupdate_resume):
209 print "Resume point detected, skipping rcupdate operation..."
210 else:
211 if os.path.exists(self.settings["controller_file"]):
212 cmd("/bin/bash "+self.settings["controller_file"]+" rc-update",\
213 "rc-update script failed.",env=self.env)
214 - touch(self.settings["autoresume_path"]+"rcupdate")
215 + touch(rcupdate_resume)
216
217 def clean(self):
218 + clean_resume = pjoin(self.settings["autoresume_path"], "clean")
219 if "AUTORESUME" in self.settings \
220 - and os.path.exists(self.settings["autoresume_path"]+"clean"):
221 + and os.path.exists(clean_resume):
222 print "Resume point detected, skipping clean operation..."
223 else:
224 for x in self.settings["cleanables"]:
225 @@ -1182,11 +1192,11 @@ class generic_stage_target(generic_target):
226 if os.path.exists(self.settings["controller_file"]):
227 cmd("/bin/bash "+self.settings["controller_file"]+" clean",\
228 "clean script failed.",env=self.env)
229 - touch(self.settings["autoresume_path"]+"clean")
230 + touch(clean_resume)
231
232 def empty(self):
233 - if "AUTORESUME" in self.settings \
234 - and os.path.exists(self.settings["autoresume_path"]+"empty"):
235 + empty_resume = pjoin(self.settings["autoresume_path"], "empty")
236 + if "AUTORESUME" in self.settings and os.path.exists(empty_resume):
237 print "Resume point detected, skipping empty operation..."
238 else:
239 if self.settings["spec_prefix"]+"/empty" in self.settings:
240 @@ -1210,11 +1220,11 @@ class generic_stage_target(generic_target):
241 os.makedirs(myemp,0755)
242 os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
243 os.chmod(myemp,mystat[ST_MODE])
244 - touch(self.settings["autoresume_path"]+"empty")
245 + touch(empty_resume)
246
247 def remove(self):
248 - if "AUTORESUME" in self.settings \
249 - and os.path.exists(self.settings["autoresume_path"]+"remove"):
250 + remove_resume = pjoin(self.settings["autoresume_path"], "remove")
251 + if "AUTORESUME" in self.settings and os.path.exists(remove_resume):
252 print "Resume point detected, skipping remove operation..."
253 else:
254 if self.settings["spec_prefix"]+"/rm" in self.settings:
255 @@ -1229,29 +1239,29 @@ class generic_stage_target(generic_target):
256 if os.path.exists(self.settings["controller_file"]):
257 cmd("/bin/bash "+self.settings["controller_file"]+\
258 " clean","Clean failed.",env=self.env)
259 - touch(self.settings["autoresume_path"]+"remove")
260 + touch(remove_resume)
261 except:
262 self.unbind()
263 raise
264
265 def preclean(self):
266 - if "AUTORESUME" in self.settings \
267 - and os.path.exists(self.settings["autoresume_path"]+"preclean"):
268 + preclean_resume = pjoin(self.settings["autoresume_path"], "preclean")
269 + if "AUTORESUME" in self.settings and os.path.exists(preclean_resume):
270 print "Resume point detected, skipping preclean operation..."
271 else:
272 try:
273 if os.path.exists(self.settings["controller_file"]):
274 cmd("/bin/bash "+self.settings["controller_file"]+\
275 " preclean","preclean script failed.",env=self.env)
276 - touch(self.settings["autoresume_path"]+"preclean")
277 + touch(preclean_resume)
278
279 except:
280 self.unbind()
281 raise CatalystError, "Build failed, could not execute preclean"
282
283 def capture(self):
284 - if "AUTORESUME" in self.settings \
285 - and os.path.exists(self.settings["autoresume_path"]+"capture"):
286 + capture_resume = pjoin(self.settings["autoresume_path"], "capture")
287 + if "AUTORESUME" in self.settings and os.path.exists(capture_resume):
288 print "Resume point detected, skipping capture operation..."
289 else:
290 """ Capture target in a tarball """
291 @@ -1272,18 +1282,18 @@ class generic_stage_target(generic_target):
292 self.gen_contents_file(self.settings["target_path"])
293 self.gen_digest_file(self.settings["target_path"])
294
295 - touch(self.settings["autoresume_path"]+"capture")
296 + touch(capture_resume)
297
298 def run_local(self):
299 - if "AUTORESUME" in self.settings \
300 - and os.path.exists(self.settings["autoresume_path"]+"run_local"):
301 + run_local_resume = pjoin(self.settings["autoresume_path"], "run_local")
302 + if "AUTORESUME" in self.settings and os.path.exists(run_local_resume):
303 print "Resume point detected, skipping run_local operation..."
304 else:
305 try:
306 if os.path.exists(self.settings["controller_file"]):
307 cmd("/bin/bash "+self.settings["controller_file"]+" run",\
308 "run script failed.",env=self.env)
309 - touch(self.settings["autoresume_path"]+"run_local")
310 + touch(run_local_resume)
311
312 except CatalystError:
313 self.unbind()
314 @@ -1350,8 +1360,8 @@ class generic_stage_target(generic_target):
315 self.chroot_lock.unlock()
316
317 def unmerge(self):
318 - if "AUTORESUME" in self.settings \
319 - and os.path.exists(self.settings["autoresume_path"]+"unmerge"):
320 + unmerge_resume = pjoin(self.settings["autoresume_path"], "unmerge")
321 + if "AUTORESUME" in self.settings and os.path.exists(unmerge_resume):
322 print "Resume point detected, skipping unmerge operation..."
323 else:
324 if self.settings["spec_prefix"]+"/unmerge" in self.settings:
325 @@ -1379,22 +1389,25 @@ class generic_stage_target(generic_target):
326 except CatalystError:
327 self.unbind()
328 raise
329 - touch(self.settings["autoresume_path"]+"unmerge")
330 + touch(unmerge_resume)
331
332 def target_setup(self):
333 - if "AUTORESUME" in self.settings \
334 - and os.path.exists(self.settings["autoresume_path"]+"target_setup"):
335 + target_setup_resume = pjoin(self.settings["autoresume_path"],
336 + "target_setup")
337 + if "AUTORESUME" in self.settings and os.path.exists(target_setup_resume):
338 print "Resume point detected, skipping target_setup operation..."
339 else:
340 print "Setting up filesystems per filesystem type"
341 cmd("/bin/bash "+self.settings["controller_file"]+\
342 " target_image_setup "+ self.settings["target_path"],\
343 "target_image_setup script failed.",env=self.env)
344 - touch(self.settings["autoresume_path"]+"target_setup")
345 + touch(target_setup_resume)
346
347 def setup_overlay(self):
348 - if "AUTORESUME" in self.settings \
349 - and os.path.exists(self.settings["autoresume_path"]+"setup_overlay"):
350 + setup_overlay_resume = pjoin(self.settings["autoresume_path"],
351 + "setup_overlay")
352 + if "AUTORESUME" in self.settings and \
353 + os.path.exists(setup_overlay_resume):
354 print "Resume point detected, skipping setup_overlay operation..."
355 else:
356 if self.settings["spec_prefix"]+"/overlay" in self.settings:
357 @@ -1404,11 +1417,11 @@ class generic_stage_target(generic_target):
358 self.settings["target_path"],\
359 self.settings["spec_prefix"]+"overlay: "+x+\
360 " copy failed.",env=self.env)
361 - touch(self.settings["autoresume_path"]+"setup_overlay")
362 + touch(setup_overlay_resume)
363
364 def create_iso(self):
365 - if "AUTORESUME" in self.settings \
366 - and os.path.exists(self.settings["autoresume_path"]+"create_iso"):
367 + create_iso_resume = pjoin(self.settings["autoresume_path"], "create_iso")
368 + if "AUTORESUME" in self.settings and os.path.exists(create_iso_resume):
369 print "Resume point detected, skipping create_iso operation..."
370 else:
371 """ Create the ISO """
372 @@ -1418,15 +1431,16 @@ class generic_stage_target(generic_target):
373 env=self.env)
374 self.gen_contents_file(self.settings["iso"])
375 self.gen_digest_file(self.settings["iso"])
376 - touch(self.settings["autoresume_path"]+"create_iso")
377 + touch(create_iso_resume)
378 else:
379 print "WARNING: livecd/iso was not defined."
380 print "An ISO Image will not be created."
381
382 def build_packages(self):
383 - if "AUTORESUME" in self.settings \
384 - and os.path.exists(self.settings["autoresume_path"]+\
385 - "build_packages"):
386 + build_packages_resume = pjoin(self.settings["autoresume_path"],
387 + "build_packages")
388 + if "AUTORESUME" in self.settings and \
389 + os.path.exists(build_packages_resume):
390 print "Resume point detected, skipping build_packages operation..."
391 else:
392 if self.settings["spec_prefix"]+"/packages" in self.settings:
393 @@ -1442,7 +1456,7 @@ class generic_stage_target(generic_target):
394 cmd("/bin/bash "+self.settings["controller_file"]+\
395 " build_packages "+mypack,\
396 "Error in attempt to build packages",env=self.env)
397 - touch(self.settings["autoresume_path"]+"build_packages")
398 + touch(build_packages_resume)
399 except CatalystError:
400 self.unbind()
401 raise CatalystError,self.settings["spec_prefix"]+\
402 @@ -1450,8 +1464,9 @@ class generic_stage_target(generic_target):
403
404 def build_kernel(self):
405 "Build all configured kernels"
406 - if "AUTORESUME" in self.settings \
407 - and os.path.exists(self.settings["autoresume_path"]+"build_kernel"):
408 + build_kernel_resume = pjoin(self.settings["autoresume_path"],
409 + "build_kernel")
410 + if "AUTORESUME" in self.settings and os.path.exists(build_kernel_resume):
411 print "Resume point detected, skipping build_kernel operation..."
412 else:
413 if "boot/kernel" in self.settings:
414 @@ -1467,7 +1482,7 @@ class generic_stage_target(generic_target):
415 env=self.env)
416 for kname in mynames:
417 self._build_kernel(kname=kname)
418 - touch(self.settings["autoresume_path"]+"build_kernel")
419 + touch(build_kernel_resume)
420 except CatalystError:
421 self.unbind()
422 raise CatalystError,\
423 @@ -1475,9 +1490,9 @@ class generic_stage_target(generic_target):
424
425 def _build_kernel(self, kname):
426 "Build a single configured kernel by name"
427 - if "AUTORESUME" in self.settings \
428 - and os.path.exists(self.settings["autoresume_path"]\
429 - +"build_kernel_"+kname):
430 + kname_resume = pjoin(self.settings["autoresume_path"],
431 + "build_kernel_" + kname)
432 + if "AUTORESUME" in self.settings and os.path.exists(kname_resume):
433 print "Resume point detected, skipping build_kernel for "+kname+" operation..."
434 return
435 self._copy_kernel_config(kname=kname)
436 @@ -1519,8 +1534,7 @@ class generic_stage_target(generic_target):
437 cmd("rm -R "+self.settings["chroot_path"]+\
438 "/tmp/initramfs_overlay/",env=self.env)
439
440 - touch(self.settings["autoresume_path"]+\
441 - "build_kernel_"+kname)
442 + touch(kname_resume)
443
444 """
445 Execute the script that cleans up the kernel build
446 @@ -1573,29 +1587,30 @@ class generic_stage_target(generic_target):
447 "/initramfs_overlay"],env=self.env)
448
449 def bootloader(self):
450 - if "AUTORESUME" in self.settings \
451 - and os.path.exists(self.settings["autoresume_path"]+"bootloader"):
452 + bootloader_resume = pjoin(self.settings["autoresume_path"], "bootloader")
453 + if "AUTORESUME" in self.settings and os.path.exists(bootloader_resume):
454 print "Resume point detected, skipping bootloader operation..."
455 else:
456 try:
457 cmd("/bin/bash "+self.settings["controller_file"]+\
458 " bootloader " + self.settings["target_path"],\
459 "Bootloader script failed.",env=self.env)
460 - touch(self.settings["autoresume_path"]+"bootloader")
461 + touch(bootloader_resume)
462 except CatalystError:
463 self.unbind()
464 raise CatalystError,"Script aborting due to error."
465
466 def livecd_update(self):
467 + livecd_update_resume = pjoin(self.settings["autoresume_path"],
468 + "livecd_update")
469 if "AUTORESUME" in self.settings \
470 - and os.path.exists(self.settings["autoresume_path"]+\
471 - "livecd_update"):
472 + and os.path.exists(livecd_update_resume):
473 print "Resume point detected, skipping build_packages operation..."
474 else:
475 try:
476 cmd("/bin/bash "+self.settings["controller_file"]+\
477 " livecd-update","livecd-update failed.",env=self.env)
478 - touch(self.settings["autoresume_path"]+"livecd_update")
479 + touch(livecd_update_resume)
480
481 except CatalystError:
482 self.unbind()
483 --
484 1.8.5.3

Replies

Subject Author
[gentoo-catalyst] Re: [PATCH] Fix autoresume file paths to only be configured once. "W. Trevor King" <wking@×××××××.us>