X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flaunch.py;h=1757d2bcee717d1780d272c8e24fed977ee0dedd;hb=703c89bb8361c1d5bc7456ef47a91b5e63dcb74b;hp=27e9d6bfdab60e75a2832a2b8e3683b7d341adf7;hpb=568365b3b2ec343ffa3e1b2159c38abbe88011eb;p=mpd-sima.git diff --git a/sima/launch.py b/sima/launch.py index 27e9d6b..1757d2b 100644 --- a/sima/launch.py +++ b/sima/launch.py @@ -26,6 +26,7 @@ import sys from importlib import __import__ as sima_import from os.path import isfile +from os import rename ## # third parties components @@ -38,6 +39,7 @@ from .lib.simadb import SimaDB from .utils.config import ConfMan from .utils.startopt import StartOpt from .utils.utils import exception_log, SigHup, MPDSimaException +from .utils.blcli import BLCli # core plugins from .plugins.core.history import History from .plugins.core.mpdoptions import MpdOptions @@ -85,18 +87,30 @@ def start(sopt, restart=False): logger = logging.getLogger('sima') logfile = config.get('log', 'logfile', fallback=None) verbosity = config.get('log', 'verbosity') - set_logger(verbosity, logfile) + if sopt.options.get('command'): # disable file logging + set_logger(verbosity) + else: + set_logger(verbosity, logfile) logger.debug('Command line say: %s', sopt.options) # Create database if not present db_file = config.get('sima', 'db_file') if not isfile(db_file): logger.debug('Creating database in "%s"', db_file) - open(db_file, 'a').close() # TODO: to remove with new simadb in v0.18 + SimaDB(db_path=db_file).create_db() + # Migration from v0.17.0 + dbinfo = SimaDB(db_path=db_file).get_info() + if not dbinfo: # v0.17.0 → v0.18+ migration + logger.warning('Backing up database!') + rename(db_file, db_file + '-old-version-backup') + logger.info('Creating an new database in "%s"', db_file) SimaDB(db_path=db_file).create_db() if sopt.options.get('command'): cmd = sopt.options.get('command') + if cmd.startswith('bl-'): + BLCli(config, sopt.options) + sys.exit(0) if cmd == "generate-config": config.write(sys.stdout, space_around_delimiters=True) sys.exit(0) @@ -178,7 +192,7 @@ def run(sopt, restart=False): def main(): """Entry point""" nfo = dict({'version': info.__version__, - 'prog': 'sima'}) + 'prog': 'mpd-sima'}) # StartOpt gathers options from command line call (in StartOpt().options) sopt = StartOpt(nfo) run(sopt)