mirror of
https://github.com/k4yt3x/video2x.git
synced 2025-01-30 15:48:13 +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
|
Name: Package Main
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: July 3, 2021
|
Date Created: July 3, 2021
|
||||||
Last Modified: February 11, 2022
|
Last Modified: February 26, 2022
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from .video2x import main
|
from .video2x import main
|
||||||
|
|
||||||
|
# built-in imports
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
sys.exit(main())
|
||||||
|
@ -27,7 +27,7 @@ __ __ _ _ ___ __ __
|
|||||||
Name: Video2X
|
Name: Video2X
|
||||||
Creator: K4YT3X
|
Creator: K4YT3X
|
||||||
Date Created: February 24, 2018
|
Date Created: February 24, 2018
|
||||||
Last Modified: February 16, 2022
|
Last Modified: February 27, 2022
|
||||||
|
|
||||||
Editor: BrianPetkovsek
|
Editor: BrianPetkovsek
|
||||||
Last Modified: June 17, 2019
|
Last Modified: June 17, 2019
|
||||||
@ -491,21 +491,30 @@ def parse_arguments() -> argparse.Namespace:
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> int:
|
||||||
"""
|
"""
|
||||||
command line direct invocation
|
command line entrypoint for direct CLI invocation
|
||||||
program entry point
|
|
||||||
|
:rtype int: 0 if completed successfully, else other int
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# display version and lawful informaition
|
# display version and lawful informaition
|
||||||
if "--version" in sys.argv:
|
if "--version" in sys.argv:
|
||||||
print(LEGAL_INFO)
|
print(LEGAL_INFO)
|
||||||
sys.exit(0)
|
return 0
|
||||||
|
|
||||||
# parse command line arguments
|
# parse command line arguments
|
||||||
args = parse_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
|
# set logger level
|
||||||
if os.environ.get("LOGURU_LEVEL") is None:
|
if os.environ.get("LOGURU_LEVEL") is None:
|
||||||
os.environ["LOGURU_LEVEL"] = args.loglevel.upper()
|
os.environ["LOGURU_LEVEL"] = args.loglevel.upper()
|
||||||
@ -546,10 +555,12 @@ def main() -> None:
|
|||||||
args.algorithm,
|
args.algorithm,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
# don't print the traceback for manual terminations
|
# don't print the traceback for manual terminations
|
||||||
except KeyboardInterrupt as e:
|
except KeyboardInterrupt as e:
|
||||||
raise SystemExit(e)
|
return 2
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
raise SystemExit(e)
|
return 1
|
||||||
|
Loading…
Reference in New Issue
Block a user