From 0a8ab5873662180652756c70486aa109eb00d97d Mon Sep 17 00:00:00 2001 From: kaliko <kaliko@azylum.org> 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 <kaliko@azylum.org> +.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/> +.\" 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 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + +`xsltproc -''-nonet \ + -''-param man.charmap.use.subset "0" \ + -''-param make.year.ranges "1" \ + -''-param make.single.year.ranges "1" \ + /usr/share/xml/docbook/stylesheet/nwalsh/manpages/docbook.xsl \ + manpage.xml' + +A manual page <package>.<section> will be generated. You may view the +manual page with: nroff -man <package>.<section> | less'. A typical entry +in a Makefile or Makefile.am is: + +DB2MAN = /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl +XP = xsltproc -''-nonet -''-param man.charmap.use.subset "0" + +manpage.1: manpage.xml + $(XP) $(DB2MAN) $< + +The xsltproc binary is found in the xsltproc package. The XSL files are in +docbook-xsl. A description of the parameters you can use can be found in the +docbook-xsl-doc-* packages. Please remember that if you create the nroff +version in one of the debian/rules file targets (such as build), you will need +to include xsltproc and docbook-xsl in your Build-Depends control field. +Alternatively use the xmlto command/package. That will also automatically +pull in xsltproc and docbook-xsl. + +Notes for using docbook2x: docbook2x-man does not automatically create the +AUTHOR(S) and COPYRIGHT sections. In this case, please add them manually as +<refsect1> ... </refsect1>. + +To disable the automatic creation of the AUTHOR(S) and COPYRIGHT sections +read /usr/share/doc/docbook-xsl/doc/manpages/authors.html. This file can be +found in the docbook-xsl-doc-html package. + +Validation can be done using: `xmllint -''-noout -''-valid manpage.xml` + +General documentation about man-pages and man-page-formatting: +man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ + +--> +<!DOCTYPE refentry [ + + <!ENTITY dhsection "1"> + <!ENTITY dhpackage "mpd-sima"> + <!ENTITY dhutils "test-tags-config"> + +]> + +<refentry xmlns="http://docbook.org/ns/docbook" + xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0"> + <xi:include href="info.xml" /> + <refmeta> + <refentrytitle>&dhutils;</refentrytitle> + <manvolnum>&dhsection;</manvolnum> + </refmeta> + <refnamediv> + <refname>&dhutils;</refname> + <refpurpose>controls tags plugin configuration.</refpurpose> + </refnamediv> + <refsynopsisdiv> + <cmdsynopsis> + <command>&dhutils;</command> + <arg choice="req"><option>config_file</option></arg> + </cmdsynopsis> + </refsynopsisdiv> + <refsect1 id="description"> + <title>DESCRIPTION</title> + <para>This manual page documents briefly the + <command>&dhutils;</command> commands.</para> + <para> + <command>&dhutils;</command> + will load <varname>config_file</varname> 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.<sbr /> + See also environment variables special case for MPD host and port in <xref linkend="environment"/>. + </para> + </refsect1> + <xi:include href="files.xml" /> + <refsect1 id="environment"> + <title>ENVIRONMENT</title> + <variablelist> + <varlistentry> + <term><envar>MPD_HOST</envar>, <envar>MPD_PORT</envar></term> + <listitem> + <para>&dhutils; will look for <envar>MPD_HOST</envar> and + <envar>MPD_PORT</envar> to override built-in configuration + (set to "localhost:6600").</para> + <para>&dhutils; expects <envar>MPD_HOST</envar> syntax as documented in mpc manual, + cf. <citerefentry><refentrytitle>mpc</refentrytitle><manvolnum>1</manvolnum></citerefentry>. + <sbr/>To use a password, provide a value of the form "password@host". + </para> + </listitem> + </varlistentry> + <varlistentry> + <term><envar>HTTP_PROXY</envar>, <envar>HTTPS_PROXY</envar></term> + <listitem> + <para>&dhutils; honors <envar>HTTP_PROXY</envar> environment variables.</para> + </listitem> + </varlistentry> + </variablelist> + </refsect1> + <xi:include href="feedback.xml" /> + <xi:include href="seealso.xml" /> +</refentry> 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 <kaliko@azylum.org> +# +# 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 <http://www.gnu.org/licenses/>. +# +# +"""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