add return codes

This commit is contained in:
Jakob Ketterl 2022-06-01 17:58:06 +02:00
parent be8e35cbcf
commit 08485f255a
4 changed files with 22 additions and 17 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys
from owrx.__main__ import main from owrx.__main__ import main
if __name__ == "__main__": if __name__ == "__main__":
main() sys.exit(main())

View File

@ -57,12 +57,15 @@ def main():
if args.version: if args.version:
print("OpenWebRX version {version}".format(version=openwebrx_version)) print("OpenWebRX version {version}".format(version=openwebrx_version))
elif args.module == "admin": return 0
run_admin_action(adminparser, args)
elif args.module == "config": if args.module == "admin":
run_admin_action(configparser, args) return run_admin_action(adminparser, args)
else:
start_receiver() if args.module == "config":
return run_admin_action(configparser, args)
return start_receiver()
def start_receiver(): def start_receiver():
@ -100,7 +103,7 @@ Support and info: https://groups.io/g/openwebrx
description = featureDetector.get_requirement_description(f) description = featureDetector.get_requirement_description(f)
if description: if description:
logger.error("description for %s:\n%s", f, description) logger.error("description for %s:\n%s", f, description)
return return 1
# Get error messages about unknown / unavailable features as soon as possible # Get error messages about unknown / unavailable features as soon as possible
# start up "always-on" sources right away # start up "always-on" sources right away
@ -119,3 +122,5 @@ Support and info: https://groups.io/g/openwebrx
SdrService.stopAllSources() SdrService.stopAllSources()
ReportingEngine.stopAll() ReportingEngine.stopAll()
DecoderQueue.stopAll() DecoderQueue.stopAll()
return 0

View File

@ -46,15 +46,14 @@ def run_admin_action(parser, args):
else: else:
if not hasattr(args, "silent") or not args.silent: if not hasattr(args, "silent") or not args.silent:
parser.print_help() parser.print_help()
sys.exit(1) return 1
sys.exit(0) return 0
try: try:
command.run(args) return command.run(args)
except Exception: except Exception:
if not hasattr(args, "silent") or not args.silent: if not hasattr(args, "silent") or not args.silent:
print("Error running command:") print("Error running command:")
traceback.print_exc() traceback.print_exc()
sys.exit(1) return 1
sys.exit(0) return 0

View File

@ -30,8 +30,7 @@ class UserCommand(Command, metaclass=ABCMeta):
password = getpass("Please enter the new password for {username}: ".format(username=username)) password = getpass("Please enter the new password for {username}: ".format(username=username))
confirm = getpass("Please confirm the new password: ") confirm = getpass("Please confirm the new password: ")
if password != confirm: if password != confirm:
print("ERROR: Password mismatch.") raise ValueError("Password mismatch")
sys.exit(1)
generated = False generated = False
return password, generated return password, generated
@ -108,8 +107,9 @@ class HasUser(Command):
if args.user in userList: if args.user in userList:
if not args.silent: if not args.silent:
print('User "{name}" exists.'.format(name=args.user)) print('User "{name}" exists.'.format(name=args.user))
return 0
else: else:
if not args.silent: if not args.silent:
print('User "{name}" does not exist.'.format(name=args.user)) print('User "{name}" does not exist.'.format(name=args.user))
# in bash, a return code > 0 is interpreted as "false" # in bash, a return code > 0 is interpreted as "false"
sys.exit(1) return 1