diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-28 03:30:00 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-28 03:30:00 +0200 |
commit | 2010311b76299bb3f0803a52510ab41d64d8e41a (patch) | |
tree | bc6dd00aa99c38a7dcffcc381e50af6394aa4896 /music_sampler/helpers.py | |
parent | 023d9381fb532d09f1e08df65ee545da64222caa (diff) | |
download | MusicSampler-2010311b76299bb3f0803a52510ab41d64d8e41a.tar.gz MusicSampler-2010311b76299bb3f0803a52510ab41d64d8e41a.tar.zst MusicSampler-2010311b76299bb3f0803a52510ab41d64d8e41a.zip |
Improve error message and handling
Diffstat (limited to 'music_sampler/helpers.py')
-rw-r--r-- | music_sampler/helpers.py | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/music_sampler/helpers.py b/music_sampler/helpers.py index 68c1328..6acaba4 100644 --- a/music_sampler/helpers.py +++ b/music_sampler/helpers.py | |||
@@ -29,11 +29,11 @@ def register_fonts(): | |||
29 | symbola = find_font("Symbola") | 29 | symbola = find_font("Symbola") |
30 | 30 | ||
31 | if ubuntu_regular is None: | 31 | if ubuntu_regular is None: |
32 | error_print("Font Ubuntu regular could not be found, please install it.") | 32 | error_print("Font Ubuntu regular could not be found, " |
33 | sys.exit() | 33 | "please install it.", exit=True) |
34 | if symbola is None: | 34 | if symbola is None: |
35 | error_print("Font Symbola could not be found, please install it.") | 35 | error_print("Font Symbola could not be found, please install it.", |
36 | sys.exit() | 36 | exit=True) |
37 | if ubuntu_bold is None: | 37 | if ubuntu_bold is None: |
38 | warn_print("Font Ubuntu Bold could not be found.") | 38 | warn_print("Font Ubuntu Bold could not be found.") |
39 | 39 | ||
@@ -180,12 +180,29 @@ def gain(volume, old_volume=None): | |||
180 | 20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)), | 180 | 20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)), |
181 | max(volume, 0)] | 181 | max(volume, 0)] |
182 | 182 | ||
183 | def debug_print(message, with_trace=False): | 183 | def debug_print(message, with_trace=None): |
184 | if with_trace is None: | ||
185 | with_trace = (Logger.getEffectiveLevel() < logging.WARN) | ||
186 | with_trace &= (sys.exc_info()[0] is not None) | ||
187 | |||
184 | Logger.debug('MusicSampler: ' + message, exc_info=with_trace) | 188 | Logger.debug('MusicSampler: ' + message, exc_info=with_trace) |
185 | 189 | ||
186 | def error_print(message, with_trace=False): | 190 | def error_print(message, exit=False, with_trace=None): |
187 | Logger.error('MusicSampler: ' + message, exc_info=with_trace) | 191 | if with_trace is None: |
192 | with_trace = (Logger.getEffectiveLevel() < logging.WARN) | ||
193 | with_trace &= (sys.exc_info()[0] is not None) | ||
194 | |||
195 | # FIXME: handle it correctly when in a thread | ||
196 | if exit: | ||
197 | Logger.critical('MusicSampler: ' + message, exc_info=with_trace) | ||
198 | sys.exit(1) | ||
199 | else: | ||
200 | Logger.error('MusicSampler: ' + message, exc_info=with_trace) | ||
201 | |||
202 | def warn_print(message, with_trace=None): | ||
203 | if with_trace is None: | ||
204 | with_trace = (Logger.getEffectiveLevel() < logging.WARN) | ||
205 | with_trace &= (sys.exc_info()[0] is not None) | ||
188 | 206 | ||
189 | def warn_print(message, with_trace=False): | ||
190 | Logger.warn('MusicSampler: ' + message, exc_info=with_trace) | 207 | Logger.warn('MusicSampler: ' + message, exc_info=with_trace) |
191 | 208 | ||