]>
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 | |
8f88a3e4 | 17 | for mapped_key in config['keys']: |
e7f8dab4 | 18 | key = mapping.find_by_unicode(mapped_key) |
8f88a3e4 IB |
19 | if key is None: |
20 | continue | |
21 | ||
22 | for action in config['keys'][mapped_key]: | |
23 | action_name = list(action)[0] | |
24 | action_args = {} | |
25 | if action[action_name] is None: | |
26 | action[action_name] = [] | |
27 | ||
e7f8dab4 IB |
28 | if 'include' in action[action_name]: |
29 | included = action[action_name]['include'] | |
30 | del(action[action_name]['include']) | |
31 | ||
32 | if isinstance(included, str): | |
33 | action[action_name].update(aliases[included], **action[action_name]) | |
34 | else: | |
35 | for included_ in included: | |
36 | action[action_name].update(aliases[included_], **action[action_name]) | |
37 | ||
8f88a3e4 | 38 | for argument in action[action_name]: |
e7f8dab4 | 39 | if argument == 'file': |
8f88a3e4 IB |
40 | filename = action[action_name]['file'] |
41 | if filename not in seen_files: | |
e7f8dab4 | 42 | seen_files[filename] = MusicFile(filename, file_lock) |
8f88a3e4 | 43 | |
d8ab67c7 | 44 | action_args['music'] = seen_files[filename] |
8f88a3e4 IB |
45 | |
46 | else: | |
47 | action_args[argument] = action[action_name][argument] | |
48 | ||
49 | key.add_action(action_name, **action_args) | |
b86db9f1 IB |
50 | |
51 | for key_property in config['key_properties']: | |
52 | key = mapping.find_by_unicode(key_property) | |
53 | if key is None: | |
54 | continue | |
55 | ||
56 | if 'description' in config['key_properties'][key_property]: | |
57 | key.set_description(config['key_properties'][key_property]['description']) | |
58 | if 'color' in config['key_properties'][key_property]: | |
59 | key.set_color(config['key_properties'][key_property]['color']) |