|
@@ -29,6 +29,7 @@ import os
|
|
|
from jwmudlib import database
|
|
|
from jwmudlib import jwmu_exceptions
|
|
|
from jwmudlib import daemon
|
|
|
+from jwmudlib import configuration
|
|
|
|
|
|
parser = argparse.ArgumentParser(prog="jwmud", add_help=True)
|
|
|
parser.add_argument("-d", "--daemon", action="store_true", dest="daemon",
|
|
@@ -43,25 +44,40 @@ parser.add_argument("-c", "--config", dest="config", help="define an alternate"
|
|
|
"configuration file")
|
|
|
arguments = parser.parse_args()
|
|
|
|
|
|
-# TODO: Implement configuration and insert it here
|
|
|
+if arguments.config is not None:
|
|
|
+ config = configuration.conf(arguments.config)
|
|
|
+else:
|
|
|
+ config = configuration.conf()
|
|
|
|
|
|
-logger = logging.getLogger("jwmud")
|
|
|
+try:
|
|
|
+ config.Read()
|
|
|
+except jwmu_exceptions.ConfigurationFileAccessDenied as e:
|
|
|
+ print(e, file=sys.stderr)
|
|
|
+ sys.exit(1)
|
|
|
+except jwmu_exceptions.ConfigurationFileMissing as e:
|
|
|
+ print(e, file=sys.stderr)
|
|
|
+ sys.exit(1)
|
|
|
|
|
|
-# TODO: Set log level according to configuration
|
|
|
+logger = logging.getLogger("jwmud")
|
|
|
|
|
|
-logger.setLevel(logging.INFO)
|
|
|
+if config.values["syslog_level"] == "debug":
|
|
|
+ logger.setLevel(logging.DEBUG)
|
|
|
+elif config.values["syslog_level"] == "error":
|
|
|
+ logger.setLevel(logging.ERROR)
|
|
|
+else:
|
|
|
+ logger.setLevel(logging.INFO)
|
|
|
|
|
|
formatter = logging.Formatter("%(name)s[" + str(os.getpid()) + "]: %(message)s")
|
|
|
|
|
|
-
|
|
|
-# TODO: Set syslog facility according to configuration
|
|
|
-
|
|
|
if arguments.daemon is True:
|
|
|
- syslog_handler = logging.handlers.SysLogHandler("/dev/log")
|
|
|
+ if config.values["syslog_facility"] == "daemon":
|
|
|
+ syslog_handler = logging.handlers.SysLogHandler(
|
|
|
+ "/dev/log", facility=logging.handlers.SysLogHandler.LOG_DAEMON)
|
|
|
+ else:
|
|
|
+ syslog_handler = logging.handlers.SysLogHandler("/dev/log")
|
|
|
syslog_handler.setFormatter(formatter)
|
|
|
logger.addHandler(syslog_handler)
|
|
|
else:
|
|
|
console_handler = logging.StreamHandler()
|
|
|
console_handler.setFormatter(formatter)
|
|
|
- logger.addHandler(console_handler)
|
|
|
-
|
|
|
+ logger.addHandler(console_handler)
|