public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-catalyst] [PATCH 1/4] use native code in more places for file ops
@ 2016-05-20 14:27 Mike Frysinger
  2016-05-20 14:27 ` [gentoo-catalyst] [PATCH 2/4] cmd: add support for running commands directly Mike Frysinger
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Mike Frysinger @ 2016-05-20 14:27 UTC (permalink / raw
  To: gentoo-catalyst

Rather than shell out to cp/rm/mv, use python native code to do things.
---
 catalyst/base/stagebase.py | 39 +++++++++++++++------------------------
 1 file changed, 15 insertions(+), 24 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 2009ab6..0b25516 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1013,8 +1013,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
 		else:
 			log.notice('Setting up chroot...')
 
-			cmd("cp /etc/resolv.conf " + self.settings["chroot_path"] + "/etc/",
-				env=self.env)
+			shutil.copy('/etc/resolv.conf', self.settings['chroot_path'] + '/etc/')
 
 			# Copy over the envscript, if applicable
 			if "envscript" in self.settings:
@@ -1030,18 +1029,15 @@ class StageBase(TargetBase, ClearBase, GenBase):
 					'Catalyst Maintainers use VERY minimal envscripts, if used at all.\n'
 					'You have been warned.')
 
-				cmd("cp "+self.settings["envscript"]+" "+\
-					self.settings["chroot_path"]+"/tmp/envscript",\
-					env=self.env)
+				shutil.copy(self.settings['envscript'],
+					self.settings['chroot_path'] + '/tmp/envscript')
 
 			# Copy over /etc/hosts from the host in case there are any
 			# 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",\
-					env=self.env)
-				cmd("cp /etc/hosts "+self.settings["chroot_path"]+"/etc/hosts",\
-					env=self.env)
+			hosts_file = self.settings['chroot_path'] + '/etc/hosts'
+			if os.path.exists(hosts_file):
+				os.rename(hosts_file, hosts_file + '.catalyst')
+				shutil.copy('/etc/hosts', hosts_file)
 
 			# Modify and write out make.conf (for the chroot)
 			makepath = normpath(self.settings["chroot_path"] +
@@ -1162,10 +1158,9 @@ class StageBase(TargetBase, ClearBase, GenBase):
 				clear_path(self.settings["destpath"] + x)
 
 		# 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",\
-				env=self.env)
+		hosts_file = self.settings['chroot_path'] + '/etc/hosts'
+		if os.path.exists(hosts_file + '.catalyst'):
+			os.rename(hosts_file + '.catalyst', hosts_file)
 
 		# Remove our overlay
 		if os.path.exists(self.settings["chroot_path"] + self.settings["local_overlay"]):
@@ -1565,11 +1560,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
 			env=self.env)
 
 		if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings:
-			if os.path.exists(self.settings["chroot_path"]+\
-				"/tmp/initramfs_overlay/"):
-				log.notice('Cleaning up temporary overlay dir')
-				cmd("rm -R "+self.settings["chroot_path"]+\
-					"/tmp/initramfs_overlay/",env=self.env)
+			log.notice('Cleaning up temporary overlay dir')
+			clear_dir(self.settings['chroot_path'] + '/tmp/initramfs_overlay/')
 
 		self.resume.is_enabled("build_kernel_"+kname)
 
@@ -1586,11 +1578,10 @@ class StageBase(TargetBase, ClearBase, GenBase):
 					self.settings[key])
 
 			try:
-				cmd('cp ' + self.settings[key] + ' ' +
-					self.settings['chroot_path'] + '/var/tmp/' + kname + '.config',
-					env=self.env)
+				shutil.copy(self.settings[key],
+					self.settings['chroot_path'] + '/var/tmp/' + kname + '.config')
 
-			except CatalystError:
+			except IOError:
 				self.unbind()
 
 	def _copy_initramfs_overlay(self, kname):
-- 
2.8.2



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-05-20 15:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-20 14:27 [gentoo-catalyst] [PATCH 1/4] use native code in more places for file ops Mike Frysinger
2016-05-20 14:27 ` [gentoo-catalyst] [PATCH 2/4] cmd: add support for running commands directly Mike Frysinger
2016-05-20 15:48   ` Brian Dolbec
2016-05-20 14:27 ` [gentoo-catalyst] [PATCH 3/4] replace ad-hoc implementations of clear_dir Mike Frysinger
2016-05-20 15:49   ` Brian Dolbec
2016-05-20 14:27 ` [gentoo-catalyst] [PATCH 4/4] replace os.system with cmd Mike Frysinger
2016-05-20 15:51   ` Brian Dolbec
2016-05-20 15:46 ` [gentoo-catalyst] [PATCH 1/4] use native code in more places for file ops Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox