Add command-line options, user configuration and daemon mode.
This commit is contained in:
parent
f1c8497f3b
commit
1b8608021f
4
TODO
4
TODO
@ -15,8 +15,8 @@
|
|||||||
===
|
===
|
||||||
|
|
||||||
* SSL connections and authentications
|
* SSL connections and authentications
|
||||||
* Daemon mode
|
* [DONE] Daemon mode
|
||||||
* User configuration
|
* [DONE] User configuration
|
||||||
|
|
||||||
|
|
||||||
0.5
|
0.5
|
||||||
|
47
radicale.py
47
radicale.py
@ -19,22 +19,49 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
# TODO: Manage depth and calendars/collections (see xmlutils)
|
|
||||||
# TODO: Manage smart and configurable logs
|
|
||||||
# TODO: Manage authentication
|
|
||||||
# TODO: Magage command-line options
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Radicale Server entry point.
|
Radicale Server entry point.
|
||||||
|
|
||||||
Launch the Radicale Server according to the configuration.
|
Launch the Radicale Serve according to configuration and command-line
|
||||||
|
arguments.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# TODO: Manage depth and calendars/collections (see xmlutils)
|
||||||
|
# TODO: Manage smart and configurable logs
|
||||||
|
# TODO: Manage authentication
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import optparse
|
||||||
|
|
||||||
import radicale
|
import radicale
|
||||||
|
|
||||||
if radicale.config.get("server", "protocol") == "http":
|
parser = optparse.OptionParser()
|
||||||
|
parser.add_option(
|
||||||
|
"-d", "--daemon", action="store_true",
|
||||||
|
default=radicale.config.getboolean("server", "daemon"),
|
||||||
|
help="launch as daemon")
|
||||||
|
parser.add_option(
|
||||||
|
"-n", "--name",
|
||||||
|
default=radicale.config.get("server", "name"),
|
||||||
|
help="set server name")
|
||||||
|
parser.add_option(
|
||||||
|
"-p", "--port",
|
||||||
|
default=radicale.config.getint("server", "port"),
|
||||||
|
help="set server port")
|
||||||
|
parser.add_option(
|
||||||
|
"-P", "--protocol",
|
||||||
|
default=radicale.config.get("server", "protocol"),
|
||||||
|
help="set server protocol")
|
||||||
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
|
if options.daemon:
|
||||||
|
if os.fork():
|
||||||
|
sys.exit()
|
||||||
|
sys.stdout = sys.stderr = open(os.devnull, "w")
|
||||||
|
if options.protocol == "http":
|
||||||
server = radicale.server.HTTPServer(
|
server = radicale.server.HTTPServer(
|
||||||
(radicale.config.get("server", "name"),
|
(options.name, options.port), radicale.CalendarHandler)
|
||||||
radicale.config.getint("server", "port")),
|
|
||||||
radicale.CalendarHandler)
|
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
|
else:
|
||||||
|
raise StandardError("%s: unsupported protocol" % options.protocol)
|
||||||
|
@ -26,6 +26,7 @@ Give a configparser-like interface to read and write configuration.
|
|||||||
|
|
||||||
# TODO: Use abstract filenames for other platforms
|
# TODO: Use abstract filenames for other platforms
|
||||||
|
|
||||||
|
import os
|
||||||
try:
|
try:
|
||||||
from configparser import RawConfigParser as ConfigParser
|
from configparser import RawConfigParser as ConfigParser
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -45,6 +46,7 @@ _initial = {
|
|||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"name": "",
|
"name": "",
|
||||||
"port": "5232",
|
"port": "5232",
|
||||||
|
"daemon": "False",
|
||||||
#"certificate": "/etc/apache2/ssl/server.crt",
|
#"certificate": "/etc/apache2/ssl/server.crt",
|
||||||
#"privatekey": "/etc/apache2/ssl/server.key",
|
#"privatekey": "/etc/apache2/ssl/server.key",
|
||||||
#"log": "/var/www/radicale/server.log",
|
#"log": "/var/www/radicale/server.log",
|
||||||
@ -64,7 +66,7 @@ _initial = {
|
|||||||
},
|
},
|
||||||
"support": {
|
"support": {
|
||||||
"type": "plain",
|
"type": "plain",
|
||||||
"folder": "~/.config/radicale",
|
"folder": os.path.expanduser("~/.config/radicale"),
|
||||||
"calendar": "radicale/calendar",
|
"calendar": "radicale/calendar",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -75,3 +77,4 @@ for section, values in _initial.items():
|
|||||||
_config.set(section, key, value)
|
_config.set(section, key, value)
|
||||||
|
|
||||||
_config.read("/etc/radicale/config")
|
_config.read("/etc/radicale/config")
|
||||||
|
_config.read(os.path.expanduser("~/.config/radicale/config"))
|
||||||
|
Loading…
Reference in New Issue
Block a user