Improve temporaries management.

This commit is contained in:
Frédéric Tronel
2026-08-31 12:00:12 +02:00
parent b0bc0a338e
commit 153873637e
2 changed files with 15 additions and 6 deletions
+4 -4
View File
@@ -60,7 +60,7 @@ def main() -> int:
if args.coarse and args.threshold is not None:
logger.error('--coarse and threshold arguments are exclusive.')
exit(-1)
return 2
if (not args.coarse) and args.threshold is None:
args.threshold = 0
@@ -80,7 +80,7 @@ def main() -> int:
ts1, ts2 = parse_time_interval(interval)
if ts1 is None or ts2 is None:
logger.error("Illegal time interval: %s", interval)
exit(-1)
return 2
parts.append((ts1,ts2))
# Sort intervals
@@ -92,7 +92,7 @@ def main() -> int:
ts1, ts2 = part
if prevts > ts1:
logger.error('Intervals are overlapping')
exit(-1)
return 2
prevts = ts2
config = ProcessingOptions(
@@ -110,8 +110,8 @@ def main() -> int:
all_optional_tools = all_optional_tools)
logger.debug("Configuration: %s", config)
temporaries = TemporaryFiles(config.keep_temporaries)
try:
temporaries = TemporaryFiles(config.keep_temporaries)
process_recording(config, temporaries)
except TSCutError as exc:
logger.error("%s", exc)
+11 -2
View File
@@ -25,5 +25,14 @@ class TemporaryFiles:
for f in self._files:
path = os.path.realpath(f.name)
logger.info("Removing: %s", path)
f.close()
os.unlink(path)
try:
f.close()
os.unlink(path)
except OSError:
logger.exception("Unable to remove temporary file: %s", path)
def __enter__(self) -> Self:
return self
def __exit__(self, ...) -> None:
self.cleanup()