diff --git a/owrx/__main__.py b/owrx/__main__.py index b7c00e8..9eb8680 100644 --- a/owrx/__main__.py +++ b/owrx/__main__.py @@ -2,6 +2,7 @@ from http.server import HTTPServer from owrx.http import RequestHandler from owrx.config.core import CoreConfig from owrx.config import Config +from owrx.config.commands import MigrateCommand from owrx.feature import FeatureDetector from owrx.sdr import SdrService from socketserver import ThreadingMixIn @@ -37,14 +38,20 @@ def main(): parser.add_argument("-v", "--version", action="store_true", help="Show the software version") moduleparser = parser.add_subparsers(title="Modules", dest="module") - adminparser = moduleparser.add_parser("admin", help="OpenWebRX admin actions") + adminparser = moduleparser.add_parser("admin", help="Administration actions") add_admin_parser(adminparser) + configparser = moduleparser.add_parser("config", help="Configuration actions") + configcommandparser = configparser.add_subparsers(title="Commands", dest="command") + + migrateparser = configcommandparser.add_parser("migrate", help="Migrage configuration files") + migrateparser.set_defaults(cls=MigrateCommand) + args = parser.parse_args() if args.version: print("OpenWebRX version {version}".format(version=openwebrx_version)) - elif args.module == "admin": + elif args.module in ["admin", "config"]: # override loglevel for admin commands, they shouldn't be that verbose logging.basicConfig(level=logging.INFO, force=True) run_admin_action(adminparser, args) diff --git a/owrx/admin/__init__.py b/owrx/admin/__init__.py index dc5410d..d2d0346 100644 --- a/owrx/admin/__init__.py +++ b/owrx/admin/__init__.py @@ -51,7 +51,7 @@ def run_admin_action(parser, args): try: command.run(args) except Exception: - if not args.silent: + if not hasattr(args, "silent") or not args.silent: print("Error running command:") traceback.print_exc() sys.exit(1) diff --git a/owrx/config/commands.py b/owrx/config/commands.py new file mode 100644 index 0000000..efcaf31 --- /dev/null +++ b/owrx/config/commands.py @@ -0,0 +1,22 @@ +from owrx.admin.commands import Command +from owrx.config import Config +from owrx.bookmarks import Bookmarks + + +class MigrateCommand(Command): + def run(self, args): + print("Migrating configuration...") + + config = Config.get() + # a key that is set will end up in the DynamicConfig, so this will transfer everything there + for key, value in config.items(): + config[key] = value + config.store() + + print("Migrating bookmarks...") + # bookmarks just need to be saved + b = Bookmarks.getSharedInstance() + b.getBookmarks() + b.store() + + print("Migration complete!")