* [gentoo-catalyst] [PATCH 1/4] catalyst: Remove unused import
@ 2021-01-24 15:07 Matt Turner
2021-01-24 15:07 ` [gentoo-catalyst] [PATCH 2/4] catalyst: Use lazy % formatting in logging functions Matt Turner
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Matt Turner @ 2021-01-24 15:07 UTC (permalink / raw
To: gentoo-catalyst; +Cc: Matt Turner
Signed-off-by: Matt Turner <mattst88@gentoo.org>
---
catalyst/base/targetbase.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/catalyst/base/targetbase.py b/catalyst/base/targetbase.py
index 3e338bee..ce16566b 100644
--- a/catalyst/base/targetbase.py
+++ b/catalyst/base/targetbase.py
@@ -3,7 +3,7 @@ import os
from abc import ABC, abstractmethod
from pathlib import Path
-from catalyst.support import addl_arg_parse, CatalystError
+from catalyst.support import addl_arg_parse
class TargetBase(ABC):
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-catalyst] [PATCH 2/4] catalyst: Use lazy % formatting in logging functions
2021-01-24 15:07 [gentoo-catalyst] [PATCH 1/4] catalyst: Remove unused import Matt Turner
@ 2021-01-24 15:07 ` Matt Turner
2021-01-24 15:07 ` [gentoo-catalyst] [PATCH 3/4] catalyst: Remove fallback make.conf parsing code Matt Turner
2021-01-24 15:07 ` [gentoo-catalyst] [PATCH 4/4] catalyst: Clean up exception handling Matt Turner
2 siblings, 0 replies; 4+ messages in thread
From: Matt Turner @ 2021-01-24 15:07 UTC (permalink / raw
To: gentoo-catalyst; +Cc: Matt Turner
Signed-off-by: Matt Turner <mattst88@gentoo.org>
---
catalyst/base/stagebase.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 676206ff..badcfefa 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -823,7 +823,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
repo_conf_chroot = self.to_chroot(repo_conf)
repo_conf_chroot.parent.mkdir(mode=0o755, parents=True, exist_ok=True)
- log.info(f'Creating repo config {repo_conf_chroot}.')
+ log.info('Creating repo config %s.', repo_conf_chroot)
try:
with open(repo_conf_chroot, 'w') as f:
@@ -846,10 +846,10 @@ class StageBase(TargetBase, ClearBase, GenBase):
location_chroot = self.to_chroot(location)
location_chroot.mkdir(mode=0o755, parents=True, exist_ok=True)
- log.info(f'Copying overlay dir {x} to {location_chroot}')
+ log.info('Copying overlay dir %s to %s', x, location_chroot)
cmd(f'cp -a {x}/* {location_chroot}', env=self.env)
else:
- log.warning(f'Skipping missing overlay {x}.')
+ log.warning('Skipping missing overlay %s.', x)
def root_overlay(self):
""" Copy over the root_overlay """
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-catalyst] [PATCH 3/4] catalyst: Remove fallback make.conf parsing code
2021-01-24 15:07 [gentoo-catalyst] [PATCH 1/4] catalyst: Remove unused import Matt Turner
2021-01-24 15:07 ` [gentoo-catalyst] [PATCH 2/4] catalyst: Use lazy % formatting in logging functions Matt Turner
@ 2021-01-24 15:07 ` Matt Turner
2021-01-24 15:07 ` [gentoo-catalyst] [PATCH 4/4] catalyst: Clean up exception handling Matt Turner
2 siblings, 0 replies; 4+ messages in thread
From: Matt Turner @ 2021-01-24 15:07 UTC (permalink / raw
To: gentoo-catalyst; +Cc: Matt Turner
Signed-off-by: Matt Turner <mattst88@gentoo.org>
---
catalyst/support.py | 42 +++---------------------------------------
1 file changed, 3 insertions(+), 39 deletions(-)
diff --git a/catalyst/support.py b/catalyst/support.py
index f3a865a7..fa652987 100644
--- a/catalyst/support.py
+++ b/catalyst/support.py
@@ -2,7 +2,6 @@
import glob
import sys
import os
-import re
import shutil
import time
from pathlib import Path
@@ -12,6 +11,8 @@ import libmount
from portage.repository.config import RepoConfig
+from snakeoil.bash import read_bash_dict
+
from catalyst import log
BASH_BINARY = "/bin/bash"
@@ -135,47 +136,10 @@ defined are not preserved. In other words, "foo", "bar", "oni" ordering is prese
print_traceback=True)
-def parse_makeconf(mylines):
- mymakeconf = {}
- pos = 0
- pat = re.compile("([0-9a-zA-Z_]*)=(.*)")
- while pos < len(mylines):
- if len(mylines[pos]) <= 1:
- # skip blanks
- pos += 1
- continue
- if mylines[pos][0] in ["#", " ", "\t"]:
- # skip indented lines, comments
- pos += 1
- continue
- else:
- myline = mylines[pos]
- mobj = pat.match(myline)
- pos += 1
- if mobj.group(2):
- clean_string = re.sub(r"\"", r"", mobj.group(2))
- mymakeconf[mobj.group(1)] = clean_string
- return mymakeconf
-
-
def read_makeconf(mymakeconffile):
if os.path.exists(mymakeconffile):
try:
- try:
- import snakeoil.bash # import snakeoil.fileutils
- return snakeoil.bash.read_bash_dict(mymakeconffile, sourcing_command="source")
- except ImportError:
- try:
- import portage.util
- return portage.util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True)
- except Exception:
- try:
- import portage_util
- return portage_util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True)
- except ImportError:
- with open(mymakeconffile, "r") as myf:
- mylines = myf.readlines()
- return parse_makeconf(mylines)
+ return read_bash_dict(mymakeconffile, sourcing_command="source")
except Exception:
raise CatalystError("Could not parse make.conf file " +
mymakeconffile, print_traceback=True)
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-catalyst] [PATCH 4/4] catalyst: Clean up exception handling
2021-01-24 15:07 [gentoo-catalyst] [PATCH 1/4] catalyst: Remove unused import Matt Turner
2021-01-24 15:07 ` [gentoo-catalyst] [PATCH 2/4] catalyst: Use lazy % formatting in logging functions Matt Turner
2021-01-24 15:07 ` [gentoo-catalyst] [PATCH 3/4] catalyst: Remove fallback make.conf parsing code Matt Turner
@ 2021-01-24 15:07 ` Matt Turner
2 siblings, 0 replies; 4+ messages in thread
From: Matt Turner @ 2021-01-24 15:07 UTC (permalink / raw
To: gentoo-catalyst; +Cc: Matt Turner
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 <mattst88@gentoo.org>
---
catalyst/base/stagebase.py | 110 +++++++++++-------------------
catalyst/support.py | 4 +-
catalyst/targets/livecd_stage2.py | 4 +-
catalyst/targets/netboot.py | 33 +++------
catalyst/targets/snapshot.py | 2 +-
5 files changed, 55 insertions(+), 98 deletions(-)
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index badcfefa..44e09d3e 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/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':
--
2.26.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-01-24 15:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-24 15:07 [gentoo-catalyst] [PATCH 1/4] catalyst: Remove unused import Matt Turner
2021-01-24 15:07 ` [gentoo-catalyst] [PATCH 2/4] catalyst: Use lazy % formatting in logging functions Matt Turner
2021-01-24 15:07 ` [gentoo-catalyst] [PATCH 3/4] catalyst: Remove fallback make.conf parsing code Matt Turner
2021-01-24 15:07 ` [gentoo-catalyst] [PATCH 4/4] catalyst: Clean up exception handling Matt Turner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox