Create catalyst.util.move() helper and use it
authorAndrew Gaffney <agaffney@gentoo.org>
Sun, 13 Sep 2009 20:21:23 +0000 (15:21 -0500)
committerAndrew Gaffney <agaffney@gentoo.org>
Sun, 13 Sep 2009 20:21:23 +0000 (15:21 -0500)
ChangeLog
modules/catalyst/target/generic_stage.py
modules/catalyst/util.py

index f926b6f937e06d80cdb2a473774a93bad7483c91..6e71c06fc320f9fef60df09301a45432da2db2af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,10 @@
 # Distributed under the GPL v2
 # $Id$
 
+  13 Sep 2009; Andrew Gaffney <agaffney@gentoo.org>
+  modules/catalyst/target/generic_stage.py, modules/catalyst/util.py:
+  Create catalyst.util.move() helper and use it
+
   13 Sep 2009; Andrew Gaffney <agaffney@gentoo.org>
   modules/catalyst/target/generic_stage.py, modules/catalyst/util.py:
   Add catalyst.util.copy() helper function and use it
index 85708f4e16cca6ba664a3bee7424abdede6d0f62..d5a1f37f7fe38d5e6ef66538f79f56817b2ada66 100644 (file)
@@ -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"):
index e00ec558f4709a31825202576261174fa029d63f..1095766874287bfa4f0c57ee97128600665eec3a 100644 (file)
@@ -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