]>
Commit | Line | Data |
---|---|---|
1df30f07 | 1 | # -*- coding: utf-8 -*- |
be27763f IB |
2 | from .music_file import * |
3 | from .mapping import * | |
ba9ea93a IB |
4 | from .lock import * |
5 | import yaml | |
8f88a3e4 | 6 | |
e7f8dab4 | 7 | def parse_config(mapping): |
8f88a3e4 IB |
8 | stream = open("config.yml", "r") |
9 | config = yaml.load(stream) | |
10 | stream.close() | |
11 | ||
12 | aliases = config['aliases'] | |
13 | seen_files = {} | |
14 | ||
ba9ea93a | 15 | file_lock = Lock("file") |
e7f8dab4 | 16 | |
d479af33 IB |
17 | channel_id = 0 |
18 | ||
8f88a3e4 | 19 | for mapped_key in config['keys']: |
e7f8dab4 | 20 | key = mapping.find_by_unicode(mapped_key) |
8f88a3e4 IB |
21 | if key is None: |
22 | continue | |
23 | ||
24 | for action in config['keys'][mapped_key]: | |
25 | action_name = list(action)[0] | |
26 | action_args = {} | |
27 | if action[action_name] is None: | |
28 | action[action_name] = [] | |
29 | ||
e7f8dab4 IB |
30 | if 'include' in action[action_name]: |
31 | included = action[action_name]['include'] | |
32 | del(action[action_name]['include']) | |
33 | ||
34 | if isinstance(included, str): | |
35 | action[action_name].update(aliases[included], **action[action_name]) | |
36 | else: | |
37 | for included_ in included: | |
38 | action[action_name].update(aliases[included_], **action[action_name]) | |
39 | ||
8f88a3e4 | 40 | for argument in action[action_name]: |
e7f8dab4 | 41 | if argument == 'file': |
8f88a3e4 IB |
42 | filename = action[action_name]['file'] |
43 | if filename not in seen_files: | |
d479af33 IB |
44 | seen_files[filename] = MusicFile(filename, file_lock, channel_id) |
45 | channel_id = channel_id + 1 | |
8f88a3e4 | 46 | |
d8ab67c7 | 47 | action_args['music'] = seen_files[filename] |
8f88a3e4 IB |
48 | |
49 | else: | |
50 | action_args[argument] = action[action_name][argument] | |
51 | ||
52 | key.add_action(action_name, **action_args) | |
b86db9f1 IB |
53 | |
54 | for key_property in config['key_properties']: | |
55 | key = mapping.find_by_unicode(key_property) | |
56 | if key is None: | |
57 | continue | |
58 | ||
59 | if 'description' in config['key_properties'][key_property]: | |
60 | key.set_description(config['key_properties'][key_property]['description']) | |
61 | if 'color' in config['key_properties'][key_property]: | |
62 | key.set_color(config['key_properties'][key_property]['color']) | |
d479af33 IB |
63 | |
64 | # Return the number of channels reserved | |
65 | return channel_id + 1 |