diff --git a/video2x/__main__.py b/video2x/__main__.py index c9e8d8d..d93968f 100755 --- a/video2x/__main__.py +++ b/video2x/__main__.py @@ -19,12 +19,15 @@ along with this program. If not, see . Name: Package Main Author: K4YT3X Date Created: July 3, 2021 -Last Modified: February 11, 2022 +Last Modified: February 26, 2022 """ # local imports from .video2x import main +# built-in imports +import sys + if __name__ == "__main__": - main() + sys.exit(main()) diff --git a/video2x/video2x.py b/video2x/video2x.py index 7cea11c..349688b 100755 --- a/video2x/video2x.py +++ b/video2x/video2x.py @@ -27,7 +27,7 @@ __ __ _ _ ___ __ __ Name: Video2X Creator: K4YT3X Date Created: February 24, 2018 -Last Modified: February 16, 2022 +Last Modified: February 27, 2022 Editor: BrianPetkovsek Last Modified: June 17, 2019 @@ -491,21 +491,30 @@ def parse_arguments() -> argparse.Namespace: return parser.parse_args() -def main() -> None: +def main() -> int: """ - command line direct invocation - program entry point + command line entrypoint for direct CLI invocation + + :rtype int: 0 if completed successfully, else other int """ try: # display version and lawful informaition if "--version" in sys.argv: print(LEGAL_INFO) - sys.exit(0) + return 0 # parse command line arguments args = parse_arguments() + # check input/output file paths + if not args.input.exists(): + logger.critical(f"Cannot find input file: {args.input}") + return 1 + elif not args.input.is_file(): + logger.critical(f"Input path is not a file") + return 1 + # set logger level if os.environ.get("LOGURU_LEVEL") is None: os.environ["LOGURU_LEVEL"] = args.loglevel.upper() @@ -546,10 +555,12 @@ def main() -> None: args.algorithm, ) + return 0 + # don't print the traceback for manual terminations except KeyboardInterrupt as e: - raise SystemExit(e) + return 2 except Exception as e: logger.exception(e) - raise SystemExit(e) + return 1