From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id AED481382C5 for ; Thu, 28 Jan 2021 02:09:36 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E3D6EE09C2; Thu, 28 Jan 2021 02:09:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B983FE09C2 for ; Thu, 28 Jan 2021 02:09:35 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 54F38340C59 for ; Thu, 28 Jan 2021 02:09:34 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A83754AD for ; Thu, 28 Jan 2021 02:09:32 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1611799606.50ba8aadf5f7096e9079eafec9182d526956cd49.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/targets/, catalyst/, catalyst/base/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/base/stagebase.py catalyst/main.py catalyst/support.py catalyst/targets/livecd_stage2.py catalyst/targets/netboot.py catalyst/targets/snapshot.py X-VCS-Directories: catalyst/base/ catalyst/targets/ catalyst/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: 50ba8aadf5f7096e9079eafec9182d526956cd49 X-VCS-Branch: pending/mattst88 Date: Thu, 28 Jan 2021 02:09:32 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: a2542048-ab04-41f7-8f6b-d99dd77b07bb X-Archives-Hash: cc165a01d093edb97bb3fe51f8ee4dc3 commit: 50ba8aadf5f7096e9079eafec9182d526956cd49 Author: Matt Turner gentoo org> AuthorDate: Sun Jan 24 02:43:47 2021 +0000 Commit: Matt Turner gentoo org> CommitDate: Thu Jan 28 02:06:46 2021 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=50ba8aad catalyst: Clean up exception handling Use 'raise from' where sensible, but a lot of the CatalystErrors are just trading one CatalystError for another, so remove them. Signed-off-by: Matt Turner gentoo.org> catalyst/base/stagebase.py | 110 ++++++++++++++------------------------ catalyst/main.py | 4 +- catalyst/support.py | 4 +- catalyst/targets/livecd_stage2.py | 4 +- catalyst/targets/netboot.py | 33 ++++-------- catalyst/targets/snapshot.py | 2 +- 6 files changed, 57 insertions(+), 100 deletions(-) diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index 28ff8fd2..46cb1fda 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -906,7 +906,7 @@ class StageBase(TargetBase, ClearBase, GenBase): fstype=fstype, options=options) cxt.mount() except Exception as e: - raise CatalystError(f"Couldn't mount: {source}, {e}") + raise CatalystError(f"Couldn't mount: {source}, {e}") from e def chroot_setup(self): self.makeconf = read_makeconf(normpath(self.settings["chroot_path"] + @@ -978,7 +978,7 @@ class StageBase(TargetBase, ClearBase, GenBase): except OSError as e: raise CatalystError('Could not write %s: %s' % ( normpath(self.settings["chroot_path"] + - self.settings["make_conf"]), e)) + self.settings["make_conf"]), e)) from e self.resume.enable("chroot_setup") def write_make_conf(self, setup=True): @@ -1206,13 +1206,11 @@ class StageBase(TargetBase, ClearBase, GenBase): # operations, so we get easy glob handling. log.notice('%s: removing %s', self.settings["spec_prefix"], x) clear_path(self.settings["stage_path"] + x) - try: - if os.path.exists(self.settings["controller_file"]): - cmd([self.settings['controller_file'], 'clean'], - env=self.env) - self.resume.enable("remove") - except: - raise + + if os.path.exists(self.settings["controller_file"]): + cmd([self.settings['controller_file'], 'clean'], + env=self.env) + self.resume.enable("remove") def preclean(self): if "autoresume" in self.settings["options"] \ @@ -1278,19 +1276,14 @@ class StageBase(TargetBase, ClearBase, GenBase): log.notice('Resume point detected, skipping run_local operation...') return - try: - if os.path.exists(self.settings["controller_file"]): - log.info('run_local() starting controller script...') - cmd([self.settings['controller_file'], 'run'], - env=self.env) - self.resume.enable("run_local") - else: - log.info('run_local() no controller_file found... %s', - self.settings['controller_file']) - - except CatalystError: - raise CatalystError("Stage build aborting due to error.", - print_traceback=False) + if os.path.exists(self.settings["controller_file"]): + log.info('run_local() starting controller script...') + cmd([self.settings['controller_file'], 'run'], + env=self.env) + self.resume.enable("run_local") + else: + log.info('run_local() no controller_file found... %s', + self.settings['controller_file']) def setup_environment(self): log.debug('setup_environment(); settings = %r', self.settings) @@ -1382,13 +1375,10 @@ class StageBase(TargetBase, ClearBase, GenBase): [self.settings[self.settings["spec_prefix"] + "/unmerge"]] # Before cleaning, unmerge stuff - try: - cmd([self.settings['controller_file'], 'unmerge'] + - self.settings[self.settings['spec_prefix'] + '/unmerge'], - env=self.env) - log.info('unmerge shell script') - except CatalystError: - raise + cmd([self.settings['controller_file'], 'unmerge'] + + self.settings[self.settings['spec_prefix'] + '/unmerge'], + env=self.env) + log.info('unmerge shell script') self.resume.enable("unmerge") def target_setup(self): @@ -1457,14 +1447,9 @@ class StageBase(TargetBase, ClearBase, GenBase): command.append(self.settings[target_pkgs]) else: command.extend(self.settings[target_pkgs]) - try: - cmd(command, env=self.env) - fileutils.touch(build_packages_resume) - self.resume.enable("build_packages") - except CatalystError: - raise CatalystError( - self.settings["spec_prefix"] + - "build aborting due to error.") + cmd(command, env=self.env) + fileutils.touch(build_packages_resume) + self.resume.enable("build_packages") def build_kernel(self): '''Build all configured kernels''' @@ -1475,19 +1460,14 @@ class StageBase(TargetBase, ClearBase, GenBase): return if "boot/kernel" in self.settings: - try: - mynames = self.settings["boot/kernel"] - if isinstance(mynames, str): - mynames = [mynames] - # Execute the script that sets up the kernel build environment - cmd([self.settings['controller_file'], 'pre-kmerge'], env=self.env) - for kname in [sanitize_name(name) for name in mynames]: - self._build_kernel(kname=kname) - self.resume.enable("build_kernel") - except CatalystError: - raise CatalystError( - "build aborting due to kernel build error.", - print_traceback=True) + mynames = self.settings["boot/kernel"] + if isinstance(mynames, str): + mynames = [mynames] + # Execute the script that sets up the kernel build environment + cmd([self.settings['controller_file'], 'pre-kmerge'], env=self.env) + for kname in [sanitize_name(name) for name in mynames]: + self._build_kernel(kname=kname) + self.resume.enable("build_kernel") def _build_kernel(self, kname): "Build a single configured kernel by name" @@ -1531,12 +1511,8 @@ class StageBase(TargetBase, ClearBase, GenBase): raise CatalystError("Can't find kernel config: %s" % self.settings[key]) - try: - shutil.copy(self.settings[key], - self.settings['chroot_path'] + '/var/tmp/' + kname + '.config') - - except IOError: - raise + shutil.copy(self.settings[key], + self.settings['chroot_path'] + '/var/tmp/' + kname + '.config') def _copy_initramfs_overlay(self, kname): key = 'boot/kernel/' + kname + '/initramfs_overlay' @@ -1560,13 +1536,10 @@ class StageBase(TargetBase, ClearBase, GenBase): 'Resume point detected, skipping bootloader operation...') return - try: - cmd([self.settings['controller_file'], 'bootloader', - self.settings['target_path'].rstrip('/')], - env=self.env) - self.resume.enable("bootloader") - except CatalystError: - raise CatalystError("Script aborting due to error.") + cmd([self.settings['controller_file'], 'bootloader', + self.settings['target_path'].rstrip('/')], + env=self.env) + self.resume.enable("bootloader") def livecd_update(self): if "autoresume" in self.settings["options"] \ @@ -1575,14 +1548,9 @@ class StageBase(TargetBase, ClearBase, GenBase): 'Resume point detected, skipping build_packages operation...') return - try: - cmd([self.settings['controller_file'], 'livecd-update'], - env=self.env) - self.resume.enable("livecd_update") - - except CatalystError: - raise CatalystError( - "build aborting due to livecd_update error.") + cmd([self.settings['controller_file'], 'livecd-update'], + env=self.env) + self.resume.enable("livecd_update") @staticmethod def _debug_pause_(): diff --git a/catalyst/main.py b/catalyst/main.py index b0d9015f..0de1040f 100644 --- a/catalyst/main.py +++ b/catalyst/main.py @@ -77,10 +77,10 @@ def build_target(addlargs): target = addlargs["target"].replace('-', '_') module = import_module(target) target = getattr(module, target)(conf_values, addlargs) - except AttributeError: + except AttributeError as e: raise CatalystError( "Target \"%s\" not available." % target, - print_traceback=True) + print_traceback=True) from e except CatalystError: return False return target.run() diff --git a/catalyst/support.py b/catalyst/support.py index fa652987..fc50fa34 100644 --- a/catalyst/support.py +++ b/catalyst/support.py @@ -140,9 +140,9 @@ def read_makeconf(mymakeconffile): if os.path.exists(mymakeconffile): try: return read_bash_dict(mymakeconffile, sourcing_command="source") - except Exception: + except Exception as e: raise CatalystError("Could not parse make.conf file " + - mymakeconffile, print_traceback=True) + mymakeconffile, print_traceback=True) from e else: makeconf = {} return makeconf diff --git a/catalyst/targets/livecd_stage2.py b/catalyst/targets/livecd_stage2.py index e90e9f53..ff4ea62a 100644 --- a/catalyst/targets/livecd_stage2.py +++ b/catalyst/targets/livecd_stage2.py @@ -79,11 +79,11 @@ class livecd_stage2(StageBase): "livecd/modblacklist"].split() for x in self.settings["livecd/modblacklist"]: myf.write("\nblacklist "+x) - except: + except Exception as e: raise CatalystError("Couldn't open " + self.settings["chroot_path"] + "/etc/modprobe.d/blacklist.conf.", - print_traceback=True) + print_traceback=True) from e def set_action_sequence(self): self.build_sequence.extend([ diff --git a/catalyst/targets/netboot.py b/catalyst/targets/netboot.py index a2a9fcb3..38d0cb45 100644 --- a/catalyst/targets/netboot.py +++ b/catalyst/targets/netboot.py @@ -30,17 +30,14 @@ class netboot(StageBase): ]) def __init__(self, spec, addlargs): - try: - if "netboot/packages" in addlargs: - if isinstance(addlargs['netboot/packages'], str): - loopy = [addlargs["netboot/packages"]] - else: - loopy = addlargs["netboot/packages"] + if "netboot/packages" in addlargs: + if isinstance(addlargs['netboot/packages'], str): + loopy = [addlargs["netboot/packages"]] + else: + loopy = addlargs["netboot/packages"] - for x in loopy: - self.valid_values |= {"netboot/packages/"+x+"/files"} - except: - raise CatalystError("configuration error in netboot/packages.") + for x in loopy: + self.valid_values |= {"netboot/packages/"+x+"/files"} StageBase.__init__(self, spec, addlargs) self.settings["merge_path"] = normpath("/tmp/image/") @@ -89,12 +86,8 @@ class netboot(StageBase): else: myfiles.append(self.settings["netboot/extra_files"]) - try: - cmd([self.settings['controller_file'], 'image'] + - myfiles, env=self.env) - except CatalystError: - raise CatalystError("Failed to copy files to image!", - print_traceback=True) + cmd([self.settings['controller_file'], 'image'] + + myfiles, env=self.env) self.resume.enable("copy_files_to_image") @@ -116,12 +109,8 @@ class netboot(StageBase): # we're done, move the kernels to builds/* # no auto resume here as we always want the # freshest images moved - try: - cmd([self.settings['controller_file'], 'final'], env=self.env) - log.notice('Netboot Build Finished!') - except CatalystError: - raise CatalystError("Failed to move kernel images!", - print_traceback=True) + cmd([self.settings['controller_file'], 'final'], env=self.env) + log.notice('Netboot Build Finished!') def remove(self): if "autoresume" in self.settings["options"] \ diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py index 7732312c..6b727600 100644 --- a/catalyst/targets/snapshot.py +++ b/catalyst/targets/snapshot.py @@ -73,7 +73,7 @@ class snapshot(TargetBase): except subprocess.CalledProcessError as e: raise CatalystError(f'{e.cmd} failed with return code' f'{e.returncode}\n' - f'{e.output}\n') + f'{e.output}\n') from e def run(self): if self.settings['snapshot_treeish'] == 'stable': From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 09B6C1382C5 for ; Thu, 28 Jan 2021 02:41:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 39D03E0A87; Thu, 28 Jan 2021 02:41:46 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 15F7AE0A87 for ; Thu, 28 Jan 2021 02:41:46 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DE9933410CE for ; Thu, 28 Jan 2021 02:41:43 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 43E9F4AD for ; Thu, 28 Jan 2021 02:41:42 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1611799606.50ba8aadf5f7096e9079eafec9182d526956cd49.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/, catalyst/targets/, catalyst/base/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/base/stagebase.py catalyst/main.py catalyst/support.py catalyst/targets/livecd_stage2.py catalyst/targets/netboot.py catalyst/targets/snapshot.py X-VCS-Directories: catalyst/targets/ catalyst/base/ catalyst/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: 50ba8aadf5f7096e9079eafec9182d526956cd49 X-VCS-Branch: master Date: Thu, 28 Jan 2021 02:41:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 4744a644-f6a2-41d2-9daf-4af1990ce104 X-Archives-Hash: 12cd2eb5c7435ae2effb905bcdf3655b Message-ID: <20210128024142.k8tuqqJ-1PcyabRAgvAuG90ybSm7blvTMiY4C3eUzUY@z> commit: 50ba8aadf5f7096e9079eafec9182d526956cd49 Author: Matt Turner gentoo org> AuthorDate: Sun Jan 24 02:43:47 2021 +0000 Commit: Matt Turner gentoo org> CommitDate: Thu Jan 28 02:06:46 2021 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=50ba8aad catalyst: Clean up exception handling Use 'raise from' where sensible, but a lot of the CatalystErrors are just trading one CatalystError for another, so remove them. Signed-off-by: Matt Turner gentoo.org> catalyst/base/stagebase.py | 110 ++++++++++++++------------------------ catalyst/main.py | 4 +- catalyst/support.py | 4 +- catalyst/targets/livecd_stage2.py | 4 +- catalyst/targets/netboot.py | 33 ++++-------- catalyst/targets/snapshot.py | 2 +- 6 files changed, 57 insertions(+), 100 deletions(-) diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index 28ff8fd2..46cb1fda 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -906,7 +906,7 @@ class StageBase(TargetBase, ClearBase, GenBase): fstype=fstype, options=options) cxt.mount() except Exception as e: - raise CatalystError(f"Couldn't mount: {source}, {e}") + raise CatalystError(f"Couldn't mount: {source}, {e}") from e def chroot_setup(self): self.makeconf = read_makeconf(normpath(self.settings["chroot_path"] + @@ -978,7 +978,7 @@ class StageBase(TargetBase, ClearBase, GenBase): except OSError as e: raise CatalystError('Could not write %s: %s' % ( normpath(self.settings["chroot_path"] + - self.settings["make_conf"]), e)) + self.settings["make_conf"]), e)) from e self.resume.enable("chroot_setup") def write_make_conf(self, setup=True): @@ -1206,13 +1206,11 @@ class StageBase(TargetBase, ClearBase, GenBase): # operations, so we get easy glob handling. log.notice('%s: removing %s', self.settings["spec_prefix"], x) clear_path(self.settings["stage_path"] + x) - try: - if os.path.exists(self.settings["controller_file"]): - cmd([self.settings['controller_file'], 'clean'], - env=self.env) - self.resume.enable("remove") - except: - raise + + if os.path.exists(self.settings["controller_file"]): + cmd([self.settings['controller_file'], 'clean'], + env=self.env) + self.resume.enable("remove") def preclean(self): if "autoresume" in self.settings["options"] \ @@ -1278,19 +1276,14 @@ class StageBase(TargetBase, ClearBase, GenBase): log.notice('Resume point detected, skipping run_local operation...') return - try: - if os.path.exists(self.settings["controller_file"]): - log.info('run_local() starting controller script...') - cmd([self.settings['controller_file'], 'run'], - env=self.env) - self.resume.enable("run_local") - else: - log.info('run_local() no controller_file found... %s', - self.settings['controller_file']) - - except CatalystError: - raise CatalystError("Stage build aborting due to error.", - print_traceback=False) + if os.path.exists(self.settings["controller_file"]): + log.info('run_local() starting controller script...') + cmd([self.settings['controller_file'], 'run'], + env=self.env) + self.resume.enable("run_local") + else: + log.info('run_local() no controller_file found... %s', + self.settings['controller_file']) def setup_environment(self): log.debug('setup_environment(); settings = %r', self.settings) @@ -1382,13 +1375,10 @@ class StageBase(TargetBase, ClearBase, GenBase): [self.settings[self.settings["spec_prefix"] + "/unmerge"]] # Before cleaning, unmerge stuff - try: - cmd([self.settings['controller_file'], 'unmerge'] + - self.settings[self.settings['spec_prefix'] + '/unmerge'], - env=self.env) - log.info('unmerge shell script') - except CatalystError: - raise + cmd([self.settings['controller_file'], 'unmerge'] + + self.settings[self.settings['spec_prefix'] + '/unmerge'], + env=self.env) + log.info('unmerge shell script') self.resume.enable("unmerge") def target_setup(self): @@ -1457,14 +1447,9 @@ class StageBase(TargetBase, ClearBase, GenBase): command.append(self.settings[target_pkgs]) else: command.extend(self.settings[target_pkgs]) - try: - cmd(command, env=self.env) - fileutils.touch(build_packages_resume) - self.resume.enable("build_packages") - except CatalystError: - raise CatalystError( - self.settings["spec_prefix"] + - "build aborting due to error.") + cmd(command, env=self.env) + fileutils.touch(build_packages_resume) + self.resume.enable("build_packages") def build_kernel(self): '''Build all configured kernels''' @@ -1475,19 +1460,14 @@ class StageBase(TargetBase, ClearBase, GenBase): return if "boot/kernel" in self.settings: - try: - mynames = self.settings["boot/kernel"] - if isinstance(mynames, str): - mynames = [mynames] - # Execute the script that sets up the kernel build environment - cmd([self.settings['controller_file'], 'pre-kmerge'], env=self.env) - for kname in [sanitize_name(name) for name in mynames]: - self._build_kernel(kname=kname) - self.resume.enable("build_kernel") - except CatalystError: - raise CatalystError( - "build aborting due to kernel build error.", - print_traceback=True) + mynames = self.settings["boot/kernel"] + if isinstance(mynames, str): + mynames = [mynames] + # Execute the script that sets up the kernel build environment + cmd([self.settings['controller_file'], 'pre-kmerge'], env=self.env) + for kname in [sanitize_name(name) for name in mynames]: + self._build_kernel(kname=kname) + self.resume.enable("build_kernel") def _build_kernel(self, kname): "Build a single configured kernel by name" @@ -1531,12 +1511,8 @@ class StageBase(TargetBase, ClearBase, GenBase): raise CatalystError("Can't find kernel config: %s" % self.settings[key]) - try: - shutil.copy(self.settings[key], - self.settings['chroot_path'] + '/var/tmp/' + kname + '.config') - - except IOError: - raise + shutil.copy(self.settings[key], + self.settings['chroot_path'] + '/var/tmp/' + kname + '.config') def _copy_initramfs_overlay(self, kname): key = 'boot/kernel/' + kname + '/initramfs_overlay' @@ -1560,13 +1536,10 @@ class StageBase(TargetBase, ClearBase, GenBase): 'Resume point detected, skipping bootloader operation...') return - try: - cmd([self.settings['controller_file'], 'bootloader', - self.settings['target_path'].rstrip('/')], - env=self.env) - self.resume.enable("bootloader") - except CatalystError: - raise CatalystError("Script aborting due to error.") + cmd([self.settings['controller_file'], 'bootloader', + self.settings['target_path'].rstrip('/')], + env=self.env) + self.resume.enable("bootloader") def livecd_update(self): if "autoresume" in self.settings["options"] \ @@ -1575,14 +1548,9 @@ class StageBase(TargetBase, ClearBase, GenBase): 'Resume point detected, skipping build_packages operation...') return - try: - cmd([self.settings['controller_file'], 'livecd-update'], - env=self.env) - self.resume.enable("livecd_update") - - except CatalystError: - raise CatalystError( - "build aborting due to livecd_update error.") + cmd([self.settings['controller_file'], 'livecd-update'], + env=self.env) + self.resume.enable("livecd_update") @staticmethod def _debug_pause_(): diff --git a/catalyst/main.py b/catalyst/main.py index b0d9015f..0de1040f 100644 --- a/catalyst/main.py +++ b/catalyst/main.py @@ -77,10 +77,10 @@ def build_target(addlargs): target = addlargs["target"].replace('-', '_') module = import_module(target) target = getattr(module, target)(conf_values, addlargs) - except AttributeError: + except AttributeError as e: raise CatalystError( "Target \"%s\" not available." % target, - print_traceback=True) + print_traceback=True) from e except CatalystError: return False return target.run() diff --git a/catalyst/support.py b/catalyst/support.py index fa652987..fc50fa34 100644 --- a/catalyst/support.py +++ b/catalyst/support.py @@ -140,9 +140,9 @@ def read_makeconf(mymakeconffile): if os.path.exists(mymakeconffile): try: return read_bash_dict(mymakeconffile, sourcing_command="source") - except Exception: + except Exception as e: raise CatalystError("Could not parse make.conf file " + - mymakeconffile, print_traceback=True) + mymakeconffile, print_traceback=True) from e else: makeconf = {} return makeconf diff --git a/catalyst/targets/livecd_stage2.py b/catalyst/targets/livecd_stage2.py index e90e9f53..ff4ea62a 100644 --- a/catalyst/targets/livecd_stage2.py +++ b/catalyst/targets/livecd_stage2.py @@ -79,11 +79,11 @@ class livecd_stage2(StageBase): "livecd/modblacklist"].split() for x in self.settings["livecd/modblacklist"]: myf.write("\nblacklist "+x) - except: + except Exception as e: raise CatalystError("Couldn't open " + self.settings["chroot_path"] + "/etc/modprobe.d/blacklist.conf.", - print_traceback=True) + print_traceback=True) from e def set_action_sequence(self): self.build_sequence.extend([ diff --git a/catalyst/targets/netboot.py b/catalyst/targets/netboot.py index a2a9fcb3..38d0cb45 100644 --- a/catalyst/targets/netboot.py +++ b/catalyst/targets/netboot.py @@ -30,17 +30,14 @@ class netboot(StageBase): ]) def __init__(self, spec, addlargs): - try: - if "netboot/packages" in addlargs: - if isinstance(addlargs['netboot/packages'], str): - loopy = [addlargs["netboot/packages"]] - else: - loopy = addlargs["netboot/packages"] + if "netboot/packages" in addlargs: + if isinstance(addlargs['netboot/packages'], str): + loopy = [addlargs["netboot/packages"]] + else: + loopy = addlargs["netboot/packages"] - for x in loopy: - self.valid_values |= {"netboot/packages/"+x+"/files"} - except: - raise CatalystError("configuration error in netboot/packages.") + for x in loopy: + self.valid_values |= {"netboot/packages/"+x+"/files"} StageBase.__init__(self, spec, addlargs) self.settings["merge_path"] = normpath("/tmp/image/") @@ -89,12 +86,8 @@ class netboot(StageBase): else: myfiles.append(self.settings["netboot/extra_files"]) - try: - cmd([self.settings['controller_file'], 'image'] + - myfiles, env=self.env) - except CatalystError: - raise CatalystError("Failed to copy files to image!", - print_traceback=True) + cmd([self.settings['controller_file'], 'image'] + + myfiles, env=self.env) self.resume.enable("copy_files_to_image") @@ -116,12 +109,8 @@ class netboot(StageBase): # we're done, move the kernels to builds/* # no auto resume here as we always want the # freshest images moved - try: - cmd([self.settings['controller_file'], 'final'], env=self.env) - log.notice('Netboot Build Finished!') - except CatalystError: - raise CatalystError("Failed to move kernel images!", - print_traceback=True) + cmd([self.settings['controller_file'], 'final'], env=self.env) + log.notice('Netboot Build Finished!') def remove(self): if "autoresume" in self.settings["options"] \ diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py index 7732312c..6b727600 100644 --- a/catalyst/targets/snapshot.py +++ b/catalyst/targets/snapshot.py @@ -73,7 +73,7 @@ class snapshot(TargetBase): except subprocess.CalledProcessError as e: raise CatalystError(f'{e.cmd} failed with return code' f'{e.returncode}\n' - f'{e.output}\n') + f'{e.output}\n') from e def run(self): if self.settings['snapshot_treeish'] == 'stable': From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6C9BE13835E for ; Fri, 29 Jan 2021 23:50:55 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0ED59E0ACD; Fri, 29 Jan 2021 23:50:54 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E015AE0ACD for ; Fri, 29 Jan 2021 23:50:53 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D613D340FF0 for ; Fri, 29 Jan 2021 23:50:52 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 0C4354B5 for ; Fri, 29 Jan 2021 23:50:50 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1611799606.50ba8aadf5f7096e9079eafec9182d526956cd49.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/base/, catalyst/, catalyst/targets/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/base/stagebase.py catalyst/main.py catalyst/support.py catalyst/targets/livecd_stage2.py catalyst/targets/netboot.py catalyst/targets/snapshot.py X-VCS-Directories: catalyst/base/ catalyst/ catalyst/targets/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: 50ba8aadf5f7096e9079eafec9182d526956cd49 X-VCS-Branch: wip/mattst88 Date: Fri, 29 Jan 2021 23:50:50 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 60fee9ea-a0f8-4b6c-8aeb-136b6b047baa X-Archives-Hash: c895920befb93aa935e04b6f6c88f351 Message-ID: <20210129235050._Ww9VKCPQw6PKgWrhia9lsMHTvR8_2GjUJ_hOyW2RMo@z> commit: 50ba8aadf5f7096e9079eafec9182d526956cd49 Author: Matt Turner gentoo org> AuthorDate: Sun Jan 24 02:43:47 2021 +0000 Commit: Matt Turner gentoo org> CommitDate: Thu Jan 28 02:06:46 2021 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=50ba8aad catalyst: Clean up exception handling Use 'raise from' where sensible, but a lot of the CatalystErrors are just trading one CatalystError for another, so remove them. Signed-off-by: Matt Turner gentoo.org> catalyst/base/stagebase.py | 110 ++++++++++++++------------------------ catalyst/main.py | 4 +- catalyst/support.py | 4 +- catalyst/targets/livecd_stage2.py | 4 +- catalyst/targets/netboot.py | 33 ++++-------- catalyst/targets/snapshot.py | 2 +- 6 files changed, 57 insertions(+), 100 deletions(-) diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index 28ff8fd2..46cb1fda 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -906,7 +906,7 @@ class StageBase(TargetBase, ClearBase, GenBase): fstype=fstype, options=options) cxt.mount() except Exception as e: - raise CatalystError(f"Couldn't mount: {source}, {e}") + raise CatalystError(f"Couldn't mount: {source}, {e}") from e def chroot_setup(self): self.makeconf = read_makeconf(normpath(self.settings["chroot_path"] + @@ -978,7 +978,7 @@ class StageBase(TargetBase, ClearBase, GenBase): except OSError as e: raise CatalystError('Could not write %s: %s' % ( normpath(self.settings["chroot_path"] + - self.settings["make_conf"]), e)) + self.settings["make_conf"]), e)) from e self.resume.enable("chroot_setup") def write_make_conf(self, setup=True): @@ -1206,13 +1206,11 @@ class StageBase(TargetBase, ClearBase, GenBase): # operations, so we get easy glob handling. log.notice('%s: removing %s', self.settings["spec_prefix"], x) clear_path(self.settings["stage_path"] + x) - try: - if os.path.exists(self.settings["controller_file"]): - cmd([self.settings['controller_file'], 'clean'], - env=self.env) - self.resume.enable("remove") - except: - raise + + if os.path.exists(self.settings["controller_file"]): + cmd([self.settings['controller_file'], 'clean'], + env=self.env) + self.resume.enable("remove") def preclean(self): if "autoresume" in self.settings["options"] \ @@ -1278,19 +1276,14 @@ class StageBase(TargetBase, ClearBase, GenBase): log.notice('Resume point detected, skipping run_local operation...') return - try: - if os.path.exists(self.settings["controller_file"]): - log.info('run_local() starting controller script...') - cmd([self.settings['controller_file'], 'run'], - env=self.env) - self.resume.enable("run_local") - else: - log.info('run_local() no controller_file found... %s', - self.settings['controller_file']) - - except CatalystError: - raise CatalystError("Stage build aborting due to error.", - print_traceback=False) + if os.path.exists(self.settings["controller_file"]): + log.info('run_local() starting controller script...') + cmd([self.settings['controller_file'], 'run'], + env=self.env) + self.resume.enable("run_local") + else: + log.info('run_local() no controller_file found... %s', + self.settings['controller_file']) def setup_environment(self): log.debug('setup_environment(); settings = %r', self.settings) @@ -1382,13 +1375,10 @@ class StageBase(TargetBase, ClearBase, GenBase): [self.settings[self.settings["spec_prefix"] + "/unmerge"]] # Before cleaning, unmerge stuff - try: - cmd([self.settings['controller_file'], 'unmerge'] + - self.settings[self.settings['spec_prefix'] + '/unmerge'], - env=self.env) - log.info('unmerge shell script') - except CatalystError: - raise + cmd([self.settings['controller_file'], 'unmerge'] + + self.settings[self.settings['spec_prefix'] + '/unmerge'], + env=self.env) + log.info('unmerge shell script') self.resume.enable("unmerge") def target_setup(self): @@ -1457,14 +1447,9 @@ class StageBase(TargetBase, ClearBase, GenBase): command.append(self.settings[target_pkgs]) else: command.extend(self.settings[target_pkgs]) - try: - cmd(command, env=self.env) - fileutils.touch(build_packages_resume) - self.resume.enable("build_packages") - except CatalystError: - raise CatalystError( - self.settings["spec_prefix"] + - "build aborting due to error.") + cmd(command, env=self.env) + fileutils.touch(build_packages_resume) + self.resume.enable("build_packages") def build_kernel(self): '''Build all configured kernels''' @@ -1475,19 +1460,14 @@ class StageBase(TargetBase, ClearBase, GenBase): return if "boot/kernel" in self.settings: - try: - mynames = self.settings["boot/kernel"] - if isinstance(mynames, str): - mynames = [mynames] - # Execute the script that sets up the kernel build environment - cmd([self.settings['controller_file'], 'pre-kmerge'], env=self.env) - for kname in [sanitize_name(name) for name in mynames]: - self._build_kernel(kname=kname) - self.resume.enable("build_kernel") - except CatalystError: - raise CatalystError( - "build aborting due to kernel build error.", - print_traceback=True) + mynames = self.settings["boot/kernel"] + if isinstance(mynames, str): + mynames = [mynames] + # Execute the script that sets up the kernel build environment + cmd([self.settings['controller_file'], 'pre-kmerge'], env=self.env) + for kname in [sanitize_name(name) for name in mynames]: + self._build_kernel(kname=kname) + self.resume.enable("build_kernel") def _build_kernel(self, kname): "Build a single configured kernel by name" @@ -1531,12 +1511,8 @@ class StageBase(TargetBase, ClearBase, GenBase): raise CatalystError("Can't find kernel config: %s" % self.settings[key]) - try: - shutil.copy(self.settings[key], - self.settings['chroot_path'] + '/var/tmp/' + kname + '.config') - - except IOError: - raise + shutil.copy(self.settings[key], + self.settings['chroot_path'] + '/var/tmp/' + kname + '.config') def _copy_initramfs_overlay(self, kname): key = 'boot/kernel/' + kname + '/initramfs_overlay' @@ -1560,13 +1536,10 @@ class StageBase(TargetBase, ClearBase, GenBase): 'Resume point detected, skipping bootloader operation...') return - try: - cmd([self.settings['controller_file'], 'bootloader', - self.settings['target_path'].rstrip('/')], - env=self.env) - self.resume.enable("bootloader") - except CatalystError: - raise CatalystError("Script aborting due to error.") + cmd([self.settings['controller_file'], 'bootloader', + self.settings['target_path'].rstrip('/')], + env=self.env) + self.resume.enable("bootloader") def livecd_update(self): if "autoresume" in self.settings["options"] \ @@ -1575,14 +1548,9 @@ class StageBase(TargetBase, ClearBase, GenBase): 'Resume point detected, skipping build_packages operation...') return - try: - cmd([self.settings['controller_file'], 'livecd-update'], - env=self.env) - self.resume.enable("livecd_update") - - except CatalystError: - raise CatalystError( - "build aborting due to livecd_update error.") + cmd([self.settings['controller_file'], 'livecd-update'], + env=self.env) + self.resume.enable("livecd_update") @staticmethod def _debug_pause_(): diff --git a/catalyst/main.py b/catalyst/main.py index b0d9015f..0de1040f 100644 --- a/catalyst/main.py +++ b/catalyst/main.py @@ -77,10 +77,10 @@ def build_target(addlargs): target = addlargs["target"].replace('-', '_') module = import_module(target) target = getattr(module, target)(conf_values, addlargs) - except AttributeError: + except AttributeError as e: raise CatalystError( "Target \"%s\" not available." % target, - print_traceback=True) + print_traceback=True) from e except CatalystError: return False return target.run() diff --git a/catalyst/support.py b/catalyst/support.py index fa652987..fc50fa34 100644 --- a/catalyst/support.py +++ b/catalyst/support.py @@ -140,9 +140,9 @@ def read_makeconf(mymakeconffile): if os.path.exists(mymakeconffile): try: return read_bash_dict(mymakeconffile, sourcing_command="source") - except Exception: + except Exception as e: raise CatalystError("Could not parse make.conf file " + - mymakeconffile, print_traceback=True) + mymakeconffile, print_traceback=True) from e else: makeconf = {} return makeconf diff --git a/catalyst/targets/livecd_stage2.py b/catalyst/targets/livecd_stage2.py index e90e9f53..ff4ea62a 100644 --- a/catalyst/targets/livecd_stage2.py +++ b/catalyst/targets/livecd_stage2.py @@ -79,11 +79,11 @@ class livecd_stage2(StageBase): "livecd/modblacklist"].split() for x in self.settings["livecd/modblacklist"]: myf.write("\nblacklist "+x) - except: + except Exception as e: raise CatalystError("Couldn't open " + self.settings["chroot_path"] + "/etc/modprobe.d/blacklist.conf.", - print_traceback=True) + print_traceback=True) from e def set_action_sequence(self): self.build_sequence.extend([ diff --git a/catalyst/targets/netboot.py b/catalyst/targets/netboot.py index a2a9fcb3..38d0cb45 100644 --- a/catalyst/targets/netboot.py +++ b/catalyst/targets/netboot.py @@ -30,17 +30,14 @@ class netboot(StageBase): ]) def __init__(self, spec, addlargs): - try: - if "netboot/packages" in addlargs: - if isinstance(addlargs['netboot/packages'], str): - loopy = [addlargs["netboot/packages"]] - else: - loopy = addlargs["netboot/packages"] + if "netboot/packages" in addlargs: + if isinstance(addlargs['netboot/packages'], str): + loopy = [addlargs["netboot/packages"]] + else: + loopy = addlargs["netboot/packages"] - for x in loopy: - self.valid_values |= {"netboot/packages/"+x+"/files"} - except: - raise CatalystError("configuration error in netboot/packages.") + for x in loopy: + self.valid_values |= {"netboot/packages/"+x+"/files"} StageBase.__init__(self, spec, addlargs) self.settings["merge_path"] = normpath("/tmp/image/") @@ -89,12 +86,8 @@ class netboot(StageBase): else: myfiles.append(self.settings["netboot/extra_files"]) - try: - cmd([self.settings['controller_file'], 'image'] + - myfiles, env=self.env) - except CatalystError: - raise CatalystError("Failed to copy files to image!", - print_traceback=True) + cmd([self.settings['controller_file'], 'image'] + + myfiles, env=self.env) self.resume.enable("copy_files_to_image") @@ -116,12 +109,8 @@ class netboot(StageBase): # we're done, move the kernels to builds/* # no auto resume here as we always want the # freshest images moved - try: - cmd([self.settings['controller_file'], 'final'], env=self.env) - log.notice('Netboot Build Finished!') - except CatalystError: - raise CatalystError("Failed to move kernel images!", - print_traceback=True) + cmd([self.settings['controller_file'], 'final'], env=self.env) + log.notice('Netboot Build Finished!') def remove(self): if "autoresume" in self.settings["options"] \ diff --git a/catalyst/targets/snapshot.py b/catalyst/targets/snapshot.py index 7732312c..6b727600 100644 --- a/catalyst/targets/snapshot.py +++ b/catalyst/targets/snapshot.py @@ -73,7 +73,7 @@ class snapshot(TargetBase): except subprocess.CalledProcessError as e: raise CatalystError(f'{e.cmd} failed with return code' f'{e.returncode}\n' - f'{e.output}\n') + f'{e.output}\n') from e def run(self): if self.settings['snapshot_treeish'] == 'stable':