From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id F3F59138262 for ; Fri, 20 May 2016 14:27:54 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 854BD2240E8; Fri, 20 May 2016 14:27:50 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 29AC72240E2 for ; Fri, 20 May 2016 14:27:50 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id DC6553409B7 for ; Fri, 20 May 2016 14:27:48 +0000 (UTC) From: Mike Frysinger 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 Message-Id: <1463754466-15028-1-git-send-email-vapier@gentoo.org> X-Mailer: git-send-email 2.8.2 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-catalyst@lists.gentoo.org Reply-to: gentoo-catalyst@lists.gentoo.org X-Archives-Salt: 5ca6189d-66c9-4130-90dd-59692627f978 X-Archives-Hash: ba3a739464cc1b05cccb16d8375952bf 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