Out-of-the-box simple configuration

git-svn-id: http://svn.32rwr.info/radicale/trunk@5 74e4794c-479d-4a33-9dda-c6c359d70f12
This commit is contained in:
(no author) 2008-12-30 19:26:03 +00:00
parent 5e1a4d4131
commit e87d37703d
7 changed files with 72 additions and 13 deletions

View File

@ -21,10 +21,7 @@
# TODO: Manage smart and configurable logs # TODO: Manage smart and configurable logs
# TODO: Manage authentication # TODO: Manage authentication
# TODO: remove this hack
import sys import sys
sys.path.append("/usr/local/lib/python2.5/site-packages")
from twisted.web import server from twisted.web import server
from twisted.internet import reactor from twisted.internet import reactor
from twisted.python import log from twisted.python import log

25
radicale/acl/fake.py Normal file
View File

@ -0,0 +1,25 @@
# -*- coding: utf-8; indent-tabs-mode: nil; -*-
#
# This file is part of Radicale Server - Calendar Server
# Copyright © 2008 The Radicale Team
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
from .. import config
def users():
"""
Get the List of all Users
"""
return [config.get("acl", "defaultUser")]

View File

@ -35,7 +35,7 @@ _initial = {
"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",
"port": "1001", "port": "5232",
}, },
"encoding": { "encoding": {
"request": "utf-8", "request": "utf-8",
@ -48,14 +48,17 @@ _initial = {
}, },
"status": { "status": {
"200": "HTTP/1.1 200 OK", "200": "HTTP/1.1 200 OK",
"204": "HTTP/1.1 204 No Content",
}, },
"acl": { "acl": {
"type": "htpasswd", "type": "fake",
"filename": "/etc/radicale/users", "filename": "/etc/radicale/users",
"defaultUser": "radicale",
}, },
"support": { "support": {
"type": "plain", "type": "plain",
"folder": "/var/local/radicale", "folder": "~/.config/radicale",
"defaultCalendar": "radicale/calendar",
}, },
} }

View File

@ -21,18 +21,21 @@
import calendar import calendar
def writeCalendar(headers=[], timezones=[], todos=[], events=[]): def writeCalendar(headers=[calendar.Header("PRODID:-//The Radicale Team//NONSGML Radicale Server//EN"),
calendar.Header("VERSION:2.0")],
timezones=[], todos=[], events=[]):
""" """
Create calendar from headers, timezones, todos, events Create calendar from headers, timezones, todos, events
""" """
# TODO: Manage encoding and EOL # TODO: Manage encoding and EOL
return "\n".join(( cal = "\n".join((
"BEGIN:VCALENDAR", "BEGIN:VCALENDAR",
"\n".join([header.text for header in headers]), "\n".join([header.text for header in headers]),
"\n".join([timezone.text for timezone in timezones]), "\n".join([timezone.text for timezone in timezones]),
"\n".join([todo.text for todo in todos]), "\n".join([todo.text for todo in todos]),
"\n".join([event.text for event in events]), "\n".join([event.text for event in events]),
"END:VCALENDAR")) "END:VCALENDAR"))
return "\n".join([line for line in cal.splitlines() if line])
def events(vcalendar): def events(vcalendar):
""" """

View File

@ -22,5 +22,6 @@ _support = __import__(config.get("support", "type"), locals(), globals())
append = _support.append append = _support.append
calendars =_support.calendars calendars =_support.calendars
mkcalendar =_support.mkcalendar
read = _support.read read = _support.read
remove = _support.remove remove = _support.remove

View File

@ -22,23 +22,35 @@ import posixpath
from .. import ical from .. import ical
from .. import config from .. import config
_folder = os.path.expanduser(config.get("support", "folder"))
def calendars(): def calendars():
""" """
List Available Calendars Paths List Available Calendars Paths
""" """
calendars = [] calendars = []
for folder in os.listdir(config.get("support", "folder")): for folder in os.listdir(_folder):
for cal in os.listdir(os.path.join(config.get("support", "folder"), folder)): for cal in os.listdir(os.path.join(_folder, folder)):
calendars.append(posixpath.join(folder, cal)) calendars.append(posixpath.join(folder, cal))
return calendars return calendars
def mkcalendar(name):
"""
Write new calendar
"""
user, cal = name.split(posixpath.sep)
if not os.path.exists(os.path.join(_folder, user)):
os.makedirs(os.path.join(_folder, user))
fd = open(os.path.join(_folder, user, cal), "w")
fd.write(ical.writeCalendar())
def read(cal): def read(cal):
""" """
Read cal Read cal
""" """
path = os.path.join(config.get("support", "folder"), cal.replace(posixpath.sep, os.path.sep)) path = os.path.join(_folder, cal.replace(posixpath.sep, os.path.sep))
return open(path).read() return open(path).read()
def append(cal, vcalendar): def append(cal, vcalendar):
@ -47,7 +59,7 @@ def append(cal, vcalendar):
""" """
oldCalendar = read(cal) oldCalendar = read(cal)
oldTzs = [tz.tzid for tz in ical.timezones(oldCalendar)] oldTzs = [tz.tzid for tz in ical.timezones(oldCalendar)]
path = os.path.join(config.get("support", "folder"), cal.replace(posixpath.sep, os.path.sep)) path = os.path.join(_folder, cal.replace(posixpath.sep, os.path.sep))
oldObjects = [] oldObjects = []
oldObjects.extend([event.etag() for event in ical.events(oldCalendar)]) oldObjects.extend([event.etag() for event in ical.events(oldCalendar)])
@ -89,7 +101,7 @@ def remove(cal, etag):
""" """
Remove object named uid from cal Remove object named uid from cal
""" """
path = os.path.join(config.get("support", "folder"), cal.replace(posixpath.sep, os.path.sep)) path = os.path.join(_folder, cal.replace(posixpath.sep, os.path.sep))
cal = read(cal) cal = read(cal)
@ -102,3 +114,8 @@ def remove(cal, etag):
fd.write(ical.writeCalendar(headers, timezones, todos, events)) fd.write(ical.writeCalendar(headers, timezones, todos, events))
fd.close() fd.close()
if config.get("support", "defaultCalendar"):
user, cal = config.get("support", "defaultCalendar").split(posixpath.sep)
if not os.path.exists(os.path.join(_folder, user, cal)):
mkcalendar(config.get("support", "defaultCalendar"))

View File

@ -171,6 +171,19 @@ def report(xmlRequest, calendar, url):
objects.extend(ical.events(calendar.vcalendar())) objects.extend(ical.events(calendar.vcalendar()))
objects.extend(ical.todos(calendar.vcalendar())) objects.extend(ical.todos(calendar.vcalendar()))
if not objects:
# TODO: Read rfc4791-9.[6|10] to find a right answer
response = ET.Element(_tag("D", "response"))
multistatus.append(response)
href = ET.Element(_tag("D", "href"))
href.text = url
response.append(href)
status = ET.Element(_tag("D", "status"))
status.text = config.get("status", "204")
response.append(status)
for obj in objects: for obj in objects:
# TODO: Use the hreference to read data and create href.text # TODO: Use the hreference to read data and create href.text
# We assume here that hreference is url # We assume here that hreference is url