Configuration cleanup.

This commit is contained in:
Guillaume Ayoub 2010-01-16 13:33:50 +01:00
parent 4ee09cf817
commit f1c8497f3b
6 changed files with 37 additions and 25 deletions

2
TODO
View File

@ -30,6 +30,6 @@
=== ===
* [DONE] No Twisted dependency * [DONE] No Twisted dependency
* [IN PROGRESS] Python 3 support * [DONE] Python 3 support
* iCal filters and rights * iCal filters and rights
* Other CalDAV clients supports * Other CalDAV clients supports

View File

@ -27,13 +27,14 @@
""" """
Radicale Server entry point. Radicale Server entry point.
Launch the Radicale Serve according to the configuration. Launch the Radicale Server according to the configuration.
""" """
import radicale import radicale
if radicale.config.get("server", "type") == "http": if radicale.config.get("server", "protocol") == "http":
server = radicale.server.HTTPServer( server = radicale.server.HTTPServer(
("", radicale.config.getint("server", "port")), (radicale.config.get("server", "name"),
radicale.config.getint("server", "port")),
radicale.CalendarHandler) radicale.CalendarHandler)
server.serve_forever() server.serve_forever()

View File

@ -37,6 +37,16 @@ class CalendarHandler(server.BaseHTTPRequestHandler):
cal = "%s/%s" % (path[0], path[1]) cal = "%s/%s" % (path[0], path[1])
self.calendar = calendar.Calendar("radicale", cal) self.calendar = calendar.Calendar("radicale", cal)
def do_GET(self):
"""Manage GET ``request``."""
self._parse_path()
answer = self.calendar.vcalendar().encode(config.get("encoding", "request"))
self.send_response(client.OK)
self.send_header("Content-Length", len(answer))
self.end_headers()
self.wfile.write(answer)
def do_DELETE(self): def do_DELETE(self):
"""Manage DELETE ``request``.""" """Manage DELETE ``request``."""
self._parse_path() self._parse_path()
@ -51,7 +61,7 @@ class CalendarHandler(server.BaseHTTPRequestHandler):
def do_OPTIONS(self): def do_OPTIONS(self):
"""Manage OPTIONS ``request``.""" """Manage OPTIONS ``request``."""
self.send_response(client.OK) self.send_response(client.OK)
self.send_header("Allow", "DELETE, OPTIONS, PROPFIND, PUT, REPORT") self.send_header("Allow", "DELETE, GET, OPTIONS, PROPFIND, PUT, REPORT")
self.send_header("DAV", "1, calendar-access") self.send_header("DAV", "1, calendar-access")
self.end_headers() self.end_headers()

View File

@ -21,11 +21,11 @@
""" """
Fake ACL. Fake ACL.
Just load the default user set in configuration, with no rights management. Just load the default user "radicale", with no rights management.
""" """
from radicale import config from radicale import config
def users(): def users():
"""Get the list of all users.""" """Get the list of all users."""
return [config.get("acl", "user")] return ["radicale"]

View File

@ -24,6 +24,8 @@ Radicale configuration module.
Give a configparser-like interface to read and write configuration. Give a configparser-like interface to read and write configuration.
""" """
# TODO: Use abstract filenames for other platforms
try: try:
from configparser import RawConfigParser as ConfigParser from configparser import RawConfigParser as ConfigParser
except ImportError: except ImportError:
@ -40,11 +42,12 @@ items = _config.items
_initial = { _initial = {
"server": { "server": {
"type": "http", "protocol": "http",
"certificate": "/etc/apache2/ssl/server.crt", "name": "",
"privatekey": "/etc/apache2/ssl/server.key",
"log": "/var/www/radicale/server.log",
"port": "5232", "port": "5232",
#"certificate": "/etc/apache2/ssl/server.crt",
#"privatekey": "/etc/apache2/ssl/server.key",
#"log": "/var/www/radicale/server.log",
}, },
"encoding": { "encoding": {
"request": "utf-8", "request": "utf-8",
@ -55,14 +58,9 @@ _initial = {
"D": "DAV:", "D": "DAV:",
"CS": "http://calendarserver.org/ns/", "CS": "http://calendarserver.org/ns/",
}, },
"status": {
"200": "HTTP/1.1 200 OK",
"204": "HTTP/1.1 204 No Content",
},
"acl": { "acl": {
"type": "fake", "type": "fake",
"filename": "/etc/radicale/users", #"filename": "/etc/radicale/users",
"user": "radicale",
}, },
"support": { "support": {
"type": "plain", "type": "plain",
@ -76,5 +74,4 @@ for section, values in _initial.items():
for key, value in values.items(): for key, value in values.items():
_config.set(section, key, value) _config.set(section, key, value)
# TODO: Use abstract filename for other platforms
_config.read("/etc/radicale/config") _config.read("/etc/radicale/config")

View File

@ -31,17 +31,21 @@ in them for XML requests (all but PUT).
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from radicale import config, ical from radicale import client, config, ical
# TODO: This is a well-known and accepted hack for ET to avoid ET from renaming # TODO: This is a well-known and accepted hack for ET to avoid ET from renaming
# namespaces, which is accepted in XML norm but often not in XML # namespaces, which is accepted in XML norm but often not in XML
# readers. Is there another clean solution to force namespaces? # readers. Is there another clean solution to force namespaces?
for key,value in config.items("namespace"): for key, value in config.items("namespace"):
ET._namespace_map[value] = key ET._namespace_map[value] = key
def _tag(short_name, local): def _tag(short_name, local):
"""Get XML Clark notation {uri(``short_name``)}``local``.""" """Get XML Clark notation {uri(``short_name``)}``local``."""
return "{%s}%s"%(config.get("namespace", short_name), local) return "{%s}%s" % (config.get("namespace", short_name), local)
def _response(code):
"""Return full W3C names from HTTP status codes."""
return "HTTP/1.1 %i %s" % (code, client.responses[code])
def delete(obj, calendar, url): def delete(obj, calendar, url):
"""Read and answer DELETE requests. """Read and answer DELETE requests.
@ -61,7 +65,7 @@ def delete(obj, calendar, url):
response.append(href) response.append(href)
status = ET.Element(_tag("D", "status")) status = ET.Element(_tag("D", "status"))
status.text = config.get("status", "200") status.text = _response(200)
response.append(status) response.append(status)
return ET.tostring(multistatus, config.get("encoding", "request")) return ET.tostring(multistatus, config.get("encoding", "request"))
@ -119,7 +123,7 @@ def propfind(xml_request, calendar, url):
prop.append(getctag) prop.append(getctag)
status = ET.Element(_tag("D", "status")) status = ET.Element(_tag("D", "status"))
status.text = config.get("status", "200") status.text = _response(200)
propstat.append(status) propstat.append(status)
return ET.tostring(multistatus, config.get("encoding", "request")) return ET.tostring(multistatus, config.get("encoding", "request"))
@ -186,7 +190,7 @@ def report(xml_request, calendar, url):
response.append(href) response.append(href)
status = ET.Element(_tag("D", "status")) status = ET.Element(_tag("D", "status"))
status.text = config.get("status", "204") status.text = _response(204)
response.append(status) response.append(status)
for obj in objects: for obj in objects:
@ -218,7 +222,7 @@ def report(xml_request, calendar, url):
prop.append(cdata) prop.append(cdata)
status = ET.Element(_tag("D", "status")) status = ET.Element(_tag("D", "status"))
status.text = config.get("status", "200") status.text = _response(200)
propstat.append(status) propstat.append(status)
return ET.tostring(multistatus, config.get("encoding", "request")) return ET.tostring(multistatus, config.get("encoding", "request"))