jwmud 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #! /usr/bin/env python3
  2. #jwmud - a program to create dynamic alarms based on configurable wake up
  3. # times
  4. #
  5. # written by Helmut Pozimski 2012-2014
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; version 2
  10. # of the License.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. # Boston, MA 02110-1301, USA.
  21. import logging
  22. import logging.handlers
  23. import argparse
  24. import sys
  25. import os
  26. from jwmudlib import database
  27. from jwmudlib import jwmu_exceptions
  28. from jwmudlib import daemon
  29. parser = argparse.ArgumentParser(prog="jwmud", add_help=True)
  30. parser.add_argument("-d", "--daemon", action="store_true", dest="daemon",
  31. help="run jwmud as a daemon")
  32. parser.add_argument("-u", "--user", dest="user", help="define an unprivileged "
  33. "user to run the daemon")
  34. parser.add_argument("-g", "--group", dest="group", help = "define an "
  35. "unprivileged group "
  36. "to run the daemon")
  37. parser.add_argument("-c", "--config", dest="config", help="define an alternate"
  38. " path to the "
  39. "configuration file")
  40. arguments = parser.parse_args()
  41. # TODO: Implement configuration and insert it here
  42. logger = logging.getLogger("jwmud")
  43. # TODO: Set log level according to configuration
  44. logger.setLevel(logging.INFO)
  45. formatter = logging.Formatter("%(name)s[" + str(os.getpid()) + "]: %(message)s")
  46. # TODO: Set syslog facility according to configuration
  47. if arguments.daemon is True:
  48. syslog_handler = logging.handlers.SysLogHandler("/dev/log")
  49. syslog_handler.setFormatter(formatter)
  50. logger.addHandler(syslog_handler)
  51. else:
  52. console_handler = logging.StreamHandler()
  53. console_handler.setFormatter(formatter)
  54. logger.addHandler(console_handler)