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)
41 parser = argparse.ArgumentParser(description='Tests Tags plugin config')
42 parser.add_argument('config', nargs=1,
43 type=lambda x: is_valid_file(parser, x))
44 pargs = parser.parse_args(sys.argv[1:])
46 conf.read(pargs.config)
48 print('Nothing in "tags" section', file=sys.stderr)
50 tags_cfg = conf['tags']
51 filt = forge_filter(tags_cfg)
52 print(f'Filter forged: "{filt}"')
53 host = conf['MPD'].get('host', None)
54 port = conf['MPD'].get('port', None)
55 cli = musicpd.MPDClient()
57 cli.connect(host=host, port=port)
58 except musicpd.ConnectionError as err:
59 print(err, file=sys.stderr)
63 except musicpd.CommandError as err:
65 print(err, file=sys.stderr)
67 print({trk.get('artist', 'ukn') for trk in res})
71 if __name__ == '__main__':
75 # vim: ai ts=4 sw=4 sts=4 expandtab fileencoding=utf8