Switch from exit() to sys.exit()

Pyinstaller doesn't recognize exit().
This commit is contained in:
Joscha 2021-05-25 17:33:05 +02:00
parent 6644126b5d
commit f85b75df8c

View File

@ -1,6 +1,7 @@
import argparse import argparse
import asyncio import asyncio
import configparser import configparser
import sys
from pathlib import Path from pathlib import Path
from .cli import PARSER, load_default_section from .cli import PARSER, load_default_section
@ -33,7 +34,7 @@ def load_config(args: argparse.Namespace) -> Config:
except ConfigLoadError as e: except ConfigLoadError as e:
log.error(str(e)) log.error(str(e))
log.error_contd(e.reason) log.error_contd(e.reason)
exit(1) sys.exit(1)
def configure_logging_from_args(args: argparse.Namespace) -> None: def configure_logging_from_args(args: argparse.Namespace) -> None:
@ -68,7 +69,7 @@ def configure_logging_from_config(args: argparse.Namespace, config: Config) -> N
log.output_report = config.default_section.report() log.output_report = config.default_section.report()
except ConfigOptionError as e: except ConfigOptionError as e:
log.error(str(e)) log.error(str(e))
exit(1) sys.exit(1)
def dump_config(args: argparse.Namespace, config: Config) -> None: def dump_config(args: argparse.Namespace, config: Config) -> None:
@ -76,7 +77,7 @@ def dump_config(args: argparse.Namespace, config: Config) -> None:
if args.dump_config and args.dump_config_to is not None: if args.dump_config and args.dump_config_to is not None:
log.error("--dump-config and --dump-config-to can't be specified at the same time") log.error("--dump-config and --dump-config-to can't be specified at the same time")
exit(1) sys.exit(1)
try: try:
if args.dump_config: if args.dump_config:
@ -88,7 +89,7 @@ def dump_config(args: argparse.Namespace, config: Config) -> None:
except ConfigDumpError as e: except ConfigDumpError as e:
log.error(str(e)) log.error(str(e))
log.error_contd(e.reason) log.error_contd(e.reason)
exit(1) sys.exit(1)
def main() -> None: def main() -> None:
@ -107,25 +108,25 @@ def main() -> None:
if args.dump_config or args.dump_config_to is not None: if args.dump_config or args.dump_config_to is not None:
dump_config(args, config) dump_config(args, config)
exit() sys.exit()
try: try:
pferd = Pferd(config, args.crawler) pferd = Pferd(config, args.crawler)
except PferdLoadError as e: except PferdLoadError as e:
log.unlock() log.unlock()
log.error(str(e)) log.error(str(e))
exit(1) sys.exit(1)
try: try:
asyncio.run(pferd.run()) asyncio.run(pferd.run())
except ConfigOptionError as e: except ConfigOptionError as e:
log.unlock() log.unlock()
log.error(str(e)) log.error(str(e))
exit(1) sys.exit(1)
except RuleParseError as e: except RuleParseError as e:
log.unlock() log.unlock()
e.pretty_print() e.pretty_print()
exit(1) sys.exit(1)
except KeyboardInterrupt: except KeyboardInterrupt:
log.unlock() log.unlock()
log.explain_topic("Interrupted, exiting immediately") log.explain_topic("Interrupted, exiting immediately")
@ -135,9 +136,9 @@ def main() -> None:
# TODO Clean up tmp files # TODO Clean up tmp files
# And when those files *do* actually get cleaned up properly, # And when those files *do* actually get cleaned up properly,
# reconsider if this should really exit with 1 # reconsider if this should really exit with 1
exit(1) sys.exit(1)
except Exception: except Exception:
log.unlock() log.unlock()
log.unexpected_exception() log.unexpected_exception()
pferd.print_report() pferd.print_report()
exit(1) sys.exit(1)