From fe1ed51724531b8c1e78e7d7eb590c9be20e275c Mon Sep 17 00:00:00 2001 From: kaliko Date: Thu, 12 Feb 2015 14:27:42 +0100 Subject: [PATCH] Add option to generate config on stdout --- data/man/mpd-sima.1 | 20 +++++++++++++------- data/man/mpd_sima.1.xml | 27 +++++++++++++++++---------- doc/Changelog | 1 + sima/client.py | 4 ++-- sima/launch.py | 6 +++++- sima/utils/config.py | 4 ++-- sima/utils/startopt.py | 7 +++++++ 7 files changed, 47 insertions(+), 22 deletions(-) diff --git a/data/man/mpd-sima.1 b/data/man/mpd-sima.1 index 2aa20a9..3e9f6be 100644 --- a/data/man/mpd-sima.1 +++ b/data/man/mpd-sima.1 @@ -2,12 +2,12 @@ .\" Title: mpd-sima .\" Author: Jack Kaliko .\" Generator: DocBook XSL Stylesheets v1.78.1 -.\" Date: 02/08/2015 +.\" Date: 02/12/2015 .\" Manual: mpd-sima 0.14.0 User Manual .\" Source: mpd-sima .\" Language: English .\" -.TH "MPD\-SIMA" "1" "02/08/2015" "mpd-sima" "mpd-sima 0.14.0 User Manual" +.TH "MPD\-SIMA" "1" "02/12/2015" "mpd-sima" "mpd-sima 0.14.0 User Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -33,9 +33,11 @@ mpd-sima \- mpd\-sima will try to maintain some titles ahead in the queue follow .HP \w'\fBmpd\-sima\fR\ 'u \fBmpd\-sima\fR [\fB\-\-daemon\fR] [\fB\-\-config=\fR\fIconf_file\fR] [\fB\-\-var_dir=\fR\fIvar_directory\fR] [\fB\-\-pid=\fR\fIpid_file\fR] [\fB\-\-log=\fR\fIlog_file\fR] [\fB\-\-log\-level=\fR\fIlog_level\fR] [\fB\-\-host=\fR\fImpd_host\fR] [\fB\-\-mpd_port=\fR\fImpd_port\fR] .HP \w'\fBmpd\-sima\fR\ 'u -\fBmpd\-sima\fR [\fB\-\-var_dir=\fR\fIvar_directory\fR] [\fB\-\-create\-db\fR] +\fBmpd\-sima\fR \-\-create\-db [\fB\-\-var_dir=\fR\fIvar_directory\fR] .HP \w'\fBmpd\-sima\fR\ 'u -\fBmpd\-sima\fR [{\fB\-h\fR\ |\ \fB\-\-help\fR} | \fB\-\-version\fR] +\fBmpd\-sima\fR \-\-generate\-config [\fB\&...\fR] +.HP \w'\fBmpd\-sima\fR\ 'u +\fBmpd\-sima\fR {{\fB\-h\fR\ |\ \fB\-\-help\fR}\ \fB\-\-version\fR} .SH "DESCRIPTION" .PP This manual page documents briefly the @@ -149,6 +151,11 @@ see also the section called \(lqFILES\(rq .RE .PP +\fB\-\-generate\-config\fR +.RS 4 +Generate a sample configuration file according to the current configuration\&. You can put other options with this one to get them in the generated configuration\&. +.RE +.PP \fB\-\-create\-db\fR .RS 4 Create the database and exit\&. Uses folder specified with @@ -258,10 +265,9 @@ DEFAULTS .RS 4 Default is to look for MPD server at localhost:6600 (or MPD_HOST/MPD_PORT env\&. var\&. if set)\&. .sp -The default behavior is to add one track, this track is to be chosen among titles from artists similar to the last artist in the queue\&. MPD_sima will add one track when the unplayed queue is one track long\&. +The get the defaults as detected by mpd\-sima on your system you can run mpd\-sima to print the config: .sp -To change these defaults, use the configuration file -mpd_sima\&.cfg +\fBmpd\-sima \-\-generate\-config\fR .RE .PP For details about mpd_sima\&.cfg refer to the manual diff --git a/data/man/mpd_sima.1.xml b/data/man/mpd_sima.1.xml index 48cf028..9a36ee5 100644 --- a/data/man/mpd_sima.1.xml +++ b/data/man/mpd_sima.1.xml @@ -73,21 +73,26 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ &dhpackage; + --create-db var_directory - + + + &dhpackage; + --generate-config + &dhpackage; - - + + + - @@ -190,6 +195,12 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ Use the specific path var_directory to look for (or create) var files (ie. database) instead of looking at the default user data location.Default is to look in $XDG_DATA_HOME/mpd_sima/. Concerning $XDG_DATA_HOME see also + + + + Generate a sample configuration file according to the current configuration. You can put other options with this one to get them in the generated configuration. + + @@ -250,12 +261,8 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ DEFAULTS Default is to look for MPD server at localhost:6600 (or MPD_HOST/MPD_PORT env. var. if set). - The default behavior is to add one track, this - track is to be chosen among titles from artists - similar to the last artist in the queue. MPD_sima - will add one track when the unplayed queue is one - track long. - To change these defaults, use the configuration file mpd_sima.cfg + The get the defaults as detected by &dhpackage; on your system you can run &dhpackage; to print the config: + &dhpackage; --generate-config diff --git a/doc/Changelog b/doc/Changelog index 2a1bbf0..87f6b04 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,6 @@ MPD_sima v0.14.0 + * Add option to generate config on stdout * Add priority feature for plugins * More robust MPD client * Fixed top track mode diff --git a/sima/client.py b/sima/client.py index e171c0b..66894a7 100644 --- a/sima/client.py +++ b/sima/client.py @@ -206,9 +206,9 @@ class PlayerClient(Player): if artist.mbid: # we already performed a lookup on artists with mbid set # search through remaining artists - artists = self._cache.get('nombid_artists', []) + artists = self._cache.get('nombid_artists') else: - artists = self._cache.get('artists', []) + artists = self._cache.get('artists') match = get_close_matches(artist.name, artists, 50, 0.73) if not match and not found: return diff --git a/sima/launch.py b/sima/launch.py index 2e2d1dd..9fb0b2d 100644 --- a/sima/launch.py +++ b/sima/launch.py @@ -83,7 +83,7 @@ def start(sopt, restart=False): verbosity = sopt.options.get('verbosity', 'warning') # loads configuration config = ConfMan(sopt.options).config - logfile = config.get('log', 'logfile') + logfile = config.get('log', 'logfile', fallback=None) verbosity = config.get('log', 'verbosity') set_logger(verbosity, logfile) logger = logging.getLogger('sima') @@ -99,6 +99,10 @@ def start(sopt, restart=False): logger.info('Done, bye...') sys.exit(0) + if sopt.options.get('generate_config'): + config.write(sys.stdout, space_around_delimiters=True) + sys.exit(0) + logger.info('Starting...') sima = core.Sima(config) diff --git a/sima/utils/config.py b/sima/utils/config.py index f7ec982..168938a 100644 --- a/sima/utils/config.py +++ b/sima/utils/config.py @@ -137,8 +137,8 @@ class ConfMan(object): # CONFIG MANAGER CLASS argparse. """ ok = True - for op, ftochk in [('log', self.config['log']['logfile']), - ('pidfile', self.config['daemon']['pidfile']),]: + for op, ftochk in [('logfile', self.config.get('log','logfile')), + ('pidfile', self.config.get('daemon', 'pidfile')),]: if not ftochk: continue if isdir(ftochk): diff --git a/sima/utils/startopt.py b/sima/utils/startopt.py index 51319f6..2081c19 100644 --- a/sima/utils/startopt.py +++ b/sima/utils/startopt.py @@ -81,6 +81,13 @@ OPTS = [ 'dest': 'conf_file', 'action': Rfile, 'help': 'Configuration file to load'}, + { + 'sw':['--generate-config'], + 'dest': 'generate_config', + 'action': 'store_true', + 'help': 'Generate a sample configuration file to stdout according to the current\ + configuration. You can put other options with this one to get them in\ + the generated configuration.'}, { 'sw':['--var_dir'], 'dest': 'var_dir', -- 2.39.2