diff --git a/simpleinit.py b/simpleinit.py index 687dd64797ad89b5b584592ee821b9a10b52e0b2..23f8365bf843fc15de033673932189953f5513f6 100755 --- a/simpleinit.py +++ b/simpleinit.py @@ -16,15 +16,19 @@ config.read(sys.argv[1]) runlevels = dict() for section in config.sections(): command = config[section] - try: - runlevel = int(command['Runlevel']) + if 'Runlevel' not in command: + print(f"Config section '{section}' is missing a 'Runlevel='!") + continue + runlevel = int(command['Runlevel']) + start = [] + stop = [] + if runlevel not in runlevels: + runlevels[runlevel] = list() + if 'CmdStart' in command: start = command['CmdStart'].splitlines() + if 'CmdStop' in command: stop = command['CmdStop'].splitlines() - if runlevel not in runlevels: - runlevels[runlevel] = list() - runlevels[runlevel].append({ 'name': section, 'start': start, 'stop': stop }) - except KeyError as e: - print(f"Config section '{section}' is missing a required {e}") + runlevels[runlevel].append({ 'name': section, 'start': start, 'stop': stop }) # TODO: persist last seen runlevel old_level = 0