Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
geier committed Mar 4, 2015
2 parents 1536013 + 7ea63f3 commit f345d10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions khal/khalendar/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self, calendar, db_path, locale):

@contextlib.contextmanager
def at_once(self):
assert not self._at_once
self._at_once = True
try:
yield self
Expand Down
21 changes: 12 additions & 9 deletions khal/khalendar/khalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,26 @@ def update(self, event):
param event: the event that should be updated
type event: event.Event
"""
assert event.etag
if self._readonly:
raise ReadOnlyCalendarError()

with self._dbtool.at_once():
if self._readonly:
raise ReadOnlyCalendarError()
if event.etag is None:
self.new(event)
else:
etag = self._storage.update(event.href, event, event.etag)
self._dbtool.update(event.vevent.to_ical(), event.href, etag=etag)
event.etag = self._storage.update(event.href, event, event.etag)
self._dbtool.update(event.vevent.to_ical(), event.href, event.etag)
self._dbtool.set_ctag(self.local_ctag())

def new(self, event):
"""save a new event to the database
param event: the event that should be updated
type event: event.Event
"""
assert not event.etag
if self._readonly:
raise ReadOnlyCalendarError()

with self._dbtool.at_once():
if self._readonly:
raise ReadOnlyCalendarError()
event.href, event.etag = self._storage.upload(event)
self._dbtool.update(event.to_ical(), event.href, event.etag)
self._dbtool.set_ctag(self.local_ctag())
Expand Down Expand Up @@ -256,6 +258,7 @@ def get_event(self, href, calendar):

def change_collection(self, event, new_collection):
href, etag, calendar = event.href, event.etag, event.calendar
event.etag = None
self._calnames[new_collection].new(event)
self._calnames[calendar].delete(href, etag)

Expand Down

0 comments on commit f345d10

Please sign in to comment.