chore: remove all E501 updates

This commit is contained in:
Jose Diaz-Gonzalez
2017-05-08 17:41:25 -06:00
committed by GitHub
parent 263b582139
commit 7022d31858

View File

@@ -96,7 +96,7 @@ def import_envvars(clear_existing_environment=True, override_existing_environmen
if clear_existing_environment: if clear_existing_environment:
os.environ.clear() os.environ.clear()
for name, value in new_env.items(): for name, value in new_env.items():
if override_existing_environment or name not in os.environ: if override_existing_environment or not name in os.environ:
os.environ[name] = value os.environ[name] = value
@@ -132,10 +132,11 @@ def shquote(s):
def sanitize_shenvname(s): def sanitize_shenvname(s):
return re.sub(SHENV_NAME_WHITELIST_REGEX, "_", s) return re.sub(SHENV_NAME_WHITELIST_REGEX, "_", s)
# Waits for the child process with the given PID, while at the same time # Waits for the child process with the given PID, while at the same time
# reaping any other child processes that have exited (e.g. adopted child # reaping any other child processes that have exited (e.g. adopted child
# processes that have terminated). # processes that have terminated).
def waitpid_reap_other_children(pid): def waitpid_reap_other_children(pid):
global terminated_child_processes global terminated_child_processes
@@ -201,7 +202,7 @@ def run_command_killable(*argv):
pid = os.spawnvp(os.P_NOWAIT, filename, argv) pid = os.spawnvp(os.P_NOWAIT, filename, argv)
try: try:
status = waitpid_reap_other_children(pid) status = waitpid_reap_other_children(pid)
except BaseException: except BaseException as s:
warn("An error occurred. Aborting.") warn("An error occurred. Aborting.")
stop_child_process(filename, pid) stop_child_process(filename, pid)
raise raise
@@ -263,11 +264,8 @@ def run_startup_files():
def start_runit(): def start_runit():
info("Booting runit daemon...") info("Booting runit daemon...")
pid = os.spawnl(os.P_NOWAIT, pid = os.spawnl(os.P_NOWAIT, "/usr/bin/runsvdir", "/usr/bin/runsvdir",
"/usr/bin/runsvdir", "-P", "/etc/service")
"/usr/bin/runsvdir",
"-P",
"/etc/service")
info("Runit started as PID %d" % pid) info("Runit started as PID %d" % pid)
return pid return pid
@@ -334,9 +332,7 @@ def main(args):
info("Runit exited with status %d" % exit_status) info("Runit exited with status %d" % exit_status)
else: else:
info("Running %s..." % " ".join(args.main_command)) info("Running %s..." % " ".join(args.main_command))
pid = os.spawnvp(os.P_NOWAIT, pid = os.spawnvp(os.P_NOWAIT, args.main_command[0], args.main_command)
args.main_command[0],
args.main_command)
try: try:
exit_code = waitpid_reap_other_children(pid) exit_code = waitpid_reap_other_children(pid)
if exit_code is None: if exit_code is None:
@@ -348,7 +344,7 @@ def main(args):
except KeyboardInterrupt: except KeyboardInterrupt:
stop_child_process(args.main_command[0], pid) stop_child_process(args.main_command[0], pid)
raise raise
except BaseException: except BaseException as s:
warn("An error occurred. Aborting.") warn("An error occurred. Aborting.")
stop_child_process(args.main_command[0], pid) stop_child_process(args.main_command[0], pid)
raise raise
@@ -360,50 +356,25 @@ def main(args):
stop_child_process("runit daemon", runit_pid) stop_child_process("runit daemon", runit_pid)
wait_for_runit_services() wait_for_runit_services()
# Parse options. # Parse options.
parser = argparse.ArgumentParser(description='Initialize the system.') parser = argparse.ArgumentParser(description='Initialize the system.')
parser.add_argument( parser.add_argument('main_command', metavar='MAIN_COMMAND', type=str, nargs='*',
'main_command', help='The main command to run. (default: runit)')
metavar='MAIN_COMMAND', parser.add_argument('--enable-insecure-key', dest='enable_insecure_key',
type=str, action='store_const', const=True, default=False,
nargs='*', help='Install the insecure SSH key')
help='The main command to run. (default: runit)') parser.add_argument('--skip-startup-files', dest='skip_startup_files',
parser.add_argument( action='store_const', const=True, default=False,
'--enable-insecure-key', help='Skip running /etc/my_init.d/* and /etc/rc.local')
dest='enable_insecure_key', parser.add_argument('--skip-runit', dest='skip_runit',
action='store_const', action='store_const', const=True, default=False,
const=True, help='Do not run runit services')
default=False, parser.add_argument('--no-kill-all-on-exit', dest='kill_all_on_exit',
help='Install the insecure SSH key') action='store_const', const=False, default=True,
parser.add_argument( help='Don\'t kill all processes on the system upon exiting')
'--skip-startup-files', parser.add_argument('--quiet', dest='log_level',
dest='skip_startup_files', action='store_const', const=LOG_LEVEL_WARN, default=LOG_LEVEL_INFO,
action='store_const', help='Only print warnings and errors')
const=True,
default=False,
help='Skip running /etc/my_init.d/* and /etc/rc.local')
parser.add_argument(
'--skip-runit',
dest='skip_runit',
action='store_const',
const=True,
default=False,
help='Do not run runit services')
parser.add_argument(
'--no-kill-all-on-exit',
dest='kill_all_on_exit',
action='store_const',
const=False,
default=True,
help='Do not kill all processes on the system upon exiting')
parser.add_argument(
'--quiet',
dest='log_level',
action='store_const',
const=LOG_LEVEL_WARN,
default=LOG_LEVEL_INFO,
help='Only print warnings and errors')
args = parser.parse_args() args = parser.parse_args()
log_level = args.log_level log_level = args.log_level
@@ -412,12 +383,9 @@ if args.skip_runit and len(args.main_command) == 0:
sys.exit(1) sys.exit(1)
# Run main function. # Run main function.
signal.signal(signal.SIGTERM, signal.signal(signal.SIGTERM, lambda signum, frame: ignore_signals_and_raise_keyboard_interrupt('SIGTERM'))
lambda signum, frame: ignore_signals_and_raise_keyboard_interrupt('SIGTERM')) signal.signal(signal.SIGINT, lambda signum, frame: ignore_signals_and_raise_keyboard_interrupt('SIGINT'))
signal.signal(signal.SIGINT, signal.signal(signal.SIGALRM, lambda signum, frame: raise_alarm_exception())
lambda signum, frame: ignore_signals_and_raise_keyboard_interrupt('SIGINT'))
signal.signal(signal.SIGALRM,
lambda signum, frame: raise_alarm_exception())
try: try:
main(args) main(args)
except KeyboardInterrupt: except KeyboardInterrupt: