X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flaunch.py;h=179f1c40be5d62a7b7875f310f53a4bbcb7b8825;hb=HEAD;hp=4b77f89a29c5320212b1fe72e16f02701735eda7;hpb=37dd60538984a3917354b794a5c96b0a025f8e95;p=mpd-sima.git diff --git a/sima/launch.py b/sima/launch.py index 4b77f89..179f1c4 100644 --- a/sima/launch.py +++ b/sima/launch.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2013, 2014, 2015, 2020,2021 kaliko +# Copyright (c) 2013, 2014, 2015, 2020-2022 kaliko # # This file is part of sima # @@ -36,6 +36,7 @@ from os import rename from . import core, info from .lib.logger import set_logger from .lib.simadb import SimaDB +from .mpdclient import PlayerError from .utils.config import ConfMan from .utils.startopt import StartOpt from .utils.utils import exception_log, SigHup, MPDSimaException @@ -51,19 +52,19 @@ def load_plugins(sima, source): """Handles internal/external plugins sima: sima.core.Sima instance source: ['internal', 'contrib'] - """ + """# pylint: disable=logging-not-lazy,logging-format-interpolation if not sima.config.get('sima', source): return logger = logging.getLogger('sima') # TODO: Sanity check for "sima.config.get('sima', source)" ? for plugin in sima.config.get('sima', source).split(','): plugin = plugin.strip(' \n') - module = 'sima.plugins.{0}.{1}'.format(source, plugin.lower()) + module = f'sima.plugins.{source}.{plugin.lower()}' try: mod_obj = sima_import(module, fromlist=[plugin]) except ImportError as err: - logger.error('Failed to load "{}" plugin\'s module: '.format(plugin) + - '{0} ({1})'.format(module, err)) + logger.error(f'Failed to load "{plugin}" plugin\'s module: ' + + f'{module} ({err})') sima.shutdown() sys.exit(1) try: @@ -114,7 +115,7 @@ def start(sopt, restart=False): if cmd == "generate-config": config.write(sys.stdout, space_around_delimiters=True) sys.exit(0) - logger.info('Running "%s" and exit' % cmd) + logger.info('Running "%s" and exit', cmd) if cmd == "config-test": logger.info('Config location: "%s"', cfg_mgmt.conf_file) from .utils.configtest import config_test @@ -135,6 +136,10 @@ def start(sopt, restart=False): sys.exit(1) SimaDB(db_path=db_file).purge_history(duration=0) sys.exit(0) + if cmd == 'random': + config['sima']['internal'] = 'Crop, Random' + if sopt.options.get('nbtracks'): + config['random']['track_to_add'] = str(sopt.options.get('nbtracks')) logger.info('Starting (%s)...', info.__version__) sima = core.Sima(config) @@ -183,7 +188,7 @@ def run(sopt, restart=False): start(sopt, restart) except SigHup: # SigHup inherit from Exception run(sopt, True) - except MPDSimaException as err: + except (MPDSimaException, PlayerError) as err: logger.error(err) sys.exit(2) except Exception: # Unhandled exception