]> kaliko git repositories - mpd-sima.git/commitdiff
Simplified configuration manager (db_file's no longer a special case)
authorkaliko <efrim@azylum.org>
Thu, 10 Oct 2013 20:05:00 +0000 (22:05 +0200)
committerkaliko <efrim@azylum.org>
Thu, 10 Oct 2013 20:05:00 +0000 (22:05 +0200)
launch
sima/core.py
sima/utils/config.py
sima/utils/startopt.py

diff --git a/launch b/launch
index e4c44b5c8207fcd30c70024ecb73fab985e2cb9f..f03ca5b120fcc753dc6035914bef19f8aa0ccd22 100755 (executable)
--- 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:
index ad21db6f16da571b46d7f8b7ac68253c04421f7c..e3bde2c6abfec4b43d2034ff8d46f5dd2a75691d 100644 (file)
@@ -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')
index c11d2e16bb82073dd972f920f5e90e08876b317b..5d79e53a2bbcee6dc34f6fd477f7b79e921f61bf 100644 (file)
@@ -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
index 988e67d336f1c5453e61fa7f3c930ae1e77c3470..da8bbda6e1763accdff197c652acc944aad85692 100644 (file)
@@ -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',