diff --git a/src/tscut/cli.py b/src/tscut/cli.py index cf19e77..eda0600 100644 --- a/src/tscut/cli.py +++ b/src/tscut/cli.py @@ -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) diff --git a/src/tscut/temporaries.py b/src/tscut/temporaries.py index 18d13ee..1d83aa9 100644 --- a/src/tscut/temporaries.py +++ b/src/tscut/temporaries.py @@ -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()