diff options
Diffstat (limited to 'helpers/__init__.py')
-rw-r--r-- | helpers/__init__.py | 149 |
1 files changed, 0 insertions, 149 deletions
diff --git a/helpers/__init__.py b/helpers/__init__.py index eb948f2..40a96af 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py | |||
@@ -1,150 +1 @@ | |||
1 | # -*- coding: utf-8 -*- | # -*- 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_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 | |||
82 | def parse_config(mapping): | ||
83 | stream = open("config.yml", "r") | ||
84 | config = yaml.load(stream) | ||
85 | stream.close() | ||
86 | |||
87 | aliases = config['aliases'] | ||
88 | seen_files = {} | ||
89 | |||
90 | file_lock = Lock("file") | ||
91 | |||
92 | channel_id = 0 | ||
93 | |||
94 | for mapped_key in config['keys']: | ||
95 | key = mapping.find_by_unicode(mapped_key) | ||
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 | |||
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 | |||
115 | for argument in action[action_name]: | ||
116 | if argument == 'file': | ||
117 | filename = action[action_name]['file'] | ||
118 | if filename not in seen_files: | ||
119 | if filename in config['music_properties']: | ||
120 | seen_files[filename] = MusicFile( | ||
121 | filename, | ||
122 | file_lock, | ||
123 | channel_id, | ||
124 | **config['music_properties'][filename]) | ||
125 | else: | ||
126 | seen_files[filename] = MusicFile( | ||
127 | filename, | ||
128 | file_lock, | ||
129 | channel_id) | ||
130 | channel_id = channel_id + 1 | ||
131 | |||
132 | action_args['music'] = seen_files[filename] | ||
133 | |||
134 | else: | ||
135 | action_args[argument] = action[action_name][argument] | ||
136 | |||
137 | key.add_action(action_name, **action_args) | ||
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']) | ||
148 | |||
149 | # Return the number of channels reserved | ||
150 | return (channel_id + 1, seen_files) | ||