move sys.exit() codes to an enum in utils.consts
This commit is contained in:
parent
3028759c86
commit
9d16f7d523
3 changed files with 15 additions and 6 deletions
9
bitbotd
9
bitbotd
|
@ -1,10 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import src.utils.consts
|
||||
|
||||
if sys.version_info < (3, 6):
|
||||
sys.stderr.write("BitBot requires python 3.6.0 or later\n")
|
||||
sys.exit(1)
|
||||
sys.exit(src.utils.consts.Exit.WRONGVERSION)
|
||||
|
||||
import atexit, argparse, faulthandler, os, platform, time, typing
|
||||
from src import Cache, Config, Control, Database, EventManager, Exports, IRCBot
|
||||
|
@ -87,7 +88,7 @@ log.info("Starting BitBot %s (Python v%s, db %s)",
|
|||
lock_file = LockFile.LockFile(lock_location)
|
||||
if not lock_file.available():
|
||||
log.critical("Database is locked. Is BitBot already running?")
|
||||
sys.exit(2)
|
||||
sys.exit(utils.consts.Exit.LOCKED)
|
||||
|
||||
atexit.register(lock_file.unlock)
|
||||
lock_file.lock()
|
||||
|
@ -161,13 +162,13 @@ if len(server_configs):
|
|||
if not bot.connect(server):
|
||||
log.error("Failed to connect to '%s'", [str(server)], exc_info=True)
|
||||
if not args.startup_disconnects:
|
||||
sys.exit(3)
|
||||
sys.exit(utils.consts.Exit.DISCONNECT)
|
||||
|
||||
try:
|
||||
bot.run()
|
||||
except Exception as e:
|
||||
log.critical("Unhandled exception: %s", [str(e)], exc_info=True)
|
||||
sys.exit(4)
|
||||
sys.exit(utils.consts.Exit.FATAL)
|
||||
else:
|
||||
try:
|
||||
if utils.cli.bool_input("no servers found, add one?"):
|
||||
|
|
|
@ -144,7 +144,7 @@ class Bot(object):
|
|||
exc_info = True
|
||||
|
||||
self.log.critical("panic() called: %s", [reason], exc_info=exc_info)
|
||||
sys.exit(20)
|
||||
sys.exit(utils.consts.Exit.PANIC)
|
||||
|
||||
def _module_lists(self):
|
||||
whitelist = self.config.get_list("module-whitelist")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import typing
|
||||
import enum, typing
|
||||
from . import _consts_256_color
|
||||
|
||||
class IRCColor(object):
|
||||
|
@ -68,3 +68,11 @@ ANSI_UNDERLINE_RESET = "\033[24m"
|
|||
PERMISSION_HARD_FAIL = 0
|
||||
PERMISSION_FORCE_SUCCESS = 1
|
||||
PERMISSION_ERROR = 2
|
||||
|
||||
class Exit(enum.Enum):
|
||||
WRONGVERSION = 1
|
||||
LOCKED = 2
|
||||
DISCONNECT = 3
|
||||
FATAL = 4
|
||||
|
||||
PANIC = 20
|
||||
|
|
Loading…
Reference in a new issue