[SCM] mpd-sima/upstream: Imported Upstream version 0.12.0~3~325e87e
kaliko-guest at users.alioth.debian.org
kaliko-guest at users.alioth.debian.org
Sun Sep 28 11:34:29 UTC 2014
The following commit has been merged in the upstream branch:
commit 111bf1b1a5057da310222164032a16fb8aaa2763
Author: Geoffroy Youri Berret <kaliko at azylum.org>
Date: Mon Jun 16 01:41:18 2014 +0200
Imported Upstream version 0.12.0~3~325e87e
diff --git a/doc/examples/album_mode.cfg b/doc/examples/album_mode.cfg
new file mode 100644
index 0000000..4d1c8cf
--- /dev/null
+++ b/doc/examples/album_mode.cfg
@@ -0,0 +1,31 @@
+#
+# For complete list of options availble please refer to manual
+# "man 5 mpd_sima.cfg" or the documentation:
+# /usr/share/doc/mpd-sima/examples/all_settings.cfg
+#
+########################## MPD SECTION ################################
+[MPD]
+host = localhost
+port = 6600
+#password = s3cr3t
+
+######################## LOGGING FACILITY #############################
+[log]
+#logfile =
+verbosity = info
+
+######################## SIMA CORE ####################################
+[sima]
+history_duration = 24 # in hours
+queue_length = 5
+
+######################### PLUGINS #####################################
+
+[crop]
+consume = 20
+
+[lastfm]
+queue_mode = album
+album_to_add = 1
+
+# vim: syntax=cfg fileencoding=utf-8
diff --git a/doc/examples/all_settings.cfg b/doc/examples/all_settings.cfg
index 3be857d..46a6184 100644
--- a/doc/examples/all_settings.cfg
+++ b/doc/examples/all_settings.cfg
@@ -1,9 +1,10 @@
########################################################################
#
-# If you need special settings, rename this file as sima.cfg within
-# your $XDG_CONFIG_HOME (default is $HOME/.config/sima/)
+# If you need special settings, rename this file as mpd_sima.cfg within
+# your $XDG_CONFIG_HOME (default is $HOME/.config/mpd_sima/)
# You can also call it with --config option.
#
+# cf. man 5 mpd_sima.cfg
########################################################################
########################## MPD SECTION ################################
diff --git a/sima/launch.py b/sima/launch.py
index 19fac0c..733d237 100644
--- a/sima/launch.py
+++ b/sima/launch.py
@@ -79,15 +79,13 @@ def start(sopt, restart=False):
# set logger
verbosity = sopt.options.get('verbosity', 'warning')
logfile = sopt.options.get('logfile', None)
- cli_loglevel = getattr(logging, verbosity.upper())
- set_logger(level=verbosity, logfile=logfile)
- logger = logging.getLogger('sima')
- logger.setLevel(cli_loglevel)
+ set_logger(verbosity, logfile)
# loads configuration
- config = ConfMan(logger, sopt.options).config
- logger.setLevel(getattr(logging,
- config.get('log', 'verbosity').upper())) # pylint: disable=E1103
-
+ config = ConfMan(sopt.options).config
+ logfile = config.get('log', 'logfile')
+ verbosity = config.get('log', 'verbosity')
+ set_logger(verbosity, logfile)
+ logger = logging.getLogger('sima')
logger.debug('Command line say: {0}'.format(sopt.options))
# Create Database
db_file = config.get('sima', 'db_file')
diff --git a/sima/lib/logger.py b/sima/lib/logger.py
index 3b287e2..05f9c35 100644
--- a/sima/lib/logger.py
+++ b/sima/lib/logger.py
@@ -50,13 +50,14 @@ class LevelFilter(logging.Filter):# Logging facility
return record.levelno <= self.level
-def set_logger(level='info', logfile=None, name='sima'):
+def set_logger(level='info', logfile=None):
"""
logger:
level: in debug, info, warning,…
- file: provides to log to file
+ logfile: file to log to
"""
+ name = 'sima'
user_log_level = getattr(logging, level.upper())
if user_log_level > logging.DEBUG:
log_format = LOG_FORMATS.get(logging.INFO)
@@ -65,22 +66,34 @@ def set_logger(level='info', logfile=None, name='sima'):
logg = logging.getLogger(name)
formatter = logging.Formatter(log_format, DATE_FMT, '{')
logg.setLevel(user_log_level)
+ filehdl = False
+ if logg.handlers:
+ for hdl in logg.handlers:
+ hdl.setFormatter(formatter)
+ if isinstance(hdl, logging.FileHandler):
+ filehdl = True
+ else:
+ logg.removeHandler(hdl)
+
if logfile:
+ if filehdl:
+ logg.handlers = []
# create file handler
fileh = logging.FileHandler(logfile)
#fileh.setLevel(user_log_level)
fileh.setFormatter(formatter)
- if not logg.hasHandlers():
- logg.addHandler(fileh)
+ logg.addHandler(fileh)
else:
- if not logg.hasHandlers():
- # create console handler with a specified log level (STDOUT)
- couth = logging.StreamHandler(sys.stdout)
- #couth.setLevel(user_log_level)
- couth.addFilter(LevelFilter(logging.WARNING))
-
- # create console handler with warning log level (STDERR)
- cerrh = logging.StreamHandler(sys.stderr)
+ if filehdl:
+ logg.info('Not changing logging handlers, only updating formatter')
+ return
+ # create console handler with a specified log level (STDOUT)
+ couth = logging.StreamHandler(sys.stdout)
+ #couth.setLevel(user_log_level)
+ couth.addFilter(LevelFilter(logging.WARNING))
+
+ # create console handler with warning log level (STDERR)
+ cerrh = logging.StreamHandler(sys.stderr)
#cerrh.setLevel(logging.WARNING)
cerrh.setLevel(logging.ERROR)
diff --git a/sima/plugins/internal/randomfallback.py b/sima/plugins/internal/randomfallback.py
index aceff44..4c011fe 100644
--- a/sima/plugins/internal/randomfallback.py
+++ b/sima/plugins/internal/randomfallback.py
@@ -71,7 +71,7 @@ class RandomFallBack(Plugin):
return trks
def get_trk(self):
- """Get a single track acording to random flavour
+ """Get a single track according to random flavour
"""
trk = None
art = None
diff --git a/sima/utils/config.py b/sima/utils/config.py
index e9da8f8..b3a8d46 100644
--- a/sima/utils/config.py
+++ b/sima/utils/config.py
@@ -25,6 +25,7 @@ Parse configuration file and set defaults for missing options.
# IMPORTS
import configparser
+import logging
import sys
from configparser import Error
@@ -105,8 +106,8 @@ class ConfMan(object): # CONFIG MANAGER CLASS
* command line options (overrides previous)
"""
- def __init__(self, logger, options=None):
- self.log = logger
+ def __init__(self, options=None):
+ self.log = logging.getLogger('sima')
# options settings priority:
# defauts < env. var. < conf. file < command line
self.conf_file = options.get('conf_file')
@@ -122,20 +123,6 @@ class ConfMan(object): # CONFIG MANAGER CLASS
# generate dbfile
self.config['sima']['db_file'] = join(self.config['sima']['var_dir'], 'sima.db')
- def get_pw(self):
- try:
- self.config.getboolean('MPD', 'password')
- self.log.debug('No password set, proceeding without ' +
- 'authentication...')
- return None
- except ValueError:
- # ValueError if password not a boolean, hence an actual password.
- pwd = self.config.get('MPD', 'password')
- if not pwd:
- self.log.debug('Password set as an empty string.')
- return None
- return pwd
-
def control_mod(self):
"""
Controls conf file permissions.
--
mpd-sima packaging
More information about the pkg-multimedia-commits
mailing list