openwebrx/owrxadmin/__main__.py

38 lines
1.2 KiB
Python
Raw Normal View History

2021-02-06 18:04:32 +01:00
from owrx.version import openwebrx_version
2021-02-06 18:15:02 +01:00
from owrxadmin.commands import NewUser, DeleteUser
2021-02-06 18:04:32 +01:00
import argparse
import sys
2021-02-06 18:57:51 +01:00
import traceback
2021-02-06 18:04:32 +01:00
2021-02-06 16:43:54 +01:00
def main():
2021-02-06 18:04:32 +01: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")
2021-02-06 19:03:28 +01:00
parser.add_argument(
"--noninteractive", action="store_true", help="Don't ask for any user input (useful for automation)"
)
2021-02-06 18:57:51 +01:00
parser.add_argument("--silent", action="store_true", help="Ignore errors (useful for automation)")
2021-02-06 19:02:50 +01:00
parser.add_argument("-u", "--user", help="User name to perform action upon")
2021-02-06 18:04:32 +01:00
args = parser.parse_args()
if args.command == "adduser":
2021-02-06 18:57:51 +01:00
command = NewUser()
2021-02-06 18:04:32 +01:00
elif args.command == "removeuser":
2021-02-06 18:57:51 +01:00
command = DeleteUser()
2021-02-06 18:04:32 +01:00
else:
2021-02-06 18:57:51 +01: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)