Skip to content

Commit

Permalink
Format log messages lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
naglis committed Dec 22, 2024
1 parent 0d0a5c1 commit 3fb41e4
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 31 deletions.
6 changes: 3 additions & 3 deletions aeneas/audiofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def read_properties(self):
# check the file can be read
if not gf.file_can_be_read(self.file_path):
self.log_exc(
"File '%s' cannot be read" % (self.file_path), None, True, OSError
["File '%s' cannot be read", self.file_path], None, True, OSError
)

# get the file size
Expand Down Expand Up @@ -416,7 +416,7 @@ def read_samples_from_file(self):
# check the file can be read
if not gf.file_can_be_read(self.file_path):
self.log_exc(
"File '%s' cannot be read" % (self.file_path), None, True, OSError
["File '%s' cannot be read", self.file_path], None, True, OSError
)

# determine if we need to convert the audio file
Expand Down Expand Up @@ -681,7 +681,7 @@ def write(self, file_path: str):
scipywavwrite(file_path, self.audio_sample_rate, data)
except Exception as exc:
self.log_exc(
"Error writing audio file to '%s'" % (file_path), exc, True, OSError
["Error writing audio file to '%s'", file_path], exc, True, OSError
)
self.log(["Writing audio file '%s'... done", file_path])

Expand Down
10 changes: 5 additions & 5 deletions aeneas/executejob.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def load_job_from_container(self, container_path, config_string=None):

if self.job is None:
self.log_exc(
"The container '%s' does not contain a valid Job" % (container_path),
["The container '%s' does not contain a valid Job", container_path],
None,
True,
ExecuteJobInputError,
Expand Down Expand Up @@ -244,7 +244,7 @@ def execute(self):
self.log(["Executing task '%s'... done", custom_id])
except Exception as exc:
self.log_exc(
"Error while executing task '%s'" % (custom_id),
["Error while executing task '%s'", custom_id],
exc,
True,
ExecuteJobExecutionError,
Expand Down Expand Up @@ -289,14 +289,14 @@ def write_output_container(self, output_directory_path):
# check if the task has sync map and sync map file path
if task.sync_map_file_path is None:
self.log_exc(
"Task '%s' has sync_map_file_path not set" % (custom_id),
["Task '%s' has sync_map_file_path not set", custom_id],
None,
True,
ExecuteJobOutputError,
)
if task.sync_map is None:
self.log_exc(
"Task '%s' has sync_map not set" % (custom_id),
["Task '%s' has sync_map not set", custom_id],
None,
True,
ExecuteJobOutputError,
Expand All @@ -309,7 +309,7 @@ def write_output_container(self, output_directory_path):
self.log(["Outputting sync map for task '%s'... done", custom_id])
except Exception:
self.log_exc(
"Error while outputting sync map for task '%s'" % (custom_id),
["Error while outputting sync map for task '%s'", custom_id],
None,
True,
ExecuteJobOutputError,
Expand Down
10 changes: 5 additions & 5 deletions aeneas/executetask.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,26 @@ def _step_begin(self, label, log=True):
if log:
self.step_label = label
self.step_begin_time = self.log(
"STEP %d BEGIN (%s)" % (self.step_index, label)
["STEP %d BEGIN (%s)", self.step_index, label]
)

def _step_end(self, log=True):
"""Log end of a step"""
if log:
step_end_time = self.log(
"STEP %d END (%s)" % (self.step_index, self.step_label)
["STEP %d END (%s)", self.step_index, self.step_label]
)
diff = step_end_time - self.step_begin_time
diff = float(diff.seconds + diff.microseconds / 1000000.0)
self.step_total += diff
self.log(
"STEP %d DURATION %.3f (%s)" % (self.step_index, diff, self.step_label)
["STEP %d DURATION %.3f (%s)", self.step_index, diff, self.step_label]
)
self.step_index += 1

def _step_failure(self, exc):
"""Log failure of a step"""
self.log_crit("STEP %d (%s) FAILURE" % (self.step_index, self.step_label))
self.log_crit(["STEP %d (%s) FAILURE", self.step_index, self.step_label])
self.step_index += 1
self.log_exc(
"Unexpected error while executing task",
Expand All @@ -135,7 +135,7 @@ def _step_failure(self, exc):

def _step_total(self):
"""Log total"""
self.log("STEP T DURATION %.3f" % (self.step_total))
self.log(["STEP T DURATION %.3f", self.step_total])

def execute(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion aeneas/ffmpegwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def convert(
# test if we can read the input file
if not gf.file_can_be_read(input_file_path):
self.log_exc(
"Input file '%s' cannot be read" % (input_file_path),
["Input file '%s' cannot be read", input_file_path],
None,
True,
OSError,
Expand Down
2 changes: 1 addition & 1 deletion aeneas/ffprobewrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def read_properties(self, audio_file_path):
self.log_exc("The audio file path is None", None, True, TypeError)
if not gf.file_can_be_read(audio_file_path):
self.log_exc(
"Input file '%s' cannot be read" % (audio_file_path),
["Input file '%s' cannot be read", audio_file_path],
None,
True,
OSError,
Expand Down
2 changes: 1 addition & 1 deletion aeneas/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def draw_png(self, output_file_path, h_zoom=5, v_zoom=30):
# check that output_file_path can be written
if not gf.file_can_be_written(output_file_path):
self.log_exc(
"Cannot write to output file '%s'" % (output_file_path),
["Cannot write to output file '%s'", output_file_path],
None,
True,
OSError,
Expand Down
4 changes: 2 additions & 2 deletions aeneas/sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ def _sanitize(
value = TimeValue(value)
except (TypeError, ValueError, decimal.InvalidOperation) as exc:
self.log_exc(
"The value of %s is not a number" % (name), exc, True, TypeError
["The value of %s is not a number", name], exc, True, TypeError
)
if value < 0:
self.log_exc(
"The value of %s is negative" % (name), None, True, ValueError
["The value of %s is negative", name], None, True, ValueError
)
return value

Expand Down
15 changes: 8 additions & 7 deletions aeneas/syncmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def output_html_for_tuning(
"""
if not gf.file_can_be_written(output_file_path):
self.log_exc(
"Cannot output HTML file '%s'. Wrong permissions?" % (output_file_path),
["Cannot output HTML file '%s'. Wrong permissions?", output_file_path],
None,
True,
OSError,
Expand Down Expand Up @@ -386,15 +386,14 @@ def read(
self.log_exc("Sync map format is None", None, True, ValueError)
if sync_map_format not in SyncMapFormat.CODE_TO_CLASS:
self.log_exc(
"Sync map format '%s' is not allowed" % (sync_map_format),
["Sync map format '%s' is not allowed", sync_map_format],
None,
True,
ValueError,
)
if not gf.file_can_be_read(input_file_path):
self.log_exc(
"Cannot read sync map file '%s'. Wrong permissions?"
% (input_file_path),
["Cannot read sync map file '%s'. Wrong permissions?", input_file_path],
None,
True,
OSError,
Expand Down Expand Up @@ -512,15 +511,17 @@ def set_head_tail_format(syncmap, head_tail_format=None):
self.log_exc("Sync map format is None", None, True, ValueError)
if sync_map_format not in SyncMapFormat.CODE_TO_CLASS:
self.log_exc(
"Sync map format '%s' is not allowed" % (sync_map_format),
["Sync map format '%s' is not allowed", sync_map_format],
None,
True,
ValueError,
)
if not gf.file_can_be_written(output_file_path):
self.log_exc(
"Cannot write sync map file '%s'. Wrong permissions?"
% (output_file_path),
[
"Cannot write sync map file '%s'. Wrong permissions?",
output_file_path,
],
None,
True,
OSError,
Expand Down
2 changes: 1 addition & 1 deletion aeneas/syncmap/smfgsubtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def parse_time_string(string):
split = string.split(self.time_values_separator)
if len(split) < 2:
self.log_exc(
"The following timing string is malformed: '%s'" % (string),
["The following timing string is malformed: '%s'", string],
None,
True,
ValueError,
Expand Down
4 changes: 2 additions & 2 deletions aeneas/synthesizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def synthesize(
)
if not gf.file_can_be_written(audio_file_path):
self.log_exc(
"Audio file path '%s' cannot be written" % (audio_file_path),
["Audio file path '%s' cannot be written", audio_file_path],
None,
True,
OSError,
Expand All @@ -240,7 +240,7 @@ def synthesize(
# check that the output file has been written
if not os.path.isfile(audio_file_path):
self.log_exc(
"Audio file path '%s' cannot be read" % (audio_file_path),
["Audio file path '%s' cannot be read", audio_file_path],
None,
True,
OSError,
Expand Down
2 changes: 1 addition & 1 deletion aeneas/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def level_at_index(self, index):
levels = self.levels
if (index < 0) or (index >= len(levels)):
self.log_exc(
"The given level index '%d' is not valid" % (index),
["The given level index '%d' is not valid", index],
None,
True,
ValueError,
Expand Down
4 changes: 2 additions & 2 deletions aeneas/ttswrappers/basettswrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def synthesize_multiple(
# check that output_file_path can be written
if not gf.file_can_be_written(output_file_path):
self.log_exc(
"Cannot write to output file '%s'" % (output_file_path),
["Cannot write to output file '%s'", output_file_path],
None,
True,
OSError,
Expand Down Expand Up @@ -709,7 +709,7 @@ def _synthesize_single_subprocess_helper(
# check the file can be read
if not gf.file_can_be_read(output_file_path):
self.log_exc(
"Output file '%s' cannot be read" % (output_file_path),
["Output file '%s' cannot be read", output_file_path],
None,
True,
None,
Expand Down

0 comments on commit 3fb41e4

Please sign in to comment.