openwebrx-clone/owrxadmin/__main__.py

36 lines
1.1 KiB
Python
Raw Normal View History

2021-02-06 17:04:32 +00:00
from owrx.version import openwebrx_version
2021-02-06 17:15:02 +00:00
from owrxadmin.commands import NewUser, DeleteUser
2021-02-06 17:04:32 +00:00
import argparse
import sys
2021-02-06 17:57:51 +00:00
import traceback
2021-02-06 17:04:32 +00:00
2021-02-06 15:43:54 +00:00
def main():
2021-02-06 17:04:32 +00:00
print("OpenWebRX admin version {version}".format(version=openwebrx_version))
parser = argparse.ArgumentParser()
parser.add_argument("command", help="One of the following commands: adduser, removeuser")
parser.add_argument("--noninteractive", action="store_true", help="Don't ask for any user input (useful for automation)")
2021-02-06 17:57:51 +00:00
parser.add_argument("--silent", action="store_true", help="Ignore errors (useful for automation)")
2021-02-06 17:04:32 +00:00
parser.add_argument("-u", "--user")
args = parser.parse_args()
if args.command == "adduser":
2021-02-06 17:57:51 +00:00
command = NewUser()
2021-02-06 17:04:32 +00:00
elif args.command == "removeuser":
2021-02-06 17:57:51 +00:00
command = DeleteUser()
2021-02-06 17:04:32 +00:00
else:
2021-02-06 17:57:51 +00:00
if not args.silent:
print("Unknown command: {command}".format(command=args.command))
sys.exit(1)
sys.exit(0)
try:
command.run(args)
except Exception:
if not args.silent:
print("Error running command:")
traceback.print_exc()
sys.exit(1)
sys.exit(0)