From b75a67a8ef2924dbcfdb9838d5b35447baf1e4be Mon Sep 17 00:00:00 2001 From: kaliko Date: Thu, 22 Apr 2021 15:15:15 +0200 Subject: [PATCH] Add new command (closes #43) Add config-test, create-db, generate-config --- data/man/Makefile | 5 +- data/man/mpd-sima.1 | 69 ++++++++++------ data/man/mpd_sima.1.xml | 62 +++++++++------ data/man/test-tags-config.1 | 137 -------------------------------- data/man/test-tags-config.1.xml | 104 ------------------------ doc/Changelog | 4 + setup.py | 5 +- sima/launch.py | 33 +++++++- sima/utils/configtest.py | 51 ++++++++++++ sima/utils/startopt.py | 58 +++++++------- sima/utils/testtags.py | 75 ----------------- 11 files changed, 198 insertions(+), 405 deletions(-) delete mode 100644 data/man/test-tags-config.1 delete mode 100644 data/man/test-tags-config.1.xml create mode 100644 sima/utils/configtest.py delete mode 100644 sima/utils/testtags.py diff --git a/data/man/Makefile b/data/man/Makefile index 7871223..32a68b7 100644 --- a/data/man/Makefile +++ b/data/man/Makefile @@ -16,9 +16,6 @@ OPTIONS=--nonet\ all: man -test-tags-config: test-tags-config.1.xml - xmllint --xinclude --nowarning --noent $< | $(XP) $(OPTIONS) $(XSL) - - simadb_cli: simadb_cli.1.xml xmllint --xinclude --nowarning --noent $< | $(XP) $(OPTIONS) $(XSL) - @@ -37,7 +34,7 @@ simadb_cli_html: mpd_sima.cfg_html: xmllint --xinclude --nowarning --noent mpd_sima.cfg.5.xml | $(XP) $(HXSL) - > ./mpd_sima.cfg.5.html -man: test-tags-config simadb_cli mpd_sima mpd_sima.cfg +man: simadb_cli mpd_sima mpd_sima.cfg html: simadb_cli_html mpd_sima_html mpd_sima.cfg_html diff --git a/data/man/mpd-sima.1 b/data/man/mpd-sima.1 index 9d26e92..b676ecd 100644 --- a/data/man/mpd-sima.1 +++ b/data/man/mpd-sima.1 @@ -2,12 +2,12 @@ .\" Title: mpd-sima .\" Author: kaliko .\" Generator: DocBook XSL Stylesheets v1.79.2 -.\" Date: 04/19/2021 +.\" Date: 04/22/2021 .\" Manual: mpd-sima 0.17.0 User Manual .\" Source: mpd-sima .\" Language: English .\" -.TH "MPD\-SIMA" "1" "04/19/2021" "mpd-sima" "mpd-sima 0.17.0 User Manual" +.TH "MPD\-SIMA" "1" "04/22/2021" "mpd-sima" "mpd-sima 0.17.0 User Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -33,11 +33,13 @@ 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 \-\-create\-db [\fB\-\-var\-dir=\fR\fIvar_directory\fR] +\fBmpd\-sima\fR {{\fB\-h\fR\ |\ \fB\-\-help\fR}\ \fB\-\-version\fR} .HP \w'\fBmpd\-sima\fR\ 'u -\fBmpd\-sima\fR \-\-generate\-config [\fB\&...\fR] +\fBmpd\-sima\fR config\-test [\fB\-\-config=\fR\fIconf_file\fR] .HP \w'\fBmpd\-sima\fR\ 'u -\fBmpd\-sima\fR {{\fB\-h\fR\ |\ \fB\-\-help\fR}\ \fB\-\-version\fR} +\fBmpd\-sima\fR create\-db [\fB\-\-var\-dir=\fR\fIvar_directory\fR] +.HP \w'\fBmpd\-sima\fR\ 'u +\fBmpd\-sima\fR generate\-config [\fB\&...\fR] .SH "DESCRIPTION" .PP This manual page documents briefly the @@ -148,25 +150,7 @@ Default is to look in \fB$XDG_DATA_HOME/mpd_sima/\fR\&. Concerning \fB$XDG_DATA_HOME\fR 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 -\fB\-\-var\-dir\fR -or default directory\&. -.br -Default is to use -\fB$XDG_DATA_HOME/mpd_sima/\fR\&. Concerning -\fB$XDG_DATA_HOME\fR -see also -the section called \(lqFILES\(rq +the section called \(lqFILES\(rq\&. .RE .PP \fB\-S \fR\fB\fImpd_host\fR\fR, \fB\-\-host=\fR\fB\fImpd_host\fR\fR @@ -203,6 +187,39 @@ Default is See also the section called \(lqENVIRONMENT\(rq .RE +.PP +\fBconfig\-test\fR +.RS 4 +Test configuration file and exit\&. Uses the configuration file specified with +\fB\-\-config\fR +or default location\&. +.br +Default is to use +\fB$XDG_CONFIG_HOME/mpd_sima/mpd_sima\&.cfg\fR +(see +the section called \(lqFILES\(rq +for more)\&. +.sp +config\-test tests MPD connection and Tags plugin configuration\&. +.RE +.PP +\fBcreate\-db\fR +.RS 4 +Create the database and exit\&. Uses folder specified with +\fB\-\-var\-dir\fR +or default directory\&. +.br +Default is to use +\fB$XDG_DATA_HOME/mpd_sima/\fR +(see +the section called \(lqFILES\(rq +for more)\&. +.RE +.PP +\fBgenerate\-config\fR +.RS 4 +Generate a sample configuration file according to the current CLI options and env\&. var\&.\&. The configuration is written on stdout\&. +.RE .SH "FILES" .PP ${XDG_CONFIG_HOME}/mpd_sima/mpd_sima\&.cfg @@ -272,11 +289,11 @@ doc/examples/\&. On Debian system please look in .PP DEFAULTS .RS 4 -Default is to look for MPD server at localhost:6600 (or MPD_HOST/MPD_PORT env\&. var\&. if set)\&. +Default is to look for MPD server at localhost:6600 (or MPD_HOST/MPD_PORT env\&. var\&. if set)\&. The default plugins will use Last\&.fm to find similar tracks to queue and fallback to random if nothing if found\&. .sp The get the defaults as detected by mpd\-sima on your system you can run mpd\-sima to print the config: .sp -\fBmpd\-sima \-\-generate\-config\fR +\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 16810bd..7d4269a 100644 --- a/data/man/mpd_sima.1.xml +++ b/data/man/mpd_sima.1.xml @@ -71,16 +71,6 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ mpd_host mpd_port - - &dhpackage; - --create-db - var_directory - - - &dhpackage; - --generate-config - - &dhpackage; - 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. - - - - - - Create the database and exit. Uses folder specified with or default directory.Default is to use $XDG_DATA_HOME/mpd_sima/. Concerning $XDG_DATA_HOME see also + 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 . @@ -223,6 +216,25 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ See also + + + + Test configuration file and exit. Uses the configuration file specified with or default location.Default is to use $XDG_CONFIG_HOME/mpd_sima/mpd_sima.cfg (see for more). + config-test tests MPD connection and Tags plugin configuration. + + + + + + Create the database and exit. Uses folder specified with or default directory.Default is to use $XDG_DATA_HOME/mpd_sima/ (see for more). + + + + + + Generate a sample configuration file according to the current CLI options and env. var.. The configuration is written on stdout. + + @@ -266,9 +278,9 @@ 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). + Default is to look for MPD server at localhost:6600 (or MPD_HOST/MPD_PORT env. var. if set). The default plugins will use Last.fm to find similar tracks to queue and fallback to random if nothing if found. The get the defaults as detected by &dhpackage; on your system you can run &dhpackage; to print the config: - &dhpackage; --generate-config + &dhpackage; generate-config diff --git a/data/man/test-tags-config.1 b/data/man/test-tags-config.1 deleted file mode 100644 index 0f5c7f6..0000000 --- a/data/man/test-tags-config.1 +++ /dev/null @@ -1,137 +0,0 @@ -'\" t -.\" Title: test-tags-config -.\" Author: kaliko -.\" Generator: DocBook XSL Stylesheets v1.79.1 -.\" Date: 01/09/2021 -.\" Manual: mpd-sima 0.16.1 User Manual -.\" Source: mpd-sima -.\" Language: English -.\" -.TH "TEST\-TAGS\-CONFIG" "1" "01/09/2021" "mpd-sima" "mpd-sima 0.16.1 User Manual" -.\" ----------------------------------------------------------------- -.\" * Define some portability stuff -.\" ----------------------------------------------------------------- -.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.\" http://bugs.debian.org/507673 -.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html -.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.ie \n(.g .ds Aq \(aq -.el .ds Aq ' -.\" ----------------------------------------------------------------- -.\" * set default formatting -.\" ----------------------------------------------------------------- -.\" disable hyphenation -.nh -.\" disable justification (adjust text to left margin only) -.ad l -.\" ----------------------------------------------------------------- -.\" * MAIN CONTENT STARTS HERE * -.\" ----------------------------------------------------------------- -.SH "NAME" -test-tags-config \- controls tags plugin configuration\&. -.SH "SYNOPSIS" -.HP \w'\fBtest\-tags\-config\fR\ 'u -\fBtest\-tags\-config\fR {\fBconfig_file\fR} -.SH "DESCRIPTION" -.PP -This manual page documents briefly the -\fBtest\-tags\-config\fR -commands\&. -.PP -\fBtest\-tags\-config\fR -will load -\fIconfig_file\fR -passed as argument and look for tags plugin configuration to query MPD with it\&. There is no attempt to auto\-discover configuration file, positional argument is required\&. -.br - -See also environment variables special case for MPD host and port in -the section called \(lqENVIRONMENT\(rq\&. -.SH "FILES" -.PP -${XDG_CONFIG_HOME}/mpd_sima/mpd_sima\&.cfg -.RS 4 -Configuration file\&. -.RE -.PP -${XDG_DATA_HOME}/mpd_sima/sima\&.db -.RS 4 -SQLite DB file\&. -.RE -.PP -${XDG_DATA_HOME}/mpd_sima/WEB_SERVICE/ -.RS 4 -Persistent http cache\&. -.RE -.PP -Usually -\fBXDG_DATA_HOME\fR -is set to -${HOME}/\&.local/share -and -\fBXDG_CONFIG_HOME\fR -to -${HOME}/\&.config\&. -.br -You may override them using command line option -\fB\-\-var\-dir\fR -and -\fB\-\-config\fR -(cf\&. -\fBmpd-sima\fR(1)) -.SH "ENVIRONMENT" -.PP -\fBMPD_HOST\fR, \fBMPD_PORT\fR -.RS 4 -test\-tags\-config will look for -\fBMPD_HOST\fR -and -\fBMPD_PORT\fR -to override built\-in configuration (set to "localhost:6600")\&. -.sp -test\-tags\-config expects -\fBMPD_HOST\fR -syntax as documented in mpc manual, cf\&. -\fBmpc\fR(1)\&. - -.br -To use a password, provide a value of the form "password@host"\&. -.RE -.PP -\fBHTTP_PROXY\fR, \fBHTTPS_PROXY\fR -.RS 4 -test\-tags\-config honors -\fBHTTP_PROXY\fR -environment variables\&. -.RE -.SH "FEEDBACK/BUGS" -.PP -The maintainer would be more than happy to ear from you, don\*(Aqt hesitate to send feedback, -\m[blue]\fB\%https://kaliko.me/contact/\fR\m[]\&. -.PP -XMPP -users are welcome to join the dedicated chat room at -\m[blue]\fBkaliko\&.me@conf\&.azylum\&.org\fR\m[]\&. -.SH "SEE ALSO" -.PP -\fBmpc\fR(1), -\fBmpd\fR(1) -.PP -/usr/share/doc/mpd\-sima/ -.SH "AUTHOR" -.PP -\fBkaliko\fR <\&kaliko@azylum\&.org\&> -.RS 4 -Wrote this man page and is currently leading MPD_sima project\&. -.RE -.SH "COPYRIGHT" -.br -Copyright \(co 2009-2021 kaliko -.br -.PP -This manual page was written for the Debian system (and may be used by others)\&. -.PP -Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 3 published by the Free Software Foundation\&. -.PP -On Debian systems, the complete text of the GNU General Public License can be found in -/usr/share/common\-licenses/GPL\&. -.sp diff --git a/data/man/test-tags-config.1.xml b/data/man/test-tags-config.1.xml deleted file mode 100644 index a62dd24..0000000 --- a/data/man/test-tags-config.1.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - -]> - - - - - &dhutils; - &dhsection; - - - &dhutils; - controls tags plugin configuration. - - - - &dhutils; - - - - - DESCRIPTION - This manual page documents briefly the - &dhutils; commands. - - &dhutils; - will load config_file passed as argument and look for tags plugin configuration to query MPD with it. There is no attempt to auto-discover configuration file, positional argument is required. - See also environment variables special case for MPD host and port in . - - - - - ENVIRONMENT - - - MPD_HOST, MPD_PORT - - &dhutils; will look for MPD_HOST and - MPD_PORT to override built-in configuration - (set to "localhost:6600"). - &dhutils; expects MPD_HOST syntax as documented in mpc manual, - cf. mpc1. - To use a password, provide a value of the form "password@host". - - - - - HTTP_PROXY, HTTPS_PROXY - - &dhutils; honors HTTP_PROXY environment variables. - - - - - - - diff --git a/doc/Changelog b/doc/Changelog index ede8139..e56ec8b 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -6,6 +6,10 @@ MPD_sima v0.17.0.dev0 * Fixed "artist with quotes not found" (closes #41) * Fixed bad pid in Uniq core plugin (closes #32) * Use duration instead of time in Track objects (closes #37) + * Move "test-tags-config" as positional argument "config-test" + * Move "--create-db" as positional argument "create-db" + * Add commands as positional arguments: + config-test, create-db, generate-config -- kaliko UNRELEASED diff --git a/setup.py b/setup.py index 6b18161..0630a78 100755 --- a/setup.py +++ b/setup.py @@ -11,8 +11,8 @@ from sima.info import __version__ as VERSION, __author__ as AUTHOR from sima.info import __doc__ as DESCRIPTION, __email__ as EMAIL data_files = [ - ('share/man/man1', ['data/man/mpd-sima.1', 'data/man/simadb_cli.1', 'data/man/test-tags-config.1']), - ('share/man/man5', ['data/man/mpd_sima.cfg.5',]), + ('share/man/man1', ['data/man/mpd-sima.1', 'data/man/simadb_cli.1']), + ('share/man/man5', ['data/man/mpd_sima.cfg.5']), ('share/doc/mpd-sima/examples/', glob.glob('doc/examples/*')), ('share/doc/mpd-sima/', [fi for fi in listdir('doc') if isfile(fi)]), ] @@ -50,7 +50,6 @@ setup(name='MPD_sima', entry_points={ 'console_scripts': [ 'mpd-sima = sima.launch:main', - 'test-tags-config = sima.utils.testtags:main' ] }, test_suite="tests", diff --git a/sima/launch.py b/sima/launch.py index 68ba4e0..a8e285e 100644 --- a/sima/launch.py +++ b/sima/launch.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2013, 2014, 2015, 2020 kaliko +# Copyright (c) 2013, 2014, 2015, 2020,2021 kaliko # # This file is part of sima # @@ -79,13 +79,39 @@ def start(sopt, restart=False): """starts application """ # loads configuration - config = ConfMan(sopt.options).config + cfg_mgmt = ConfMan(sopt.options) + config = cfg_mgmt.config # set logger logger = logging.getLogger('sima') logfile = config.get('log', 'logfile', fallback=None) verbosity = config.get('log', 'verbosity') set_logger(verbosity, logfile) logger.debug('Command line say: %s', sopt.options) + + if sopt.options.get('command'): + cmd = sopt.options.get('command') + if cmd == "generate-config": + config.write(sys.stdout, space_around_delimiters=True) + sys.exit(0) + logger.info('Running "%s" and exit' % cmd) + if cmd == "config-test": + logger.info('Config location: "%s"', cfg_mgmt.conf_file) + from .utils.configtest import config_test + config_test(config) + sys.exit(0) + if cmd == "create-db": + db_file = config.get('sima', 'db_file') + if not isfile(db_file): + logger.info('Creating database in "%s"', 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...') + else: + logger.info('Database already there, not overwriting %s', db_file) + sys.exit(0) + + # TODO: To remove eventually in next major realese v0.18 # Create Database db_file = config.get('sima', 'db_file') if (sopt.options.get('create_db', None) @@ -95,8 +121,9 @@ def start(sopt, restart=False): SimaDB(db_path=db_file).create_db() if sopt.options.get('create_db', None): logger.info('Done, bye...') - sys.exit(0) + sys.exit(0) + # TODO: To remove eventually in next major realese v0.18 if sopt.options.get('generate_config'): config.write(sys.stdout, space_around_delimiters=True) sys.exit(0) diff --git a/sima/utils/configtest.py b/sima/utils/configtest.py new file mode 100644 index 0000000..b777276 --- /dev/null +++ b/sima/utils/configtest.py @@ -0,0 +1,51 @@ +# coding: utf-8 + +import sys + +from logging import getLogger + +from ..mpdclient import MPD +from ..mpdclient import MPDError, PlayerError + +from ..plugins.internal.tags import forge_filter, control_config + +log = getLogger('sima') + + +def tags_config_test(cli, config): + tags_cfg = config['tags'] + if not control_config(tags_cfg): + return + filt = forge_filter(tags_cfg) + log.info('Trying tags and filter config:') + log.info('%s', filt) + try: + # Use window to limit reponse size + res = cli.find(filt, 'window', (0, 300)) + except MPDError as err: + cli.disconnect() + print('filter error: %s' % err, file=sys.stderr) + sys.exit(1) + artists = list({trk.albumartist for trk in res if trk.albumartist}) + if not artists: + log.info('Tags config correct but got nothing from MPD\'s library') + return + log.info('Got results, here are some of the artists found:') + log.info('%s', ' / '.join(artists[:6])) + + +def config_test(config): + cli = MPD(config) + log.info('Trying to connect MPD: %s:%s', + config.get('MPD', 'host'), + config.get('MPD', 'port')) + try: + cli.connect() + except PlayerError as err: + print(err, file=sys.stderr) + sys.exit(1) + tags_config_test(cli, config) + + +# VIM MODLINE +# vim: ai ts=4 sw=4 sts=4 expandtab fileencoding=utf8 diff --git a/sima/utils/startopt.py b/sima/utils/startopt.py index 16ad773..a1824ee 100644 --- a/sima/utils/startopt.py +++ b/sima/utils/startopt.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009-2015 kaliko +# Copyright (c) 2009-2015, 2021 kaliko # # This file is part of sima # @@ -19,14 +19,19 @@ # # -from argparse import (ArgumentParser, SUPPRESS) +from argparse import ArgumentParser, RawDescriptionHelpFormatter, SUPPRESS from .utils import Wfile, Rfile, Wdir DESCRIPTION = """ MPD_sima automagicaly queue new tracks in MPD playlist. -Command line options override their equivalent in configuration file.""" + +Command line options override their equivalent in configuration file. +If a positional arguments is provided MPD_sima execute the command and returns. +Commands available: +{} +""" def clean_dict(to_clean): @@ -35,7 +40,11 @@ def clean_dict(to_clean): if not to_clean.get(k): to_clean.pop(k) - +# COMMANDS LIST +CMDS = {'config-test': 'Test configuration (MPD connection and Tags plugin only)', + 'create-db': 'Create the database', + 'generate-config': 'Generate a configuration file to stdout', + } # OPTIONS LIST # pop out 'sw' value before creating Parser object. # PAY ATTENTION: @@ -46,13 +55,13 @@ def clean_dict(to_clean): # name it is meant to override. OPTS = [ { - 'sw':['-l', '--log'], + 'sw': ['-l', '--log'], 'type': str, 'dest': 'logfile', 'action': Wfile, 'help': 'file to log message to, default is stdout/stderr'}, { - 'sw':['-v', '--log-level'], + 'sw': ['-v', '--log-level'], 'type': str, 'dest': 'verbosity', 'choices': ['debug', 'info', 'warning', 'error'], @@ -77,39 +86,30 @@ OPTS = [ 'dest': 'port', 'help': 'Port MPD in listening on'}, { - 'sw':['-c', '--config'], + 'sw': ['-c', '--config'], 'dest': 'conf_file', 'action': Rfile, 'help': 'Configuration file to load'}, - { - 'sw':['--generate-config'], + { # TODO: To remove eventually in next major realese v0.18 + '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.'}, + 'help': SUPPRESS}, { - 'sw':['--var-dir', '--var_dir'], + 'sw': ['--var-dir', '--var_dir'], 'dest': 'var_dir', 'action': Wdir, 'help': 'Directory to store var content (ie. database, cache)'}, - { + { # TODO: To remove eventually in next major realese v0.18 'sw': ['--create-db'], 'action': 'store_true', 'dest': 'create_db', - 'help': '''Create database and exit, use destination - specified in --var-dir or standard location.'''}, - { - 'sw':['--queue-mode', '-q'], - 'dest': 'queue_mode', - 'choices': ['track', 'top', 'album'], - #'help': 'Queue mode in [track, top, album]', - 'help': SUPPRESS, }, - { - 'sw':['--purge-history'], - 'action': 'store_true', - 'dest': 'do_purge_history', 'help': SUPPRESS}, + { + 'sw': ['command'], + 'nargs': '?', + 'choices': CMDS.keys(), + 'help': 'Command to run (cf. description or unix manual for more)'}, ] @@ -127,10 +127,12 @@ class StartOpt: """ Declare options in ArgumentParser object. """ - self.parser = ArgumentParser(description=DESCRIPTION, + cmds = '\n'.join([f' * {k}: {v}' for k, v in CMDS.items()]) + self.parser = ArgumentParser(description=DESCRIPTION.format(cmds), prog=self.info.get('prog'), epilog='Happy Listening', - ) + formatter_class=RawDescriptionHelpFormatter, + ) self.parser.add_argument('--version', action='version', version='%(prog)s {version}'.format(**self.info)) # Add all options declare in OPTS diff --git a/sima/utils/testtags.py b/sima/utils/testtags.py deleted file mode 100644 index 7a7fd39..0000000 --- a/sima/utils/testtags.py +++ /dev/null @@ -1,75 +0,0 @@ -# coding: utf-8 -# Copyright (c) 2020 kaliko -# -# This file is part of sima -# -# sima is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# sima is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with sima. If not, see . -# -# -"""Testing Tags plugin config -""" - -import argparse -import os.path -import sys - -from configparser import ConfigParser - -import musicpd - -from ..plugins.internal.tags import forge_filter - - -def is_valid_file(parser, arg): - if not os.path.exists(arg) or not os.path.isfile(arg): - parser.error('The file "%s" does not exist!' % arg) - return arg - - -def main(): - parser = argparse.ArgumentParser(description='Tests Tags plugin config') - parser.add_argument('config', nargs=1, - type=lambda x: is_valid_file(parser, x)) - pargs = parser.parse_args(sys.argv[1:]) - conf = ConfigParser() - conf.read(pargs.config) - if not conf['tags']: - print('Nothing in "tags" section', file=sys.stderr) - sys.exit(1) - tags_cfg = conf['tags'] - filt = forge_filter(tags_cfg) - print(f'Filter forged: "{filt}"') - host = conf['MPD'].get('host', None) - port = conf['MPD'].get('port', None) - cli = musicpd.MPDClient() - try: - cli.connect(host=host, port=port) - except musicpd.ConnectionError as err: - print(err, file=sys.stderr) - sys.exit(1) - try: - res = cli.find(filt) - except musicpd.CommandError as err: - cli.disconnect() - print(err, file=sys.stderr) - sys.exit(1) - print({trk.get('artist', 'ukn') for trk in res}) - - -# Script starts here -if __name__ == '__main__': - main() - -# VIM MODLINE -# vim: ai ts=4 sw=4 sts=4 expandtab fileencoding=utf8 -- 2.39.5