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