public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: gentoo-catalyst@lists.gentoo.org
Subject: [gentoo-catalyst] [PATCH 1/4] use native code in more places for file ops
Date: Fri, 20 May 2016 10:27:43 -0400	[thread overview]
Message-ID: <1463754466-15028-1-git-send-email-vapier@gentoo.org> (raw)

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



             reply	other threads:[~2016-05-20 14:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-20 14:27 Mike Frysinger [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1463754466-15028-1-git-send-email-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gentoo-catalyst@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox