X-Git-Url: http://git.kaliko.me/?a=blobdiff_plain;f=sima%2Futils%2Fconfig.py;h=da66366042e082ee7e0b73f410bef2e9511d0ac7;hb=ce32823ab9d41112d989f4543432926eb38487e6;hp=84367d66b233ca3b003bdc78cb219e538eb06154;hpb=204fdd2bea753b024c7253a5830325b81aebbd61;p=mpd-sima.git diff --git a/sima/utils/config.py b/sima/utils/config.py index 84367d6..da66366 100644 --- a/sima/utils/config.py +++ b/sima/utils/config.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- - -# Copyright (c) 2009, 2010, 2011, 2013 Jack Kaliko +# Copyright (c) 2009, 2010, 2011, 2013, 2014 Jack Kaliko # # This file is part of sima # @@ -37,34 +36,54 @@ from . import utils # DEFAULTS DIRNAME = 'mpd_sima' -CONF_FILE = 'mpd_sima.cfg' +CONF_FILE = 'sima.cfg' DEFAULT_CONF = { 'MPD': { 'host': "localhost", - 'password': "false", - 'port': "6600"}, + #'password': "", + 'port': "6600", + }, 'sima': { - 'similarity': "15", - 'dynamic': "10", - 'queue_mode': "track", #TODO control values + 'internal': "Crop, Lastfm, RandomFallBack", + 'contrib': "", 'user_db': "false", 'history_duration': "8", 'queue_length': "1", - 'track_to_add': "1", - 'album_to_add': "1", - 'consume': "0", - 'single_album': "false", - 'check_new_version':"false",}, + }, 'daemon':{ 'daemon': "false", - 'pidfile': "",}, + 'pidfile': "", + }, 'log': { - 'verbosity': "info"}} + 'verbosity': "info", + 'logfile': "", + }, + 'echonest': { + 'queue_mode': "track", #TODO control values + 'max_art': "15", + 'single_album': "false", + 'track_to_add': "1", + 'album_to_add': "1", + 'depth': "1", + }, + 'lastfm': { + 'queue_mode': "track", #TODO control values + 'max_art': "10", + 'single_album': "false", + 'track_to_add': "1", + 'album_to_add': "1", + 'depth': "1", + }, + 'randomfallback': { + 'flavour': "sensible", # in pure, sensible + 'track_to_add': "1", + } + } # -class ConfMan(object):#CONFIG MANAGER CLASS +class ConfMan(object): # CONFIG MANAGER CLASS """ Configuration manager. Default configuration is stored in DEFAULT_CONF dictionnary. @@ -89,7 +108,7 @@ class ConfMan(object):#CONFIG MANAGER CLASS self.defaults = dict(DEFAULT_CONF) self.startopt = options ## Sima sqlite DB - self.userdb_file = None + self.db_file = None self.log = logger ## INIT CALLS @@ -97,6 +116,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: @@ -106,18 +126,18 @@ class ConfMan(object):#CONFIG MANAGER CLASS return None except ValueError: # ValueError if password not a boolean, hence an actual password. - pw = self.config.get('MPD', 'password') - if not pw: + pwd = self.config.get('MPD', 'password') + if not pwd: self.log.debug('Password set as an empty string.') return None - return pw + return pwd def control_mod(self): """ Controls conf file permissions. """ mode = S_IMODE(stat(self.conf_file)[ST_MODE]) - self.log.debug('file permision is: %o' % mode) + self.log.debug('file permission is: %o' % mode) if mode & S_IRWXO or mode & S_IRWXG: self.log.warning('File is readable by "other" and/or' + ' "group" (actual permission %o octal).' % @@ -184,7 +204,7 @@ class ConfMan(object):#CONFIG MANAGER CLASS def init_config(self): """ Use XDG directory standard if exists - else use "HOME/(.config|.local/share)/mpd_sima/" + else use "HOME/(.config|.local/share)/sima/" http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html """ @@ -223,10 +243,9 @@ class ConfMan(object):#CONFIG MANAGER CLASS self.log.error('Please use "--config" to locate the conf file') sys.exit(1) - self.userdb_file = join(data_dir, 'sima.db') + 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