openwebrx-clone/owrxadmin/__main__.py

48 lines
1.7 KiB
Python
Raw Normal View History

2021-02-06 17:04:32 +00:00
from owrx.version import openwebrx_version
2021-02-08 16:04:55 +00:00
from owrxadmin.commands import NewUser, DeleteUser, ResetPassword, ListUsers, DisableUser, EnableUser
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()
2021-02-08 16:04:55 +00:00
parser.add_argument("command", help="""One of the following commands:
adduser, removeuser, listusers, resetpassword, enableuser, disableuser""")
2021-02-06 18:03:28 +00:00
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 18:02:50 +00:00
parser.add_argument("-u", "--user", help="User name to perform action upon")
2021-02-08 16:04:55 +00:00
parser.add_argument("-a", "--all", action="store_true", help="Show all users")
2021-02-06 17:04:32 +00:00
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 18:12:44 +00:00
elif args.command == "resetpassword":
command = ResetPassword()
2021-02-08 16:04:55 +00:00
elif args.command == "listusers":
command = ListUsers()
elif args.command == "disableuser":
command = DisableUser()
elif args.command == "enableuser":
command = EnableUser()
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)