[libvirt] [dockerfiles PATCH 0/3] refresh: Minor Python style tweaks

These are basically the same tweaks that have recently been applied to lcitool. Andrea Bolognani (3): refresh: Remove double space refresh: Drop Error class refresh: Move exception handling to Application.run() refresh | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) -- 2.20.1

flake8 complains about it. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- refresh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refresh b/refresh index 1e6c185..730bb7c 100755 --- a/refresh +++ b/refresh @@ -35,7 +35,7 @@ class MoveAlongException(Exception): class Dockerfile: PREFIX = "buildenv-" - CROSS = "-cross-" + CROSS = "-cross-" SUFFIX = ".Dockerfile" def __init__(self, path): -- 2.20.1

Turns out we can use the built-in Exception class directly. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- refresh | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/refresh b/refresh index 730bb7c..1b94736 100755 --- a/refresh +++ b/refresh @@ -21,13 +21,6 @@ import subprocess import sys -class Error(Exception): - - def __init__(self, message): - super(Error, self).__init__() - self.message = message - - class MoveAlongException(Exception): pass @@ -47,7 +40,7 @@ class Dockerfile: # Files that don't follow the expected format should be reported if not path.stem.startswith(Dockerfile.PREFIX): - raise Error("Invalid name '{}'".format(path.stem)) + raise Exception("Invalid name '{}'".format(path.stem)) self.path = path stem = path.stem[len(Dockerfile.PREFIX):] @@ -94,7 +87,7 @@ class Dockerfile: rc = subprocess.run(args, capture_output=True) if rc.returncode != 0: - raise Error("lcitool failed: {}".format(rc.stderr.decode())) + raise Exception("lcitool failed: {}".format(rc.stderr.decode())) with self.path.open('w') as f: print(rc.stdout.decode().strip(), file=f) @@ -120,7 +113,7 @@ class Application: self.lcitool = ci_repo.joinpath("guests").joinpath("lcitool") if not self.lcitool.exists(): - raise Error("{} does not exist".format(self.lcitool)) + raise Exception("{} does not exist".format(self.lcitool)) def run(self): @@ -137,6 +130,6 @@ class Application: if __name__ == "__main__": try: Application().run() - except Error as err: - sys.stderr.write("{}: {}\n".format(sys.argv[0], err.message)) + except Exception as ex: + sys.stderr.write("{}: {}\n".format(sys.argv[0], ex)) sys.exit(1) -- 2.20.1

This commit is best viewed with 'git show -w'. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- refresh | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/refresh b/refresh index 1b94736..1db0fc8 100755 --- a/refresh +++ b/refresh @@ -117,19 +117,20 @@ class Application: def run(self): - for item in self.here.iterdir(): - try: - dockerfile = Dockerfile(item) - except MoveAlongException: - continue + try: + for item in self.here.iterdir(): + try: + dockerfile = Dockerfile(item) + except MoveAlongException: + continue - print(item.stem + item.suffix) - dockerfile.refresh(self.lcitool) + print(item.stem + item.suffix) + dockerfile.refresh(self.lcitool) + + except Exception as ex: + sys.stderr.write("{}: {}\n".format(sys.argv[0], ex)) + sys.exit(1) if __name__ == "__main__": - try: - Application().run() - except Exception as ex: - sys.stderr.write("{}: {}\n".format(sys.argv[0], ex)) - sys.exit(1) + Application().run() -- 2.20.1
participants (2)
-
Andrea Bolognani
-
Erik Skultety