# Distributed under the GPL v2
# $Id$
+ 13 Sep 2009; Andrew Gaffney <agaffney@gentoo.org>
+ modules/catalyst/target/generic_stage.py,
+ modules/catalyst/target/livecd_stage1.py,
+ modules/catalyst/target/livecd_stage2.py,
+ modules/catalyst/target/netboot.py, modules/catalyst/util.py:
+ Modify code to use catalyst.util.remove_path() helper everywhere
+ Include globbing support in remove_path()
+ Create catalyst.util.create_symlink() helper and modify code to use it
+
13 Sep 2009; Andrew Gaffney <agaffney@gentoo.org>
modules/catalyst/util.py:
Add catalyst.util.remove_dir() helper function
self.snapshot_lock_object.write_lock()
if os.path.exists(destdir):
msg(cleanup_msg)
- cleanup_cmd="rm -rf "+destdir
- cmd(cleanup_cmd,cleanup_errmsg,env=self.env)
+ catalyst.util.remove_path(destdir)
if not os.path.exists(destdir):
os.makedirs(destdir,0755)
# TODO: zmedico and I discussed making this a directory and pushing
# in a parent file, as well as other user-specified configuration.
msg("Configuring profile link...")
- cmd("rm -f "+self.settings["chroot_path"]+"/etc/make.profile",\
- "Error zapping profile link",env=self.env)
- cmd("ln -sf ../usr/portage/profiles/"+\
- self.settings["target_profile"]+" "+\
- self.settings["chroot_path"]+"/etc/make.profile",\
- "Error creating profile link",env=self.env)
+ catalyst.util.create_symlink("../usr/portage/profiles/" + self.settings["target_profile"], \
+ self.settings["chroot_path"] + "/etc/make.profile", True)
self.set_autoresume("config_profile_link")
def setup_confdir(self):
else:
if "portage_confdir" in self.settings:
msg("Configuring /etc/portage...")
- cmd("rm -rf "+self.settings["chroot_path"]+"/etc/portage",\
- "Error zapping /etc/portage",env=self.env)
+ catalyst.util.remove_path(self.settings["chroot_path"] + "/etc/portage")
cmd("cp -R "+self.settings["portage_confdir"]+"/ "+\
self.settings["chroot_path"]+"/etc/portage",\
"Error copying /etc/portage",env=self.env)
"Could not copy /etc/hosts",env=self.env)
""" Modify and write out make.conf (for the chroot) """
- cmd("rm -f "+self.settings["chroot_path"]+"/etc/make.conf",\
- "Could not remove "+self.settings["chroot_path"]+\
- "/etc/make.conf",env=self.env)
+ catalyst.util.remove_path(self.settings["chroot_path"] + "/etc/make.conf")
myf=open(self.settings["chroot_path"]+"/etc/make.conf","w")
myf.write("# These settings were set by the catalyst build script that automatically\n# built this stage.\n")
myf.write("# Please consult /usr/share/portage/config/make.conf.example for a more\n# detailed example.\n")
else:
for x in self.settings["cleanables"]:
msg("Cleaning chroot: " + x +"...")
- cmd("rm -rf "+self.settings["destpath"]+x,"Couldn't clean "+\
- x,env=self.env)
+ catalyst.util.remove_path(self.settings["destpath"] + x)
""" Put /etc/hosts back into place """
if os.path.exists(self.settings["chroot_path"]+"/etc/hosts.catalyst"):
""" Remove our overlay """
if os.path.exists(self.settings["chroot_path"]+"/usr/local/portage"):
- cmd("rm -rf "+self.settings["chroot_path"]+"/usr/local/portage",\
- "Could not remove /usr/local/portage",env=self.env)
+ catalyst.util.remove_path(self.settings["chroot_path"] + "/usr/local/portage")
cmd("sed -i '/^PORTDIR_OVERLAY/d' "+self.settings["chroot_path"]+\
"/etc/make.conf",\
"Could not remove PORTDIR_OVERLAY from make.conf",env=self.env)
operations, so we get easy glob handling.
"""
msg("livecd: removing " + x)
- os.system("rm -rf "+self.settings["chroot_path"]+x)
+ try:
+ catalyst.util.remove_path(self.settings["chroot_path"] + x)
+ except:
+ pass
try:
self.run_controller_action("clean")
self.set_autoresume("remove")
if os.path.exists(self.settings["chroot_path"]+\
"/tmp/initramfs_overlay/"):
msg("Cleaning up temporary overlay dir")
- cmd("rm -R "+self.settings["chroot_path"]+\
- "/tmp/initramfs_overlay/",env=self.env)
+ catalyst.util.remove_path(self.settings["chroot_path"] + \
+ "/tmp/initramfs_overlay/")
self.set_autoresume("build_kernel_" + kname)
else:
# first clean up any existing target stuff
if os.path.exists(self.settings["target_path"]):
- cmd("rm -rf "+self.settings["target_path"],\
- "Could not remove existing directory: "+self.settings["target_path"],env=self.env)
- self.set_autoresume("setup_target_path")
+ catalyst.util.remove_path(self.settings["target_path"])
if not os.path.exists(self.settings["target_path"]):
os.makedirs(self.settings["target_path"])
+ self.set_autoresume("setup_target_path")
def set_target_path(self):
pass
else:
# first clean up any existing target stuff
if os.path.isdir(self.settings["target_path"]):
- cmd("rm -rf "+self.settings["target_path"],
- "Could not remove existing directory: "+self.settings["target_path"],env=self.env)
- self.set_autoresume("setup_target_path")
+ catalyst.util.remove_path(self.settings["target_path"])
if not os.path.exists(self.settings["target_path"]):
os.makedirs(self.settings["target_path"])
+ self.set_autoresume("setup_target_path")
+
def run_local(self):
# what modules do we want to blacklist?
if "livecd/modblacklist" in self.settings:
else:
# first clean up any existing target stuff
if os.path.isfile(self.settings["target_path"]):
- cmd("rm -f "+self.settings["target_path"], \
- "Could not remove existing file: "+self.settings["target_path"],env=self.env)
- self.set_autoresume("setup_target_path")
+ catalyst.util.remove_path(self.settings["target_path"])
- if not os.path.exists(self.settings["storedir"]+"/builds/"):
- os.makedirs(self.settings["storedir"]+"/builds/")
+ if not os.path.exists(self.settings["storedir"]+"/builds/"):
+ os.makedirs(self.settings["storedir"]+"/builds/")
+
+ self.set_autoresume("setup_target_path")
def copy_files_to_image(self):
# copies specific files from the buildroot to merge_path
else:
if "rm" in self.settings:
for x in self.settings["rm"]:
- # we're going to shell out for all these cleaning operations,
- # so we get easy glob handling
msg("netboot: removing " + x)
- os.system("rm -rf " + self.settings["chroot_path"] + self.settings["merge_path"] + x)
+ catalyst.util.remove_path(self.settings["chroot_path"] + self.settings["merge_path"] + x)
def empty(self):
if self.check_autoresume("empty"):
Collection of utility functions for catalyst
"""
-import sys, traceback, os, re, time, shutil
+import sys, traceback, os, re, time, shutil, glob
import catalyst
from catalyst.error import *
from catalyst.output import *
if not x in myspec:
raise CatalystError, "Required argument \""+x+"\" not specified."
-def remove_dir(path):
- if os.uname()[0] == "FreeBSD":
- cmd("chflags -R noschg " + path, \
- "Could not remove immutable flag for file " \
- + path)
- try:
- shutil.rmtree(path)
- except:
- raise CatalystError("Could not remove directory '%s'" % (path,))
+def remove_path(path, glob=True):
+ paths = None
+ if glob:
+ paths = glob.glob(path)
+ else:
+ paths = [path]
+ for x in paths:
+ if os.uname()[0] == "FreeBSD":
+ cmd("chflags -R noschg " + x, \
+ "Could not remove immutable flag for path " \
+ + x)
+ if os.path.is_dir(x):
+ try:
+ shutil.rmtree(x)
+ except:
+ raise CatalystError("Could not remove directory '%s'" % (x,))
+ else:
+ try:
+ os.remove(x)
+ except:
+ raise CatalystError("Could not remove file '%s'" % (x,))
def empty_dir(path):
try:
mystat = os.stat(path)
- remove_dir(path)
+ remove_path(path, False)
os.makedirs(path, 0755)
os.chown(path, mystat[stat.ST_UID], mystat[stat.ST_GID])
os.chmod(path, mystat[stat.ST_MODE])
except:
raise CatalystError("Could not empty directory '%s'" % (path,))
+def create_symlink(src, dest, remove_existing=False):
+ if os.path.exists(dest):
+ if remove_existing:
+ remove_path(dest)
+ else:
+ raise CatalystError("Could not create symlink at '%s' due to existing file" % (dest,))
+ try:
+ os.symlink(src, dest)
+ except:
+ raise CatalystError("Could not create symlink '%s' to '%s'" % (dest, src))
# vim: ts=4 sw=4 sta noet sts=4 ai