radicale.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # Get command-line options
  34. parser = optparse.OptionParser()
  35. parser.add_option(
  36. "-d", "--daemon", action="store_true",
  37. default=radicale.config.getboolean("server", "daemon"),
  38. help="launch as daemon")
  39. parser.add_option(
  40. "-H", "--host",
  41. default=radicale.config.get("server", "host"),
  42. help="set server hostname")
  43. parser.add_option(
  44. "-p", "--port", type="int",
  45. default=radicale.config.getint("server", "port"),
  46. help="set server port")
  47. parser.add_option(
  48. "-s", "--ssl", action="store_true",
  49. default=radicale.config.getboolean("server", "ssl"),
  50. help="use SSL connection")
  51. parser.add_option(
  52. "-k", "--key",
  53. default=radicale.config.get("server", "key"),
  54. help="private key file ")
  55. parser.add_option(
  56. "-c", "--certificate",
  57. default=radicale.config.get("server", "certificate"),
  58. help="certificate file ")
  59. options, args = parser.parse_args()
  60. # Update Radicale configuration according to options
  61. for option in parser.option_list:
  62. key = option.dest
  63. if key:
  64. value = getattr(options, key)
  65. radicale.config.set("server", key, value)
  66. # Fork if Radicale is launched as daemon
  67. if options.daemon:
  68. if os.fork():
  69. sys.exit()
  70. sys.stdout = sys.stderr = open(os.devnull, "w")
  71. # Launch calendar server
  72. server_class = radicale.HTTPSServer if options.ssl else radicale.HTTPServer
  73. server = server_class((options.host, options.port), radicale.CalendarHTTPHandler)
  74. server.serve_forever()