From 0a8ab5873662180652756c70486aa109eb00d97d Mon Sep 17 00:00:00 2001 From: kaliko Date: Tue, 15 Dec 2020 14:46:43 +0100 Subject: [PATCH] Add test-tags-config helper --- data/man/Makefile | 5 +- data/man/test-tags-config.1 | 137 ++++++++++++++++++++++++++++++++ data/man/test-tags-config.1.xml | 104 ++++++++++++++++++++++++ doc/Changelog | 1 + setup.py | 5 +- sima/utils/testtags.py | 76 ++++++++++++++++++ 6 files changed, 326 insertions(+), 2 deletions(-) create mode 100644 data/man/test-tags-config.1 create mode 100644 data/man/test-tags-config.1.xml create mode 100644 sima/utils/testtags.py diff --git a/data/man/Makefile b/data/man/Makefile index 32a68b7..7871223 100644 --- a/data/man/Makefile +++ b/data/man/Makefile @@ -16,6 +16,9 @@ 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) - @@ -34,7 +37,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: simadb_cli mpd_sima mpd_sima.cfg +man: test-tags-config simadb_cli mpd_sima mpd_sima.cfg html: simadb_cli_html mpd_sima_html mpd_sima.cfg_html diff --git a/data/man/test-tags-config.1 b/data/man/test-tags-config.1 new file mode 100644 index 0000000..055f7ea --- /dev/null +++ b/data/man/test-tags-config.1 @@ -0,0 +1,137 @@ +'\" t +.\" Title: test-tags-config +.\" Author: kaliko +.\" Generator: DocBook XSL Stylesheets v1.79.1 +.\" Date: 12/15/2020 +.\" Manual: mpd-sima 0.16.0 User Manual +.\" Source: mpd-sima +.\" Language: English +.\" +.TH "TEST\-TAGS\-CONFIG" "1" "12/15/2020" "mpd-sima" "mpd-sima 0.16.0 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-2020 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 new file mode 100644 index 0000000..a62dd24 --- /dev/null +++ b/data/man/test-tags-config.1.xml @@ -0,0 +1,104 @@ + + + + + + +]> + + + + + &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 f4aaa7d..12d5a1e 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,7 @@ MPD_sima v0.16.0 * New offline autoqueue plugin based on file tags only + * Expose a new executable "test-tags-config" * Update vinstall.py (closes #34) * Fixed bug when http client fetches a corrupted cached entry (closes #35) * Need at least python 3.6 diff --git a/setup.py b/setup.py index 8e6246c..bff0d80 100755 --- a/setup.py +++ b/setup.py @@ -48,7 +48,10 @@ setup(name='MPD_sima', data_files=data_files, scripts=['simadb_cli'], entry_points={ - 'console_scripts': ['mpd-sima = sima.launch:main',] + 'console_scripts': [ + 'mpd-sima = sima.launch:main', + 'test-tags-config = sima.utils.testtags:main' + ] }, test_suite="tests", ) diff --git a/sima/utils/testtags.py b/sima/utils/testtags.py new file mode 100644 index 0000000..a779dc3 --- /dev/null +++ b/sima/utils/testtags.py @@ -0,0 +1,76 @@ +# 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) + else: + 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