radicale.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # This file is part of Radicale Server - Calendar Server
  5. # Copyright © 2008-2010 Guillaume Ayoub
  6. # Copyright © 2008 Nicolas Kandel
  7. # Copyright © 2008 Pascal Halter
  8. #
  9. # This library is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This library is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  21. """
  22. Radicale Server entry point.
  23. Launch the Radicale Serve according to configuration and command-line
  24. arguments.
  25. """
  26. # TODO: Manage depth and calendars/collections (see xmlutils)
  27. # TODO: Manage smart and configurable logs
  28. # TODO: Manage authentication
  29. import os
  30. import sys
  31. import optparse
  32. import radicale
  33. parser = optparse.OptionParser()
  34. parser.add_option(
  35. "-d", "--daemon", action="store_true",
  36. default=radicale.config.getboolean("server", "daemon"),
  37. help="launch as daemon")
  38. parser.add_option(
  39. "-n", "--name",
  40. default=radicale.config.get("server", "name"),
  41. help="set server name")
  42. parser.add_option(
  43. "-p", "--port",
  44. default=radicale.config.getint("server", "port"),
  45. help="set server port")
  46. parser.add_option(
  47. "-P", "--protocol",
  48. default=radicale.config.get("server", "protocol"),
  49. help="set server protocol")
  50. options, args = parser.parse_args()
  51. if options.daemon:
  52. if os.fork():
  53. sys.exit()
  54. sys.stdout = sys.stderr = open(os.devnull, "w")
  55. if options.protocol == "http":
  56. server = radicale.server.HTTPServer(
  57. (options.name, options.port), radicale.CalendarHandler)
  58. server.serve_forever()
  59. else:
  60. raise StandardError("%s: unsupported protocol" % options.protocol)