X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git;a=blobdiff_plain;f=music_sampler%2Fhelpers.py;h=6acaba4f7e9300523ef6c9a20c389b2eb9d79484;hp=68c1328998379a9d5f2c1deb61f5174d0359741a;hb=2010311b76299bb3f0803a52510ab41d64d8e41a;hpb=023d9381fb532d09f1e08df65ee545da64222caa 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(): symbola = find_font("Symbola") if ubuntu_regular is None: - error_print("Font Ubuntu regular could not be found, please install it.") - sys.exit() + error_print("Font Ubuntu regular could not be found, " + "please install it.", exit=True) if symbola is None: - error_print("Font Symbola could not be found, please install it.") - sys.exit() + error_print("Font Symbola could not be found, please install it.", + exit=True) if ubuntu_bold is None: warn_print("Font Ubuntu Bold could not be found.") @@ -180,12 +180,29 @@ def gain(volume, old_volume=None): 20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)), max(volume, 0)] -def debug_print(message, with_trace=False): +def debug_print(message, with_trace=None): + if with_trace is None: + with_trace = (Logger.getEffectiveLevel() < logging.WARN) + with_trace &= (sys.exc_info()[0] is not None) + Logger.debug('MusicSampler: ' + message, exc_info=with_trace) -def error_print(message, with_trace=False): - Logger.error('MusicSampler: ' + message, exc_info=with_trace) +def error_print(message, exit=False, with_trace=None): + if with_trace is None: + with_trace = (Logger.getEffectiveLevel() < logging.WARN) + with_trace &= (sys.exc_info()[0] is not None) + + # FIXME: handle it correctly when in a thread + if exit: + Logger.critical('MusicSampler: ' + message, exc_info=with_trace) + sys.exit(1) + else: + Logger.error('MusicSampler: ' + message, exc_info=with_trace) + +def warn_print(message, with_trace=None): + if with_trace is None: + with_trace = (Logger.getEffectiveLevel() < logging.WARN) + with_trace &= (sys.exc_info()[0] is not None) -def warn_print(message, with_trace=False): Logger.warn('MusicSampler: ' + message, exc_info=with_trace)