]>
Commit | Line | Data |
---|---|---|
1df30f07 | 1 | # -*- coding: utf-8 -*- |
be27763f IB |
2 | from .music_file import * |
3 | from .mapping import * | |
ba9ea93a | 4 | from .lock import * |
956ce6fd | 5 | from .font import * |
ba9ea93a | 6 | import yaml |
8f88a3e4 | 7 | |
8612c5f8 IB |
8 | def parse_config2(): |
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 | key_properties = {} | |
21 | ||
22 | for key in config['key_properties']: | |
23 | if key not in key_properties: | |
24 | key_properties[key] = { | |
25 | "actions": [], | |
26 | "properties": config['key_properties'][key], | |
27 | "files": [] | |
28 | } | |
29 | ||
30 | for mapped_key in config['keys']: | |
31 | if mapped_key not in key_properties: | |
32 | key_properties[mapped_key] = { | |
33 | "actions": [], | |
34 | "properties": {}, | |
35 | "files": [] | |
36 | } | |
37 | for action in config['keys'][mapped_key]: | |
38 | action_name = list(action)[0] | |
39 | action_args = {} | |
40 | if action[action_name] is None: | |
41 | action[action_name] = [] | |
42 | ||
43 | if 'include' in action[action_name]: | |
44 | included = action[action_name]['include'] | |
45 | del(action[action_name]['include']) | |
46 | ||
47 | if isinstance(included, str): | |
48 | action[action_name].update(aliases[included], **action[action_name]) | |
49 | else: | |
50 | for included_ in included: | |
51 | action[action_name].update(aliases[included_], **action[action_name]) | |
52 | ||
53 | for argument in action[action_name]: | |
54 | if argument == 'file': | |
55 | filename = action[action_name]['file'] | |
56 | if filename not in seen_files: | |
57 | if filename in config['music_properties']: | |
58 | seen_files[filename] = MusicFile( | |
59 | filename, | |
60 | file_lock, | |
61 | channel_id, | |
62 | **config['music_properties'][filename]) | |
63 | else: | |
64 | seen_files[filename] = MusicFile( | |
65 | filename, | |
66 | file_lock, | |
67 | channel_id) | |
68 | channel_id = channel_id + 1 | |
69 | ||
70 | if filename not in key_properties[mapped_key]['files']: | |
71 | key_properties[mapped_key]['files'].append(seen_files[filename]) | |
72 | ||
73 | action_args['music'] = seen_files[filename] | |
74 | ||
75 | else: | |
76 | action_args[argument] = action[action_name][argument] | |
77 | ||
78 | key_properties[mapped_key]['actions'].append([action_name, action_args]) | |
79 | ||
80 | return (key_properties, channel_id + 1, seen_files) | |
81 | ||
e7f8dab4 | 82 | def parse_config(mapping): |
8f88a3e4 IB |
83 | stream = open("config.yml", "r") |
84 | config = yaml.load(stream) | |
85 | stream.close() | |
86 | ||
87 | aliases = config['aliases'] | |
88 | seen_files = {} | |
89 | ||
ba9ea93a | 90 | file_lock = Lock("file") |
e7f8dab4 | 91 | |
d479af33 IB |
92 | channel_id = 0 |
93 | ||
8f88a3e4 | 94 | for mapped_key in config['keys']: |
e7f8dab4 | 95 | key = mapping.find_by_unicode(mapped_key) |
8f88a3e4 IB |
96 | if key is None: |
97 | continue | |
98 | ||
99 | for action in config['keys'][mapped_key]: | |
100 | action_name = list(action)[0] | |
101 | action_args = {} | |
102 | if action[action_name] is None: | |
103 | action[action_name] = [] | |
104 | ||
e7f8dab4 IB |
105 | if 'include' in action[action_name]: |
106 | included = action[action_name]['include'] | |
107 | del(action[action_name]['include']) | |
108 | ||
109 | if isinstance(included, str): | |
110 | action[action_name].update(aliases[included], **action[action_name]) | |
111 | else: | |
112 | for included_ in included: | |
113 | action[action_name].update(aliases[included_], **action[action_name]) | |
114 | ||
8f88a3e4 | 115 | for argument in action[action_name]: |
e7f8dab4 | 116 | if argument == 'file': |
8f88a3e4 IB |
117 | filename = action[action_name]['file'] |
118 | if filename not in seen_files: | |
87f211fb IB |
119 | if filename in config['music_properties']: |
120 | seen_files[filename] = MusicFile( | |
121 | filename, | |
122 | file_lock, | |
8612c5f8 | 123 | channel_id, |
87f211fb | 124 | **config['music_properties'][filename]) |
9de92b6d | 125 | else: |
87f211fb IB |
126 | seen_files[filename] = MusicFile( |
127 | filename, | |
128 | file_lock, | |
129 | channel_id) | |
d479af33 | 130 | channel_id = channel_id + 1 |
8f88a3e4 | 131 | |
d8ab67c7 | 132 | action_args['music'] = seen_files[filename] |
8f88a3e4 IB |
133 | |
134 | else: | |
135 | action_args[argument] = action[action_name][argument] | |
136 | ||
137 | key.add_action(action_name, **action_args) | |
b86db9f1 IB |
138 | |
139 | for key_property in config['key_properties']: | |
140 | key = mapping.find_by_unicode(key_property) | |
141 | if key is None: | |
142 | continue | |
143 | ||
144 | if 'description' in config['key_properties'][key_property]: | |
145 | key.set_description(config['key_properties'][key_property]['description']) | |
146 | if 'color' in config['key_properties'][key_property]: | |
147 | key.set_color(config['key_properties'][key_property]['color']) | |
d479af33 IB |
148 | |
149 | # Return the number of channels reserved | |
9de92b6d | 150 | return (channel_id + 1, seen_files) |