2 # Copyright (c) 2020 kaliko <kaliko@azylum.org>
4 # This file is part of sima
6 # sima is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # sima is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with sima. If not, see <http://www.gnu.org/licenses/>.
20 """Testing Tags plugin config
27 from configparser import ConfigParser
31 from ..plugins.internal.tags import forge_filter
34 def is_valid_file(parser, arg):
35 if not os.path.exists(arg) or not os.path.isfile(arg):
36 parser.error('The file "%s" does not exist!' % arg)
42 parser = argparse.ArgumentParser(description='Tests Tags plugin config')
43 parser.add_argument('config', nargs=1,
44 type=lambda x: is_valid_file(parser, x))
45 pargs = parser.parse_args(sys.argv[1:])
47 conf.read(pargs.config)
49 print('Nothing in "tags" section', file=sys.stderr)
51 tags_cfg = conf['tags']
52 filt = forge_filter(tags_cfg)
53 print(f'Filter forged: "{filt}"')
54 host = conf['MPD'].get('host', None)
55 port = conf['MPD'].get('port', None)
56 cli = musicpd.MPDClient()
58 cli.connect(host=host, port=port)
59 except musicpd.ConnectionError as err:
60 print(err, file=sys.stderr)
64 except musicpd.CommandError as err:
66 print(err, file=sys.stderr)
68 print({trk.get('artist', 'ukn') for trk in res})
72 if __name__ == '__main__':
76 # vim: ai ts=4 sw=4 sts=4 expandtab fileencoding=utf8