2 # -*- coding: utf-8 -*-
4 # This file is part of Calypso Server - Calendar Server
5 # Copyright © 2011 Keith Packard
6 # Copyright © 2008-2011 Guillaume Ayoub
7 # Copyright © 2008 Nicolas Kandel
8 # Copyright © 2008 Pascal Halter
10 # This library is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Calypso. If not, see <http://www.gnu.org/licenses/>.
23 # This file is just a script, allow [a-z0-9]* variable names
24 # pylint: disable-msg=C0103
26 # ``import calypso`` refers to the ``calypso`` module, not ``calypso.py``
27 # pylint: disable-msg=W0406
30 Calypso Server entry point.
32 Launch the Calypso Server according to configuration and command-line
37 # TODO: Manage smart and configurable logs
44 import calypso.ical as ical
46 # Get command-line options
47 parser = optparse.OptionParser()
49 "-v", "--version", action="store_true",
51 help="show version and exit")
53 "-d", "--daemon", action="store_true",
54 default=calypso.config.getboolean("server", "daemon"),
55 help="launch as daemon")
57 "-f", "--foreground", action="store_false", dest="daemon",
58 help="launch in foreground (opposite of --daemon)")
61 default=calypso.config.get("server", "host"),
62 help="set server hostname")
64 "-p", "--port", type="int",
65 default=calypso.config.getint("server", "port"),
66 help="set server port")
68 "-s", "--ssl", action="store_true",
69 default=calypso.config.getboolean("server", "ssl"),
70 help="use SSL connection")
72 "-S", "--no-ssl", action="store_false", dest="ssl",
73 help="do not use SSL connection (opposite of --ssl)")
76 default=calypso.config.get("server", "key"),
77 help="private key file ")
79 "-c", "--certificate",
80 default=calypso.config.get("server", "certificate"),
81 help="certificate file ")
83 "-i", "--import", dest="import_dest")
85 (options, args) = parser.parse_args()
87 # Update Calypso configuration according to options
88 for option in parser.option_list:
91 value = getattr(options, key)
92 calypso.config.set("server", key, value)
94 # Print version and exit if the option is given
96 print(calypso.VERSION)
99 # Run import if requested
100 if options.import_dest:
102 calendar = ical.Calendar(options.import_dest)
104 print "Cannot open calendar %s" % options.import_dest
108 if not calendar.import_file(arg):
115 # Fork if Calypso is launched as daemon
119 sys.stdout = sys.stderr = open(os.devnull, "w")
121 # Launch calendar server
122 server_class = calypso.HTTPSServer if options.ssl else calypso.HTTPServer
123 server = server_class(
124 (options.host, options.port), calypso.CalendarHTTPHandler)
125 server.serve_forever(poll_interval=10)