From cbb0f65f5f9cabb55831f4dc018c6b5734403bef Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Sun, 13 Sep 2009 15:21:23 -0500 Subject: [PATCH] Create catalyst.util.move() helper and use it --- ChangeLog | 4 ++++ modules/catalyst/target/generic_stage.py | 10 ++++------ modules/catalyst/util.py | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index f926b6f9..6e71c06f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ # Distributed under the GPL v2 # $Id$ + 13 Sep 2009; Andrew Gaffney + modules/catalyst/target/generic_stage.py, modules/catalyst/util.py: + Create catalyst.util.move() helper and use it + 13 Sep 2009; Andrew Gaffney modules/catalyst/target/generic_stage.py, modules/catalyst/util.py: Add catalyst.util.copy() helper function and use it diff --git a/modules/catalyst/target/generic_stage.py b/modules/catalyst/target/generic_stage.py index 85708f4e..d5a1f37f 100644 --- a/modules/catalyst/target/generic_stage.py +++ b/modules/catalyst/target/generic_stage.py @@ -847,9 +847,8 @@ class generic_stage_target(generic_target): specialties in there """ if os.path.exists(self.settings["chroot_path"]+"/etc/hosts"): - cmd("mv "+self.settings["chroot_path"]+"/etc/hosts "+\ - self.settings["chroot_path"]+"/etc/hosts.catalyst",\ - "Could not backup /etc/hosts",env=self.env) + catalyst.util.move(self.settings["chroot_path"] + "/etc/hosts", \ + self.settings["chroot_path"] + "/etc/hosts.catalyst") catalyst.util.copy("/etc/hosts", self.settings["chroot_path"] + "/etc/hosts") """ Modify and write out make.conf (for the chroot) """ @@ -925,9 +924,8 @@ class generic_stage_target(generic_target): """ Put /etc/hosts back into place """ if os.path.exists(self.settings["chroot_path"]+"/etc/hosts.catalyst"): - cmd("mv -f "+self.settings["chroot_path"]+"/etc/hosts.catalyst "+\ - self.settings["chroot_path"]+"/etc/hosts",\ - "Could not replace /etc/hosts",env=self.env) + catalyst.util.move(self.settings["chroot_path"] + "/etc/hosts.catalyst", \ + self.settings["chroot_path"]+"/etc/hosts", force=True) """ Remove our overlay """ if os.path.exists(self.settings["chroot_path"]+"/usr/local/portage"): diff --git a/modules/catalyst/util.py b/modules/catalyst/util.py index e00ec558..10957668 100644 --- a/modules/catalyst/util.py +++ b/modules/catalyst/util.py @@ -283,4 +283,12 @@ def copy(src, dest, recursive=False): if retval != 0: raise CatalystError("Could not copy path '%s'" % (src,)) +def move(src, dest, force=False): + try: + if os.path.exists(dest): + remove_path(dest) + os.rename(src, dest) + except: + raise CatalystError("Could not rename '%s' to '%s'" % (src, dest)) + # vim: ts=4 sw=4 sta noet sts=4 ai -- 2.26.2