From 72e9add5aff01c9c2f7b15382c7d4d420cc52b5f Mon Sep 17 00:00:00 2001 From: bom Date: Wed, 22 Feb 2023 09:58:57 +0100 Subject: [PATCH] Add system repository for command line handling --- system_repository.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 system_repository.py diff --git a/system_repository.py b/system_repository.py new file mode 100644 index 0000000..18f5893 --- /dev/null +++ b/system_repository.py @@ -0,0 +1,22 @@ +import subprocess as sub + +class SystemRepository(): + + def __init__(self): + self.stdout = [""] + self.stderr = [""] + + def run(self, *args): + stream = sub.Popen(args, + stdout=sub.PIPE, + stderr=sub.PIPE, + text=True, + encoding="UTF-8") + self.stdout = stream.stdout.readlines() + self.stderr = stream.stderr.readlines() + + def run_checked(self, *args): + self.run(args) + + if len(self.stderr) > 0: + raise Exception(f"Command failed with: {self.stderr}")