Running black

This commit is contained in:
James Barnsley
2020-02-03 16:14:04 +13:00
parent 9fa47ab734
commit df18eba73c
6 changed files with 529 additions and 623 deletions

View File

@ -13,7 +13,10 @@ class IrisSystemPermissionError(IrisSystemError):
reason = "Permission denied"
def __init__(self, path):
message = "Password-less access to %s was refused. Check your /etc/sudoers file." % path.as_uri()
message = (
"Password-less access to %s was refused. Check your /etc/sudoers file."
% path.as_uri()
)
logger.error(message)
super().__init__(message)
@ -31,57 +34,56 @@ class IrisSystemThread(Thread):
def get_command(self, action=None, *, non_interactive=False):
if self._USE_SUDO:
if non_interactive:
args = [b'sudo -n']
args = [b"sudo -n"]
else:
args = [b'sudo']
args = [b"sudo"]
else:
args = []
if action is None:
action = self.action
args = args + [bytes(self.script_path), action.encode()]
return args
##
# Run the defined action
##
def run(self):
logger.info("Running system action '"+self.action+"'")
logger.info("Running system action '" + self.action + "'")
try:
self.can_run()
except IrisSystemError as e:
logger.error(e)
error = {
'message': e.reason,
'description': e.message
}
return {
'error': error
}
error = {"message": e.reason, "description": e.message}
return {"error": error}
command = self.get_command()
logger.debug("Running '%s'", os.fsdecode(b' '.join(command)))
process = subprocess.Popen(command, stdout=subprocess.PIPE, encoding='utf8')
logger.debug("Running '%s'", os.fsdecode(b" ".join(command)))
process = subprocess.Popen(command, stdout=subprocess.PIPE, encoding="utf8")
lines = ''
lines = ""
while True:
line = process.stdout.readline()
if process.poll() is not None:
break
if line:
logger.info(line)
lines = lines+'\n'+line
lines = lines + "\n" + line
# This seems to be ignored. Detected as spammy io?
#self.ioloop.add_callback(lambda: self.callback(None, None, {'output': line}))
# self.ioloop.add_callback(lambda: self.callback(None, None, {'output': line}))
if process.returncode == 0:
self.ioloop.add_callback(lambda: self.callback({'output': lines}, None, None))
self.ioloop.add_callback(
lambda: self.callback({"output": lines}, None, None)
)
else:
self.ioloop.add_callback(lambda: self.callback(None, {'error': lines}, None))
self.ioloop.add_callback(
lambda: self.callback(None, {"error": lines}, None)
)
##
# Check if we have access to the system script (system.sh)
@ -90,8 +92,10 @@ class IrisSystemThread(Thread):
##
def can_run(self, *args, **kwargs):
# Attempt an empty call to our system file
command_bytes = b' '.join(self.get_command('check', non_interactive=True))
process = subprocess.Popen(command_bytes, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
command_bytes = b" ".join(self.get_command("check", non_interactive=True))
process = subprocess.Popen(
command_bytes, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
)
result, error = process.communicate()
exitCode = process.wait()