|
@@ -24,12 +24,15 @@ Plain text storage.
|
|
|
|
|
|
|
|
import os
|
|
import os
|
|
|
import posixpath
|
|
import posixpath
|
|
|
|
|
+import codecs
|
|
|
|
|
|
|
|
-from .. import ical
|
|
|
|
|
-from .. import config
|
|
|
|
|
|
|
+from radicale import config, ical
|
|
|
|
|
|
|
|
_folder = os.path.expanduser(config.get("support", "folder"))
|
|
_folder = os.path.expanduser(config.get("support", "folder"))
|
|
|
|
|
|
|
|
|
|
+def _open(path, mode="r"):
|
|
|
|
|
+ return codecs.open(path, mode, config.get("encoding", "stock"))
|
|
|
|
|
+
|
|
|
def calendars():
|
|
def calendars():
|
|
|
"""List available calendars paths."""
|
|
"""List available calendars paths."""
|
|
|
calendars = []
|
|
calendars = []
|
|
@@ -45,17 +48,17 @@ def mkcalendar(name):
|
|
|
user, cal = name.split(posixpath.sep)
|
|
user, cal = name.split(posixpath.sep)
|
|
|
if not os.path.exists(os.path.join(_folder, user)):
|
|
if not os.path.exists(os.path.join(_folder, user)):
|
|
|
os.makedirs(os.path.join(_folder, user))
|
|
os.makedirs(os.path.join(_folder, user))
|
|
|
- fd = open(os.path.join(_folder, user, cal), "w")
|
|
|
|
|
- fd.write(ical.write_calendar().encode(config.get("encoding", "stock")))
|
|
|
|
|
|
|
+ fd = _open(os.path.join(_folder, user, cal), "w")
|
|
|
|
|
+ fd.write(ical.write_calendar())
|
|
|
|
|
|
|
|
def read(cal):
|
|
def read(cal):
|
|
|
"""Read calendar ``cal``."""
|
|
"""Read calendar ``cal``."""
|
|
|
path = os.path.join(_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):
|
|
|
"""Append ``vcalendar`` to ``cal``."""
|
|
"""Append ``vcalendar`` to ``cal``."""
|
|
|
- old_calendar = unicode(read(cal), config.get("encoding", "stock"))
|
|
|
|
|
|
|
+ old_calendar = read(cal)
|
|
|
old_tzs = [tz.tzid for tz in ical.timezones(old_calendar)]
|
|
old_tzs = [tz.tzid for tz in ical.timezones(old_calendar)]
|
|
|
path = os.path.join(_folder, cal.replace(posixpath.sep, os.path.sep))
|
|
path = os.path.join(_folder, cal.replace(posixpath.sep, os.path.sep))
|
|
|
|
|
|
|
@@ -69,29 +72,29 @@ def append(cal, vcalendar):
|
|
|
|
|
|
|
|
for tz in ical.timezones(vcalendar):
|
|
for tz in ical.timezones(vcalendar):
|
|
|
if tz.tzid not in old_tzs:
|
|
if tz.tzid not in old_tzs:
|
|
|
- # TODO: Manage position, encoding and EOL
|
|
|
|
|
- fd = open(path)
|
|
|
|
|
|
|
+ # TODO: Manage position and EOL
|
|
|
|
|
+ fd = _open(path)
|
|
|
lines = [line for line in fd.readlines() if line]
|
|
lines = [line for line in fd.readlines() if line]
|
|
|
fd.close()
|
|
fd.close()
|
|
|
|
|
|
|
|
for i,line in enumerate(tz.text.splitlines()):
|
|
for i,line in enumerate(tz.text.splitlines()):
|
|
|
- lines.insert(2+i, line.encode(config.get("encoding", "stock"))+"\n")
|
|
|
|
|
|
|
+ lines.insert(2 + i, line + "\n")
|
|
|
|
|
|
|
|
- fd = open(path, "w")
|
|
|
|
|
|
|
+ fd = _open(path, "w")
|
|
|
fd.writelines(lines)
|
|
fd.writelines(lines)
|
|
|
fd.close()
|
|
fd.close()
|
|
|
|
|
|
|
|
for obj in objects:
|
|
for obj in objects:
|
|
|
if obj.etag() not in old_objects:
|
|
if obj.etag() not in old_objects:
|
|
|
- # TODO: Manage position, encoding and EOL
|
|
|
|
|
- fd = open(path)
|
|
|
|
|
|
|
+ # TODO: Manage position and EOL
|
|
|
|
|
+ fd = _open(path)
|
|
|
lines = [line for line in fd.readlines() if line]
|
|
lines = [line for line in fd.readlines() if line]
|
|
|
fd.close()
|
|
fd.close()
|
|
|
|
|
|
|
|
for line in obj.text.splitlines():
|
|
for line in obj.text.splitlines():
|
|
|
- lines.insert(-1, line.encode(config.get("encoding", "stock"))+"\n")
|
|
|
|
|
|
|
+ lines.insert(-1, line + "\n")
|
|
|
|
|
|
|
|
- fd = open(path, "w")
|
|
|
|
|
|
|
+ fd = _open(path, "w")
|
|
|
fd.writelines(lines)
|
|
fd.writelines(lines)
|
|
|
fd.close()
|
|
fd.close()
|
|
|
|
|
|
|
@@ -99,15 +102,15 @@ def remove(cal, etag):
|
|
|
"""Remove object named ``etag`` from ``cal``."""
|
|
"""Remove object named ``etag`` from ``cal``."""
|
|
|
path = os.path.join(_folder, cal.replace(posixpath.sep, os.path.sep))
|
|
path = os.path.join(_folder, cal.replace(posixpath.sep, os.path.sep))
|
|
|
|
|
|
|
|
- cal = unicode(read(cal), config.get("encoding", "stock"))
|
|
|
|
|
|
|
+ cal = read(cal)
|
|
|
|
|
|
|
|
headers = ical.headers(cal)
|
|
headers = ical.headers(cal)
|
|
|
timezones = ical.timezones(cal)
|
|
timezones = ical.timezones(cal)
|
|
|
todos = [todo for todo in ical.todos(cal) if todo.etag() != etag]
|
|
todos = [todo for todo in ical.todos(cal) if todo.etag() != etag]
|
|
|
events = [event for event in ical.events(cal) if event.etag() != etag]
|
|
events = [event for event in ical.events(cal) if event.etag() != etag]
|
|
|
|
|
|
|
|
- fd = open(path, "w")
|
|
|
|
|
- fd.write(ical.write_calendar(headers, timezones, todos, events).encode(config.get("encoding", "stock")))
|
|
|
|
|
|
|
+ fd = _open(path, "w")
|
|
|
|
|
+ fd.write(ical.write_calendar(headers, timezones, todos, events))
|
|
|
fd.close()
|
|
fd.close()
|
|
|
|
|
|
|
|
if config.get("support", "calendar"):
|
|
if config.get("support", "calendar"):
|