From: kaliko Date: Thu, 10 Oct 2013 20:05:00 +0000 (+0200) Subject: Simplified configuration manager (db_file's no longer a special case) X-Git-Tag: mpd-sima/0.12.0pr2~41 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=3232d76fccc3b431bd42a34a5f182667efa346d0;p=mpd-sima.git Simplified configuration manager (db_file's no longer a special case) --- diff --git a/launch b/launch index e4c44b5..f03ca5b 100755 --- a/launch +++ b/launch @@ -76,25 +76,24 @@ def main(): logger = logging.getLogger('sima') logger.setLevel(cli_loglevel) # loads configuration - conf_manager = ConfMan(logger, sopt.options) - config = conf_manager.config + config = ConfMan(logger, sopt.options).config logger.setLevel(getattr(logging, config.get('log', 'verbosity').upper())) # pylint: disable=E1103 logger.debug('Command line say: {0}'.format(sopt.options)) - # Create Database + db_file = config.get('sima', 'db_file') if (sopt.options.get('create_db', None) - or not isfile(conf_manager.db_file)): - logger.info('Creating database in "{}"'.format(conf_manager.db_file)) - open(conf_manager.db_file, 'a').close() - SimaDB(db_path=conf_manager.db_file).create_db() + or not isfile(db_file)): + logger.info('Creating database in "{}"'.format(db_file)) + open(db_file, 'a').close() + SimaDB(db_path=db_file).create_db() if sopt.options.get('create_db', None): logger.info('Done, bye...') sys.exit(0) logger.info('Starting...') - sima = core.Sima(config, conf_manager.db_file) + sima = core.Sima(config) # Loading internal plugins for plugin in PLUGINS: diff --git a/sima/core.py b/sima/core.py index ad21db6..e3bde2c 100644 --- a/sima/core.py +++ b/sima/core.py @@ -20,13 +20,13 @@ class Sima(object): """Main class, plugin and player management """ - def __init__(self, conf, dbfile): + def __init__(self, conf): self.enabled = True self.config = conf - self.sdb = SimaDB(db_path=dbfile) + self.sdb = SimaDB(db_path=conf.get('sima', 'db_file')) self.log = getLogger('sima') self.plugins = list() - self.player = self._get_player() # Player client + self.player = self.__get_player() # Player client try: self.player.connect() except (PlayerError, PlayerUnHandledError) as err: @@ -34,7 +34,7 @@ class Sima(object): self.shutdown() self.short_history = deque(maxlen=60) - def _get_player(self): + def __get_player(self): """Instanciate the player""" host = self.config.get('MPD', 'host') port = self.config.get('MPD', 'port') diff --git a/sima/utils/config.py b/sima/utils/config.py index c11d2e1..5d79e53 100644 --- a/sima/utils/config.py +++ b/sima/utils/config.py @@ -53,7 +53,8 @@ DEFAULT_CONF = { 'daemon': "false", 'pidfile': "",}, 'log': { - 'verbosity': "info"}, + 'verbosity': "info", + 'logfile': "",}, 'lastfm': { 'dynamic': "10", 'similarity': "20", @@ -104,6 +105,7 @@ class ConfMan(object): # CONFIG MANAGER CLASS self.init_config() self.control_conf() self.supersedes_config_with_cmd_line_options() + self.config['sima']['db_file'] = self.db_file def get_pw(self): try: @@ -233,7 +235,6 @@ class ConfMan(object): # CONFIG MANAGER CLASS self.db_file = join(data_dir, 'sima.db') config = configparser.SafeConfigParser() - # If no conf file present, uses defaults if not isfile(self.conf_file): self.config = config diff --git a/sima/utils/startopt.py b/sima/utils/startopt.py index 988e67d..da8bbda 100644 --- a/sima/utils/startopt.py +++ b/sima/utils/startopt.py @@ -89,7 +89,7 @@ OPTS = [ 'sw':['--var_dir'], 'dest': 'var_dir', 'action': Wdir, - 'help': 'Directory to store var content (ie. database)'}, + 'help': 'Directory to store var content (ie. database, cache)'}, { 'sw': ['--create-db'], 'action': 'store_true',