add command for explicit migration
This commit is contained in:
parent
159c231884
commit
05985ff46a
@ -2,6 +2,7 @@ from http.server import HTTPServer
|
|||||||
from owrx.http import RequestHandler
|
from owrx.http import RequestHandler
|
||||||
from owrx.config.core import CoreConfig
|
from owrx.config.core import CoreConfig
|
||||||
from owrx.config import Config
|
from owrx.config import Config
|
||||||
|
from owrx.config.commands import MigrateCommand
|
||||||
from owrx.feature import FeatureDetector
|
from owrx.feature import FeatureDetector
|
||||||
from owrx.sdr import SdrService
|
from owrx.sdr import SdrService
|
||||||
from socketserver import ThreadingMixIn
|
from socketserver import ThreadingMixIn
|
||||||
@ -37,14 +38,20 @@ def main():
|
|||||||
parser.add_argument("-v", "--version", action="store_true", help="Show the software version")
|
parser.add_argument("-v", "--version", action="store_true", help="Show the software version")
|
||||||
|
|
||||||
moduleparser = parser.add_subparsers(title="Modules", dest="module")
|
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)
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
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":
|
elif args.module in ["admin", "config"]:
|
||||||
# override loglevel for admin commands, they shouldn't be that verbose
|
# override loglevel for admin commands, they shouldn't be that verbose
|
||||||
logging.basicConfig(level=logging.INFO, force=True)
|
logging.basicConfig(level=logging.INFO, force=True)
|
||||||
run_admin_action(adminparser, args)
|
run_admin_action(adminparser, args)
|
||||||
|
@ -51,7 +51,7 @@ def run_admin_action(parser, args):
|
|||||||
try:
|
try:
|
||||||
command.run(args)
|
command.run(args)
|
||||||
except Exception:
|
except Exception:
|
||||||
if 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)
|
sys.exit(1)
|
||||||
|
22
owrx/config/commands.py
Normal file
22
owrx/config/commands.py
Normal file
@ -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!")
|
Loading…
Reference in New Issue
Block a user