###############################################################################
import logging
+import subprocess
import sys
import traceback
except InstallAbortedError:
return 1
+ # Catch any failed commands
+ except subprocess.CalledProcessError as e:
+ args = {
+ "command" : " ".join(e.cmd),
+ "output" : e.output.decode(),
+ "returncode" : e.returncode,
+ }
+
+ # Log the error
+ log.error("Command \"%(command)s\" failed with error code "
+ "%(returncode)s:\n%(output)s" % args)
+
+ # Format the error message
+ error = _("Command \"%(command)s\" failed with error code "
+ "%(returncode)s:\n\n%(output)s" % args)
+
+ # Show it
+ self.tui.error(_("An Unexpected Error Occured"), error,
+ buttons=[_("Exit")], width=78)
+
+ # Exit
+ return e.returncode
+
# Catch all other exceptions and show an error
except:
type, value, tb = sys.exc_info()
"""
with open("/etc/os-release") as f:
return util.config_read(f)
+
+ def command(self, command):
+ """
+ Runs a command in a shell environment
+ """
+ log.debug("Running command: %s" % " ".join(command))
+
+ # Execute the command
+ p = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+
+ # Check the return code (raises CalledProcessError on non-zero)
+ p.check_returncode()
+
+ # Decode output
+ output = p.stdout.decode()
+
+ # Log output
+ if output:
+ log.debug(output)
+
+ return output