run: fix flake8 violations

Two blank lines are needed either side of functions.

Comments must have a single space character immediately after
the "#".

The unused exception variable can be removed.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2021-04-01 15:10:33 +01:00
parent 457f4e6e1e
commit 4e83722a60

11
run.in
View File

@ -46,6 +46,7 @@ import random
import sys import sys
import subprocess import subprocess
# Function to intelligently prepend a path to an environment variable. # Function to intelligently prepend a path to an environment variable.
# See https://stackoverflow.com/a/9631350 # See https://stackoverflow.com/a/9631350
def prepend(env, varname, extradir): def prepend(env, varname, extradir):
@ -54,6 +55,7 @@ def prepend(env, varname, extradir):
else: else:
env[varname] = extradir env[varname] = extradir
here = "@abs_builddir@" here = "@abs_builddir@"
if len(sys.argv) < 2: if len(sys.argv) < 2:
@ -93,29 +95,36 @@ modular_daemons = [
"virtxend", "virtxend",
] ]
def is_modular_daemon(name): def is_modular_daemon(name):
return name in modular_daemons return name in modular_daemons
def is_monolithic_daemon(name): def is_monolithic_daemon(name):
return name == "libvirtd" return name == "libvirtd"
def is_systemd_host(): def is_systemd_host():
if os.getuid() != 0: if os.getuid() != 0:
return False return False
return os.path.exists("/run/systemd/system") return os.path.exists("/run/systemd/system")
def daemon_units(name): def daemon_units(name):
return [name + suffix for suffix in [ return [name + suffix for suffix in [
".service", ".socket", "-ro.socket", "-admin.socket"]] ".service", ".socket", "-ro.socket", "-admin.socket"]]
def is_unit_active(name): def is_unit_active(name):
ret = subprocess.call(["systemctl", "is-active", "-q", name]) ret = subprocess.call(["systemctl", "is-active", "-q", name])
return ret == 0 return ret == 0
def change_unit(name, action): def change_unit(name, action):
ret = subprocess.call(["systemctl", action, "-q", name]) ret = subprocess.call(["systemctl", action, "-q", name])
return ret == 0 return ret == 0
try_stop_units = [] try_stop_units = []
if is_systemd_host(): if is_systemd_host():
name = os.path.basename(prog) name = os.path.basename(prog)
@ -152,7 +161,7 @@ else:
print("Running %s..." % prog) print("Running %s..." % prog)
ret = subprocess.call([prog] + args, env=env) ret = subprocess.call([prog] + args, env=env)
except KeyboardInterrupt as ex: except KeyboardInterrupt:
pass pass
finally: finally:
print("Re-starting original systemd units...") print("Re-starting original systemd units...")