# HG changeset patch # User Amine Sehili # Date 1552331792 -3600 # Node ID 592ec1821452493ddc54274d7b6d1d57579d3adf # Parent ec7b0b3c981823f5674c634efe2a1e36d8a846d3 Reformat cmdline_util with black diff -r ec7b0b3c9818 -r 592ec1821452 auditok/cmdline_util.py --- a/auditok/cmdline_util.py Mon Mar 11 20:14:46 2019 +0100 +++ b/auditok/cmdline_util.py Mon Mar 11 20:16:32 2019 +0100 @@ -4,27 +4,31 @@ LOGGER_NAME = "AUDITOK_LOGGER" + class TimeFormatError(Exception): pass + def make_kwargs(args_namespace): - kwargs = {'min_dur' : args_namespace.min_duration, - 'max_dur' : args_namespace.max_duration, - 'max_silence' : args_namespace.max_silence, - 'drop_trailing_silence': args_namespace.drop_trailing_silence, - 'strict_min_length' : args_namespace.strict_min_length, - 'energy_threshold' : args_namespace.energy_threshold, - 'max_read_time' : args_namespace.max_time, - 'analysis_window' : args_namespace.analysis_window, - 'sampling_rate' : args_namespace.sampling_rate, - 'sample_with' : args_namespace.sample_width, - 'channels' : args_namespace.channels, - 'use_channel' : args_namespace.use_channel, - 'input_type' : args_namespace.input_type, - 'output_type' : args_namespace.output_type, - 'large_file' : args_namespace.large_file, - 'frames_per_buffer' : args_namespace.frame_per_buffer, - 'input_device_index' : args_namespace.input_device_index} + kwargs = { + "min_dur": args_namespace.min_duration, + "max_dur": args_namespace.max_duration, + "max_silence": args_namespace.max_silence, + "drop_trailing_silence": args_namespace.drop_trailing_silence, + "strict_min_length": args_namespace.strict_min_length, + "energy_threshold": args_namespace.energy_threshold, + "max_read_time": args_namespace.max_time, + "analysis_window": args_namespace.analysis_window, + "sampling_rate": args_namespace.sampling_rate, + "sample_with": args_namespace.sample_width, + "channels": args_namespace.channels, + "use_channel": args_namespace.use_channel, + "input_type": args_namespace.input_type, + "output_type": args_namespace.output_type, + "large_file": args_namespace.large_file, + "frames_per_buffer": args_namespace.frame_per_buffer, + "input_device_index": args_namespace.input_device_index, + } return kwargs @@ -35,12 +39,15 @@ # check directives are correct if fmt == "%S": + def fromatter(seconds): return "{:.3f}".format(seconds) elif fmt == "%I": + def fromatter(seconds): return "{0}".format(int(seconds * 1000)) + else: fmt = fmt.replace("%h", "{hrs:d}") fmt = fmt.replace("%m", "{mins:d}") @@ -48,7 +55,9 @@ fmt = fmt.replace("%i", "{millis:03d}") try: i = fmt.index("%") - raise TimeFormatError("Unknow time format directive '{0}'".format(fmt[i : i + 2])) + raise TimeFormatError( + "Unknow time format directive '{0}'".format(fmt[i : i + 2]) + ) except ValueError: pass @@ -58,6 +67,7 @@ mins, millis = divmod(millis, 60000) secs, millis = divmod(millis, 1000) return fmt.format(hrs=hrs, mins=mins, secs=secs, millis=millis) + return fromatter @@ -66,7 +76,7 @@ return None logger = logging.getLogger(LOGGER_NAME) if debug_stdout: - handler = logging.StreamHandler(sys.stdout) + handler = logging.StreamHandler(sys.stdout) handler.setLevel(logging.DEBUG) logger.addHandler(handler) @@ -76,4 +86,4 @@ handler.setFormatter(fmt) handler.setLevel(logging.DEBUG) logger.addHandler(handler) - return logger \ No newline at end of file + return logger