mirror of
https://github.com/k4yt3x/video2x.git
synced 2025-01-30 06:58:11 +00:00
improved main function return handling
This commit is contained in:
parent
8cb64d3b70
commit
c0fe81bd2e
@ -19,12 +19,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
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())
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user