[gentoo-commits] proj/catalyst:pending commit in: catalyst/targets/, catalyst/

2017-04-06 Thread Brian Dolbec
commit: 42747d0193e1914270a65cfa81df5e3a017a53e2
Author: Brian Dolbec  gentoo  org>
AuthorDate: Thu Apr  6 20:51:23 2017 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Thu Apr  6 20:52:26 2017 +
URL:https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=42747d01

stage1: Fix seedcache to clean out the original seed root, keep only the 
stage1root

Signed-off-by: Brian Dolbec  gentoo.org>

 catalyst/fileops.py| 23 +++
 catalyst/targets/stage1.py | 39 ++-
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/catalyst/fileops.py b/catalyst/fileops.py
index ef4ee8d1..5e51f1fc 100644
--- a/catalyst/fileops.py
+++ b/catalyst/fileops.py
@@ -107,3 +107,26 @@ def clear_dir(target, mode=0o755, chg_flags=False, 
remove=False,
 def clear_path(target):
"""Nuke |target| regardless of it being a dir or file."""
clear_dir(target, remove=True)
+
+
+def move_path(src, dest):
+   '''Move a source target to a new destination
+
+   :param src: source path to move
+   :param dest: destination path to move it to
+   :returns: boolean
+   '''
+   log.debug('Start move_path(%s, %s)', src, dest)
+   if os.path.isdir(src) and not os.path.islink(src):
+   if os.path.exists(dest):
+   log.warning('Removing existing target destination: %s', 
dest)
+   if not clear_dir(dest, remove=True):
+   return False
+   log.debug('Moving source...')
+   try:
+   shutil.move(src, dest)
+   except Exception:
+   log.error('move_path failed', exc_info=True)
+   return False
+   return True
+   return False

diff --git a/catalyst/targets/stage1.py b/catalyst/targets/stage1.py
index 18ef520d..cc4366b6 100644
--- a/catalyst/targets/stage1.py
+++ b/catalyst/targets/stage1.py
@@ -9,7 +9,7 @@ from snakeoil import fileutils
 
 from catalyst import log
 from catalyst.support import normpath
-from catalyst.fileops import ensure_dirs
+from catalyst.fileops import ensure_dirs, move_path
 from catalyst.base.stagebase import StageBase
 
 
@@ -86,3 +86,40 @@ class stage1(StageBase):
self.mounts.append("stage1root/proc")
self.target_mounts["stage1root/proc"] = "/tmp/stage1root/proc"
self.mountmap["stage1root/proc"] = "/proc"
+
+   def set_completion_action_sequences(self):
+   '''Override function for stage1
+
+   Its purpose is to move the new stage1root out of the seed stage
+   and rename it to the stage1 chroot_path after cleaning the seed 
stage
+   chroot for re-use in stage2 without the need to unpack it.
+   '''
+   if "fetch" not in self.settings["options"]:
+   self.settings["action_sequence"].append("capture")
+   if "keepwork" in self.settings["options"]:
+   
self.settings["action_sequence"].append("clear_autoresume")
+   elif "seedcache" in self.settings["options"]:
+   
self.settings["action_sequence"].append("remove_autoresume")
+   self.settings["action_sequence"].append("clean_stage1")
+   else:
+   
self.settings["action_sequence"].append("remove_autoresume")
+   self.settings["action_sequence"].append("remove_chroot")
+   return
+
+
+   def clean_stage1(self):
+   '''seedcache is enabled, so salvage the /tmp/stage1root,
+   remove the seed chroot'''
+   log.notice('Salvaging the stage1root from the chroot path ...')
+   # move the self.settings["stage_path"] outside of the 
self.settings["chroot_path"]
+   tmp_path = normpath(self.settings["storedir"] + "/tmp/" + 
"stage1root")
+   if move_path(self.settings["stage_path"], tmp_path):
+   self.remove_chroot()
+   # move it to self.settings["chroot_path"]
+   if not move_path(tmp_path, 
self.settings["chroot_path"]):
+   log.error('clean_stage1 failed, see previous 
log messages for details')
+   return False
+   log.notice('Successfully moved and cleaned the 
stage1root for the seedcache')
+   return True
+   log.error('clean_stage1 failed to move the stage1root to a 
temporary loation')
+   return False



[gentoo-commits] proj/catalyst:pending commit in: catalyst/targets/, catalyst/base/, catalyst/, etc/, examples/

2015-09-06 Thread Brian Dolbec
commit: 9a280f3988a20e7d5e66dd42aaba4033be0ddba0
Author: Brian Dolbec  gentoo  org>
AuthorDate: Sun May 24 07:36:49 2015 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Sun Sep  6 21:18:00 2015 +
URL:https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=9a280f39

Apply new compress code, normalize paths

Fix the target_filename ending in a slash

 catalyst/base/stagebase.py   | 171 +++
 catalyst/defaults.py |   4 +
 catalyst/main.py |   8 ++
 catalyst/targets/grp.py  |   2 +-
 catalyst/targets/livecd_stage1.py|   2 +-
 catalyst/targets/livecd_stage2.py|   6 +-
 catalyst/targets/netboot.py  |   8 +-
 catalyst/targets/netboot2.py |   2 +-
 catalyst/targets/stage2.py   |   8 +-
 etc/catalyst.conf|  11 ++-
 examples/generic_stage_template.spec |  32 ++-
 11 files changed, 159 insertions(+), 95 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index d898e95..655ea06 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -10,6 +10,8 @@ from stat import ST_UID, ST_GID, ST_MODE
 # for convienience
 pjoin = os.path.join
 
+from decomp.compress import CompressMap
+
 from catalyst.defaults import (SOURCE_MOUNT_DEFAULTS, TARGET_MOUNT_DEFAULTS,
PORT_LOGDIR_CLEAN)
 from catalyst.support import (CatalystError, msg, file_locate, normpath,
@@ -264,6 +266,14 @@ class StageBase(TargetBase, ClearBase, GenBase):
self.env["PORT_LOGDIR"] = self.settings["port_logdir"]
self.env["PORT_LOGDIR_CLEAN"] = PORT_LOGDIR_CLEAN
 
+   # Initialize our (de)compressor's)
+   self.decompressor = 
CompressMap(self.settings["decompress_definitions"],
+   env=self.env,
+   search_order=self.settings["decompressor_search_order"])
+
+   # save resources, it is not always needed
+   self.compressor = None
+
def override_cbuild(self):
if "CBUILD" in self.makeconf:
self.settings["CBUILD"]=self.makeconf["CBUILD"]
@@ -332,11 +342,11 @@ class StageBase(TargetBase, ClearBase, GenBase):

normpath(self.settings["kerncache_path"])
else:

self.settings["kerncache_path"]=normpath(self.settings["storedir"]+\
-   
"/kerncache/"+self.settings["target_subpath"]+"/")
+   "/kerncache/"+self.settings["target_subpath"])
 
def set_target_path(self):

self.settings["target_path"]=normpath(self.settings["storedir"]+\
-   
"/builds/"+self.settings["target_subpath"].rstrip('/')+".tar.bz2")
+   "/builds/"+self.settings["target_subpath"])
if "autoresume" in self.settings["options"]\
and self.resume.is_enabled("setup_target_path"):
print \
@@ -420,7 +430,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
"/tmp/" + self.settings["source_subpath"] + "/")
else:

self.settings["source_path"]=normpath(self.settings["storedir"]+\
-   
"/builds/"+self.settings["source_subpath"].rstrip('/')+".tar.bz2")
+   "/builds/"+self.settings["source_subpath"])
if os.path.isfile(self.settings["source_path"]):
# XXX: Is this even necessary if the previous 
check passes?
if os.path.exists(self.settings["source_path"]):
@@ -435,7 +445,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
print "\tseedcache in the options of catalyst.conf the 
source path"
print "\twill then be "+\
normpath(self.settings["storedir"]+"/builds/"+\
-   
self.settings["source_subpath"].rstrip('/')+".tar.bz2\n")
+   self.settings["source_subpath"]+"\n")
 
def set_dest_path(self):
if "root_path" in self.settings:
@@ -462,7 +472,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
else:

self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
"/snapshots/" + self.settings["snapshot_name"] +
-   
self.settings["snapshot"].rstrip('/')+".tar.bz2")
+   self.settings["snapshot"])
 
if os.path.exists(self.settings["snapshot_path"]):
self.settings["snapshot_path_hash"] = \
@@ -472,6 +482,9 @@ class StageBase(TargetBase, ClearBase, GenBase):
  

[gentoo-commits] proj/catalyst:pending commit in: catalyst/targets/, catalyst/base/

2015-09-03 Thread Brian Dolbec
commit: 07d13a24c6b28369c63c9cfcc955df6547300243
Author: Brian Dolbec  gentoo  org>
AuthorDate: Mon Jun 15 23:10:50 2015 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Thu Sep  3 15:12:39 2015 +
URL:https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=07d13a24

Fix a couple print() uses back to print statements for consistency

 catalyst/base/stagebase.py   | 4 ++--
 catalyst/targets/snapshot.py | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index e0e9023..f774ce8 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1308,8 +1308,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
target_filename = 
".".join([self.settings["target_path"],
self.compressor.extension(pack_info['mode'])])
 
-   print("Creating stage tarball... mode:",
-   self.settings["compression_mode"])
+   print "Creating stage tarball... mode:", \
+   self.settings["compression_mode"]
 
if self.compressor.compress(pack_info):
self.gen_contents_file(target_filename)

diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py
index ad96d37..1edcd02 100644
--- a/catalyst/targets/snapshot.py
+++ b/catalyst/targets/snapshot.py
@@ -72,11 +72,11 @@ class snapshot(TargetBase, GenBase):
auto_extension=True
)
if not compressor.compress(infodict):
-   print("Snapshot compression failure")
+   print "Snapshot compression failure"
else:
filename = '.'.join([self.settings["snapshot_path"],

compressor.extension(self.settings["compression_mode"])])
-   print("COMPRESSOR success filename", filename)
+   print "COMPRESSOR success filename", filename
self.gen_contents_file(filename)
self.gen_digest_file(filename)
 



[gentoo-commits] proj/catalyst:pending commit in: catalyst/targets/, catalyst/base/

2015-08-31 Thread Brian Dolbec
commit: 515546abb3859533a1a64a64253e661b19676b77
Author: Brian Dolbec  gentoo  org>
AuthorDate: Mon Jun 15 23:10:50 2015 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Tue Sep  1 05:54:12 2015 +
URL:https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=515546ab

Fix a couple print() uses back to print statements for consistency

 catalyst/base/stagebase.py   | 4 ++--
 catalyst/targets/snapshot.py | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index c23c8b7..f4bed03 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1279,8 +1279,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
target_filename = 
".".join([self.settings["target_path"],
self.compressor.extension(pack_info['mode'])])
 
-   print("Creating stage tarball... mode:",
-   self.settings["compression_mode"])
+   print "Creating stage tarball... mode:", \
+   self.settings["compression_mode"]
 
if self.compressor.compress(pack_info):
self.gen_contents_file(target_filename)

diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py
index ad96d37..1edcd02 100644
--- a/catalyst/targets/snapshot.py
+++ b/catalyst/targets/snapshot.py
@@ -72,11 +72,11 @@ class snapshot(TargetBase, GenBase):
auto_extension=True
)
if not compressor.compress(infodict):
-   print("Snapshot compression failure")
+   print "Snapshot compression failure"
else:
filename = '.'.join([self.settings["snapshot_path"],

compressor.extension(self.settings["compression_mode"])])
-   print("COMPRESSOR success filename", filename)
+   print "COMPRESSOR success filename", filename
self.gen_contents_file(filename)
self.gen_digest_file(filename)
 



[gentoo-commits] proj/catalyst:pending commit in: catalyst/targets/, catalyst/base/

2015-02-26 Thread Brian Dolbec
commit: 5b08b471611670b4cc996e45c387ecd951fb2142
Author: Brian Dolbec dolsen AT gentoo DOT org
AuthorDate: Wed Jun 12 14:40:12 2013 +
Commit: Brian Dolbec dolsen AT gentoo DOT org
CommitDate: Thu Feb 26 19:58:28 2015 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=5b08b471

Fix livecd source and target paths not ending with a slash

---
 catalyst/base/stagebase.py| 2 +-
 catalyst/targets/livecd_stage1.py | 3 +--
 catalyst/targets/livecd_stage2.py | 2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index bdeaedd..eec74df 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -294,7 +294,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
def set_target_subpath(self):
self.settings[target_subpath]=self.settings[rel_type]+/+\

self.settings[target]+-+self.settings[subarch]+-+\
-   self.settings[version_stamp]
+   self.settings[version_stamp] +'/'
 
def set_source_subpath(self):
if type(self.settings[source_subpath])!=types.StringType:

diff --git a/catalyst/targets/livecd_stage1.py 
b/catalyst/targets/livecd_stage1.py
index 55859bc..8402e7a 100644
--- a/catalyst/targets/livecd_stage1.py
+++ b/catalyst/targets/livecd_stage1.py
@@ -33,7 +33,7 @@ class livecd_stage1(StageBase):
unbind, clean,clear_autoresume]
 
def set_target_path(self):
-   
self.settings[target_path]=normpath(self.settings[storedir]+/builds/+self.settings[target_subpath])
+   
self.settings[target_path]=normpath(self.settings[storedir]+/builds/+self.settings[target_subpath]+'/')
if autoresume in self.settings[options] \
and self.resume.is_enabled(setup_target_path):
print Resume point detected, skipping target 
path setup operation...
@@ -43,7 +43,6 @@ class livecd_stage1(StageBase):
cmd(rm -rf +self.settings[target_path],\
Could not remove existing directory: 
+self.settings[target_path],env=self.env)
self.resume.enable(setup_target_path)
-
ensure_dirs(self.settings[target_path])
 
def set_spec_prefix(self):

diff --git a/catalyst/targets/livecd_stage2.py 
b/catalyst/targets/livecd_stage2.py
index 45a6767..55e6897 100644
--- a/catalyst/targets/livecd_stage2.py
+++ b/catalyst/targets/livecd_stage2.py
@@ -43,7 +43,7 @@ class livecd_stage2(StageBase):
self.settings[hash_map].generate_hash(
self.settings[source_path])
else:
-   
self.settings[source_path]=normpath(self.settings[storedir]+/tmp/+self.settings[source_subpath])
+   
self.settings[source_path]=normpath(self.settings[storedir]+/tmp/+self.settings[source_subpath]+'/')
if not os.path.exists(self.settings[source_path]):
raise CatalystError(Source Path:  +
self.settings[source_path] +  does not 
exist.,



[gentoo-commits] proj/catalyst:pending commit in: catalyst/targets/, catalyst/base/

2014-12-31 Thread Brian Dolbec
commit: 5fa2b2a910c45401f132e7ed7e9da9a993762252
Author: Brian Dolbec dolsen AT gentoo DOT org
AuthorDate: Tue Feb 12 03:51:52 2013 +
Commit: Brian Dolbec dolsen AT gentoo DOT org
CommitDate: Thu Jan  1 05:58:05 2015 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=5fa2b2a9

[1 of 3] Move base stage and target files to thier own sub-pkg

Fix an indent error in grp_target.py

---
 catalyst/base/__init__.py  |  1 +
 catalyst/{targets = base}/clearbase.py|  0
 catalyst/{targets = base}/genbase.py  |  0
 .../generic_stage_target.py = base/stagebase.py}  |  8 ++---
 catalyst/{targets = base}/targetbase.py   |  0
 catalyst/targets/embedded_target.py| 12 
 catalyst/targets/grp_target.py | 34 +-
 catalyst/targets/livecd_stage1_target.py   | 21 -
 catalyst/targets/livecd_stage2_target.py   | 13 +
 catalyst/targets/netboot2_target.py| 17 +++
 catalyst/targets/netboot_target.py | 15 ++
 catalyst/targets/snapshot_target.py|  4 +--
 catalyst/targets/stage1_target.py  | 17 ++-
 catalyst/targets/stage2_target.py  | 15 ++
 catalyst/targets/stage3_target.py  | 12 
 catalyst/targets/stage4_target.py  |  8 ++---
 catalyst/targets/tinderbox_target.py   | 11 ---
 17 files changed, 113 insertions(+), 75 deletions(-)

diff --git a/catalyst/base/__init__.py b/catalyst/base/__init__.py
new file mode 100644
index 000..8b13789
--- /dev/null
+++ b/catalyst/base/__init__.py
@@ -0,0 +1 @@
+

diff --git a/catalyst/targets/clearbase.py b/catalyst/base/clearbase.py
similarity index 100%
rename from catalyst/targets/clearbase.py
rename to catalyst/base/clearbase.py

diff --git a/catalyst/targets/genbase.py b/catalyst/base/genbase.py
similarity index 100%
rename from catalyst/targets/genbase.py
rename to catalyst/base/genbase.py

diff --git a/catalyst/targets/generic_stage_target.py 
b/catalyst/base/stagebase.py
similarity index 99%
rename from catalyst/targets/generic_stage_target.py
rename to catalyst/base/stagebase.py
index 296eee3..bebb5dc 100644
--- a/catalyst/targets/generic_stage_target.py
+++ b/catalyst/base/stagebase.py
@@ -14,13 +14,13 @@ from catalyst.defaults import (SOURCE_MOUNT_DEFAULTS, 
TARGET_MOUNT_DEFAULTS,
PORT_LOGDIR_CLEAN)
 from catalyst.support import (CatalystError, msg, file_locate, normpath,
touch, cmd, warn, list_bashify, read_makeconf, read_from_clst, ismount)
-from catalyst.targets.targetbase import TargetBase
-from catalyst.targets.clearbase import ClearBase
-from catalyst.targets.genbase import GenBase
+from catalyst.base.targetbase import TargetBase
+from catalyst.base.clearbase import ClearBase
+from catalyst.base.genbase import GenBase
 from catalyst.lock import LockDir
 
 
-class generic_stage_target(TargetBase, ClearBase, GenBase):
+class StageBase(TargetBase, ClearBase, GenBase):

This class does all of the chroot setup, copying of files, etc. It is
the driver class for pretty much everything that Catalyst does.

diff --git a/catalyst/targets/targetbase.py b/catalyst/base/targetbase.py
similarity index 100%
rename from catalyst/targets/targetbase.py
rename to catalyst/base/targetbase.py

diff --git a/catalyst/targets/embedded_target.py 
b/catalyst/targets/embedded_target.py
index 7cee7a6..528d545 100644
--- a/catalyst/targets/embedded_target.py
+++ b/catalyst/targets/embedded_target.py
@@ -10,12 +10,12 @@ ROOT=/tmp/submerge emerge --something foo bar .
 
 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
 
-import os,string,imp,types,shutil
-from catalyst.support import *
-from generic_stage_target import *
-from stat import *
 
-class embedded_target(generic_stage_target):
+from catalyst.support import normpath
+
+from catalyst.base.stagebase import StageBase
+
+class embedded_target(StageBase):

Builder class for embedded target

@@ -27,7 +27,7 @@ class embedded_target(generic_stage_target):
if embedded/fs-type in addlargs:
self.valid_values.append(embedded/fs-ops)
 
-   generic_stage_target.__init__(self,spec,addlargs)
+   StageBase.__init__(self,spec,addlargs)
self.set_build_kernel_vars(addlargs)
 
def set_action_sequence(self):

diff --git a/catalyst/targets/grp_target.py b/catalyst/targets/grp_target.py
index 033db75..deba80a 100644
--- a/catalyst/targets/grp_target.py
+++ b/catalyst/targets/grp_target.py
@@ -3,11 +3,18 @@ Gentoo Reference Platform (GRP) target
 
 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
 
-import os,types,glob
-from catalyst.support import *
-from generic_stage_target import *
+import os
+import 

[gentoo-commits] proj/catalyst:pending commit in: catalyst/targets/, catalyst/

2014-12-31 Thread Brian Dolbec
commit: d4bc8e3c5ba7bca5656ea597e3ad013a4e61c8b5
Author: Brian Dolbec dolsen AT gentoo DOT org
AuthorDate: Sun Jan 20 08:10:03 2013 +
Commit: Brian Dolbec dolsen AT gentoo DOT org
CommitDate: Thu Jan  1 05:58:05 2015 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=d4bc8e3c

Begin splitting up generic_stage_target into smaller code blocks.

This so snapshot_target does not need to import it since most of it was
not used or initialized properly.

---
 catalyst/defaults.py   |   2 +-
 catalyst/targets/clearbase.py  | 115 ++
 catalyst/targets/genbase.py|  58 +++
 catalyst/targets/generic_stage_target.py   | 167 +++--
 catalyst/targets/snapshot_target.py|  16 +-
 .../targets/{generic_target.py = targetbase.py}   |   6 +-
 6 files changed, 208 insertions(+), 156 deletions(-)

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index b36eff7..f6b2163 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -1,7 +1,7 @@
 
 
 # these should never be touched
-required_build_targets = [generic_target, generic_stage_target]
+required_build_targets = [targetbase, generic_stage_target]
 
 # new build types should be added here
 valid_build_targets = [stage1_target, stage2_target, stage3_target,

diff --git a/catalyst/targets/clearbase.py b/catalyst/targets/clearbase.py
new file mode 100644
index 000..8519acc
--- /dev/null
+++ b/catalyst/targets/clearbase.py
@@ -0,0 +1,115 @@
+
+import os
+import shutil
+from stat import ST_UID, ST_GID, ST_MODE
+
+
+from catalyst.support import cmd, countdown
+
+
+class ClearBase(object):
+   
+   This class does all of clearing after task completion
+   
+   def __init__(self, myspec):
+   self.settings = myspec
+
+
+
+   def clear_autoresume(self):
+Clean resume points since they are no longer needed 
+   if autoresume in self.settings[options]:
+   print Removing AutoResume Points: ...
+   myemp=self.settings[autoresume_path]
+   if os.path.isdir(myemp):
+   if autoresume in self.settings[options]:
+   print Emptying directory,myemp
+   
+   stat the dir, delete the dir, recreate the dir 
and set
+   the proper perms and ownership
+   
+   mystat=os.stat(myemp)
+   if os.uname()[0] == FreeBSD:
+   cmd(chflags -R noschg +myemp,\
+   Could not remove immutable 
flag for file \
+   +myemp)
+   #cmd(rm -rf +myemp, Could not remove 
existing file: +myemp,env-self.env)
+   shutil.rmtree(myemp)
+   os.makedirs(myemp,0755)
+   os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
+   os.chmod(myemp,mystat[ST_MODE])
+
+
+   def clear_chroot(self):
+   myemp=self.settings[chroot_path]
+   if os.path.isdir(myemp):
+   print Emptying directory,myemp
+   
+   stat the dir, delete the dir, recreate the dir and set
+   the proper perms and ownership
+   
+   mystat=os.stat(myemp)
+   #cmd(rm -rf +myemp, Could not remove existing file: 
+myemp,env=self.env)
+There's no easy way to change flags recursively in 
python 
+   if os.uname()[0] == FreeBSD:
+   os.system(chflags -R noschg +myemp)
+   shutil.rmtree(myemp)
+   os.makedirs(myemp,0755)
+   os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
+   os.chmod(myemp,mystat[ST_MODE])
+
+
+   def clear_packages(self):
+   if pkgcache in self.settings[options]:
+   print purging the pkgcache ...
+
+   myemp=self.settings[pkgcache_path]
+   if os.path.isdir(myemp):
+   print Emptying directory,myemp
+   
+   stat the dir, delete the dir, recreate the dir 
and set
+   the proper perms and ownership
+   
+   mystat=os.stat(myemp)
+   #cmd(rm -rf +myemp, Could not remove 
existing file: +myemp,env=self.env)
+   shutil.rmtree(myemp)
+   

[gentoo-commits] proj/catalyst:pending commit in: catalyst/targets/, catalyst/

2014-12-31 Thread Brian Dolbec
commit: 36610754ba2daca723064021001c5128d83e8f21
Author: Brian Dolbec dolsen AT gentoo DOT org
AuthorDate: Tue Feb 12 03:43:37 2013 +
Commit: Brian Dolbec dolsen AT gentoo DOT org
CommitDate: Thu Jan  1 05:58:05 2015 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=36610754

Remove redundant /bin/bash additions in cmd() calls

Remove old spawn_* functions copied from portage.
cmd() now uses subprocess.Popen().

---
 catalyst/support.py  | 301 +++
 catalyst/targets/generic_stage_target.py |  26 +--
 catalyst/targets/grp_target.py   |   2 +-
 catalyst/targets/netboot2_target.py  |   4 +-
 catalyst/targets/netboot_target.py   |   8 +-
 catalyst/targets/tinderbox_target.py |   2 +-
 6 files changed, 42 insertions(+), 301 deletions(-)

diff --git a/catalyst/support.py b/catalyst/support.py
index e2d64a1..aaacaa9 100644
--- a/catalyst/support.py
+++ b/catalyst/support.py
@@ -4,9 +4,10 @@ import string
 import os
 import types
 import re
-import signal
 import traceback
 import time
+from subprocess import Popen
+
 
 from catalyst.defaults import verbosity, valid_config_file_values
 
@@ -31,34 +32,6 @@ except:
 spawned_pids = []
 
 
-def cleanup(pids,block_exceptions=True):
-   function to go through and reap the list of pids passed to it
-   global spawned_pids
-   if type(pids) == int:
-   pids = [pids]
-   for x in pids:
-   try:
-   os.kill(x,signal.SIGTERM)
-   if os.waitpid(x,os.WNOHANG)[1] == 0:
-   # feisty bugger, still alive.
-   os.kill(x,signal.SIGKILL)
-   os.waitpid(x,0)
-   except OSError, oe:
-   if block_exceptions:
-   pass
-   if oe.errno not in (10,3):
-   raise oe
-   except SystemExit:
-   raise
-   except Exception:
-   if block_exceptions:
-   pass
-   try:
-   spawned_pids.remove(x)
-   except IndexError:
-   pass
-
-
 # a function to turn a string of non-printable characters
 # into a string of hex characters
 def hexify(str):
@@ -79,8 +52,8 @@ def read_from_clst(file):
return -1
#raise CatalystError, Could not open file +file
for line in myf.readlines():
-   #line = string.replace(line, \n, ) # drop newline
-   myline = myline + line
+   #line = string.replace(line, \n, ) # drop newline
+   myline = myline + line
myf.close()
return myline
 
@@ -145,259 +118,27 @@ def find_binary(myc):
return None
 
 
-def spawn_bash(mycommand,env={},debug=False,opt_name=None,**keywords):
-   spawn mycommand as an arguement to bash
-   args=[BASH_BINARY]
-   if not opt_name:
-   opt_name=mycommand.split()[0]
-   if BASH_ENV not in env:
-   env[BASH_ENV] = /etc/spork/is/not/valid/profile.env
-   if debug:
-   args.append(-x)
-   args.append(-c)
-   args.append(mycommand)
-   return spawn(args,env=env,opt_name=opt_name,**keywords)
-
-
-def spawn_get_output(mycommand,raw_exit_code=False,emulate_gso=True, \
-   collect_fds=[1],fd_pipes=None,**keywords):
-   call spawn, collecting the output to fd's specified in collect_fds 
list
-   emulate_gso is a compatability hack to emulate 
commands.getstatusoutput's return, minus the
-   requirement it always be a bash call (spawn_type controls the actual 
spawn call), and minus the
-   'lets let log only stdin and let stderr slide by'.
-
-   emulate_gso was deprecated from the day it was added, so convert your 
code over.
-   spawn_type is the passed in function to call- typically spawn_bash, 
spawn, spawn_sandbox, or spawn_fakeroot
-   global selinux_capable
-   pr,pw=os.pipe()
-
-   if fd_pipes==None:
-   fd_pipes={}
-   fd_pipes[0] = 0
-
-   for x in collect_fds:
-   fd_pipes[x] = pw
-   keywords[returnpid]=True
-
-   mypid=spawn_bash(mycommand,fd_pipes=fd_pipes,**keywords)
-   os.close(pw)
-   if type(mypid) != types.ListType:
-   os.close(pr)
-   return [mypid, %s: No such file or directory % 
mycommand.split()[0]]
-
-   fd=os.fdopen(pr,r)
-   mydata=fd.readlines()
-   fd.close()
-   if emulate_gso:
-   mydata=string.join(mydata)
-   if len(mydata) and mydata[-1] == \n:
-   mydata=mydata[:-1]
-   retval=os.waitpid(mypid[0],0)[1]
-   cleanup(mypid)
-   if raw_exit_code:
-

[gentoo-commits] proj/catalyst:pending commit in: catalyst/targets/, catalyst/base/

2014-12-31 Thread Brian Dolbec
commit: a1c2785438593104d7c3d2ec20dd4fb25cb19884
Author: Brian Dolbec dolsen AT gentoo DOT org
AuthorDate: Sat Jun  1 06:23:46 2013 +
Commit: Brian Dolbec dolsen AT gentoo DOT org
CommitDate: Thu Jan  1 05:58:07 2015 +
URL:
http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=a1c27854

Create AutoResume class to handle all file creation, deletion...

Create catalyst/base/resume.py.
Migrate all auto_resume operations to using the new class.

---
 catalyst/base/clearbase.py|  21 +
 catalyst/base/resume.py   | 166 ++
 catalyst/base/stagebase.py| 156 +++
 catalyst/targets/grp.py   |   4 +-
 catalyst/targets/livecd_stage1.py |   4 +-
 catalyst/targets/livecd_stage2.py |  14 ++--
 catalyst/targets/netboot2.py  |  19 +++--
 7 files changed, 250 insertions(+), 134 deletions(-)

diff --git a/catalyst/base/clearbase.py b/catalyst/base/clearbase.py
index 8462a3c..0ebe299 100644
--- a/catalyst/base/clearbase.py
+++ b/catalyst/base/clearbase.py
@@ -13,31 +13,14 @@ class ClearBase(object):

def __init__(self, myspec):
self.settings = myspec
-
+   self.resume = None
 
 
def clear_autoresume(self):
 Clean resume points since they are no longer needed 
if autoresume in self.settings[options]:
print Removing AutoResume Points: ...
-   myemp=self.settings[autoresume_path]
-   if os.path.isdir(myemp):
-   if autoresume in self.settings[options]:
-   print Emptying directory,myemp
-   
-   stat the dir, delete the dir, recreate the dir 
and set
-   the proper perms and ownership
-   
-   mystat=os.stat(myemp)
-   if os.uname()[0] == FreeBSD:
-   cmd(chflags -R noschg +myemp,\
-   Could not remove immutable 
flag for file \
-   +myemp)
-   #cmd(rm -rf +myemp, Could not remove 
existing file: +myemp,env-self.env)
-   shutil.rmtree(myemp)
-   ensure_dirs(myemp, 0755)
-   os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
-   os.chmod(myemp,mystat[ST_MODE])
+   self.resume.clear_all()
 
 
def clear_chroot(self):

diff --git a/catalyst/base/resume.py b/catalyst/base/resume.py
new file mode 100644
index 000..e42c7dc
--- /dev/null
+++ b/catalyst/base/resume.py
@@ -0,0 +1,166 @@
+#!/usr/bin/python
+
+# Maintained in full by:
+# Catalyst Team catal...@gentoo.org
+# Release Engineering Team rel...@gentoo.org
+# Copyright 2013 Brian Dolbec dol...@gentoo.org
+
+'''resume.py
+
+Performs autoresume tracking file operations such as
+set, unset, is_set, is_unset, enabled, clear_all
+'''
+
+import os
+import shutil
+from stat import ST_UID, ST_GID, ST_MODE
+import traceback
+
+from catalyst.fileops import ensure_dirs, pjoin, listdir_files
+from catalyst.support import touch
+
+
+class AutoResumeError(Exception):
+   def __init__(self, message, print_traceback=False):
+   if message:
+   if print_traceback:
+   (type,value)=sys.exc_info()[:2]
+   if value!=None:
+   print
+   print Traceback values found.  
listing...
+   print 
traceback.print_exc(file=sys.stdout)
+   print !!! catalyst: AutoResumeError  + message
+   print
+
+
+class AutoResume(object):
+   '''Class for tracking and handling all aspects of
+   the autoresume option and related files.
+   '''
+
+
+   def __init__(self, basedir, mode=0755):
+   self.basedir = basedir
+   ensure_dirs(basedir, mode=mode, fatal=True)
+   self._points = {}
+   self._init_points_()
+
+
+   def _init_points_(self):
+   '''Internal function which reads the autoresume directory and
+   for existing autoresume points and adds them to our _points 
variable
+   '''
+   existing = listdir_files(self.basedir, False)
+   for point in existing:
+   self._points[point] = pjoin(self.basedir, point)
+
+
+   def enable(self, point, data=None):
+   '''Sets the resume point 'ON'
+
+   @param point: string.  name of the resume point to enable
+   @param data: string of information to store, or None
+