1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #! /usr/bin/env python3
- #jwmud - a program to create dynamic alarms based on configurable wake up
- # times
- #
- # written by Helmut Pozimski 2012-2014
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; version 2
- # of the License.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor,
- # Boston, MA 02110-1301, USA.
- import logging
- import logging.handlers
- import argparse
- import sys
- 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",
- help="run jwmud as a daemon")
- parser.add_argument("-u", "--user", dest="user", help="define an unprivileged "
- "user to run the daemon")
- parser.add_argument("-g", "--group", dest="group", help = "define an "
- "unprivileged group "
- "to run the daemon")
- parser.add_argument("-c", "--config", dest="config", help="define an alternate"
- " path to the "
- "configuration file")
- arguments = parser.parse_args()
- if arguments.config is not None:
- config = configuration.conf(arguments.config)
- else:
- config = configuration.conf()
- 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)
- logger = logging.getLogger("jwmud")
- 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")
- if arguments.daemon is True:
- 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)
|