DELETE requests can delete calendars (closes #514)

This commit is contained in:
Guillaume Ayoub
2011-11-29 17:41:08 +01:00
parent bfe527dd41
commit 1f2f39a87a
3 changed files with 25 additions and 8 deletions

View File

@ -172,6 +172,7 @@ class Calendar(object):
self.encoding = "utf-8"
split_path = path.split("/")
self.path = os.path.join(FOLDER, path.replace("/", os.sep))
self.props_path = self.path + '.props'
if principal and split_path and os.path.isdir(self.path):
# Already existing principal calendar
self.owner = split_path[0]
@ -300,6 +301,11 @@ class Calendar(object):
self.write(items=items)
def delete(self):
"""Delete the calendar."""
os.remove(self.path)
os.remove(self.props_path)
def remove(self, name):
"""Remove object named ``name`` from calendar."""
components = [
@ -415,16 +421,15 @@ class Calendar(object):
@contextmanager
def props(self):
"""Get the calendar properties."""
props_path = self.path + '.props'
# On enter
properties = {}
if os.path.exists(props_path):
with open(props_path) as prop_file:
if os.path.exists(self.props_path):
with open(self.props_path) as prop_file:
properties.update(json.load(prop_file))
yield properties
# On exit
self._create_dirs(props_path)
with open(props_path, 'w') as prop_file:
self._create_dirs(self.props_path)
with open(self.props_path, 'w') as prop_file:
json.dump(properties, prop_file)
@property