Improve temporaries management.
This commit is contained in:
+4
-4
@@ -60,7 +60,7 @@ def main() -> int:
|
|||||||
|
|
||||||
if args.coarse and args.threshold is not None:
|
if args.coarse and args.threshold is not None:
|
||||||
logger.error('--coarse and threshold arguments are exclusive.')
|
logger.error('--coarse and threshold arguments are exclusive.')
|
||||||
exit(-1)
|
return 2
|
||||||
|
|
||||||
if (not args.coarse) and args.threshold is None:
|
if (not args.coarse) and args.threshold is None:
|
||||||
args.threshold = 0
|
args.threshold = 0
|
||||||
@@ -80,7 +80,7 @@ def main() -> int:
|
|||||||
ts1, ts2 = parse_time_interval(interval)
|
ts1, ts2 = parse_time_interval(interval)
|
||||||
if ts1 is None or ts2 is None:
|
if ts1 is None or ts2 is None:
|
||||||
logger.error("Illegal time interval: %s", interval)
|
logger.error("Illegal time interval: %s", interval)
|
||||||
exit(-1)
|
return 2
|
||||||
parts.append((ts1,ts2))
|
parts.append((ts1,ts2))
|
||||||
|
|
||||||
# Sort intervals
|
# Sort intervals
|
||||||
@@ -92,7 +92,7 @@ def main() -> int:
|
|||||||
ts1, ts2 = part
|
ts1, ts2 = part
|
||||||
if prevts > ts1:
|
if prevts > ts1:
|
||||||
logger.error('Intervals are overlapping')
|
logger.error('Intervals are overlapping')
|
||||||
exit(-1)
|
return 2
|
||||||
prevts = ts2
|
prevts = ts2
|
||||||
|
|
||||||
config = ProcessingOptions(
|
config = ProcessingOptions(
|
||||||
@@ -110,8 +110,8 @@ def main() -> int:
|
|||||||
all_optional_tools = all_optional_tools)
|
all_optional_tools = all_optional_tools)
|
||||||
|
|
||||||
logger.debug("Configuration: %s", config)
|
logger.debug("Configuration: %s", config)
|
||||||
|
temporaries = TemporaryFiles(config.keep_temporaries)
|
||||||
try:
|
try:
|
||||||
temporaries = TemporaryFiles(config.keep_temporaries)
|
|
||||||
process_recording(config, temporaries)
|
process_recording(config, temporaries)
|
||||||
except TSCutError as exc:
|
except TSCutError as exc:
|
||||||
logger.error("%s", exc)
|
logger.error("%s", exc)
|
||||||
|
|||||||
@@ -25,5 +25,14 @@ class TemporaryFiles:
|
|||||||
for f in self._files:
|
for f in self._files:
|
||||||
path = os.path.realpath(f.name)
|
path = os.path.realpath(f.name)
|
||||||
logger.info("Removing: %s", path)
|
logger.info("Removing: %s", path)
|
||||||
f.close()
|
try:
|
||||||
os.unlink(path)
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user