Skip to content

Commit

Permalink
improved main function return handling
Browse files Browse the repository at this point in the history
  • Loading branch information
k4yt3x committed Feb 27, 2022
1 parent 8cb64d3 commit c0fe81b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
7 changes: 5 additions & 2 deletions video2x/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
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())
25 changes: 18 additions & 7 deletions video2x/video2x.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

0 comments on commit c0fe81b

Please sign in to comment.