indexed items storage

Conflicts:
	radicale/storage/filesystem.py
This commit is contained in:
deronnax 2014-08-19 15:03:18 +02:00 committed by Guillaume Ayoub
parent 240125aca7
commit fbbbaae646
2 changed files with 23 additions and 13 deletions

View File

@ -193,6 +193,7 @@ class Collection(object):
else: else:
self.owner = None self.owner = None
self.is_principal = principal self.is_principal = principal
self._items = self._parse(self.text, (Event, Todo, Journal, Card, Timezone))
@classmethod @classmethod
def from_path(cls, path, depth="1", include_container=True): def from_path(cls, path, depth="1", include_container=True):
@ -341,13 +342,11 @@ class Collection(object):
else: else:
items[item.name] = item items[item.name] = item
return list(items.values()) return items
def get_item(self, name): def get_item(self, name):
"""Get collection item called ``name``.""" """Get collection item called ``name``."""
for item in self.items: raise NotImplementedError
if item.name == name:
return item
def append(self, name, text): def append(self, name, text):
"""Append items from ``text`` to collection. """Append items from ``text`` to collection.
@ -355,7 +354,7 @@ class Collection(object):
If ``name`` is given, give this name to new items in ``text``. If ``name`` is given, give this name to new items in ``text``.
""" """
items = self.items items = self.items.values()
for new_item in self._parse( for new_item in self._parse(
text, (Timezone, Event, Todo, Journal, Card), name): text, (Timezone, Event, Todo, Journal, Card), name):
@ -383,7 +382,7 @@ class Collection(object):
headers = headers or self.headers or ( headers = headers or self.headers or (
Header("PRODID:-//Radicale//NONSGML Radicale Server//EN"), Header("PRODID:-//Radicale//NONSGML Radicale Server//EN"),
Header("VERSION:%s" % self.version)) Header("VERSION:%s" % self.version))
items = items if items is not None else self.items items = items if items is not None else self.items.values()
text = serialize(self.tag, headers, items) text = serialize(self.tag, headers, items)
self.save(text) self.save(text)
@ -466,40 +465,49 @@ class Collection(object):
return header_lines return header_lines
@staticmethod
def _filter_items(items, item_type):
return [item for item in items if item.tag == item_type.tag]
@staticmethod
def _filter_items_many(items, item_types):
tags = [item_type.tag for item_type in item_types]
return [item for item in items if item.tag in tags]
@property @property
def items(self): def items(self):
"""Get list of all items in collection.""" """Get list of all items in collection."""
return self._parse(self.text, (Event, Todo, Journal, Card, Timezone)) return self._items.values()
@property @property
def components(self): def components(self):
"""Get list of all components in collection.""" """Get list of all components in collection."""
return self._parse(self.text, (Event, Todo, Journal, Card)) return self._filter_items_many(self.items, (Event, Todo, Journal, Card))
@property @property
def events(self): def events(self):
"""Get list of ``Event`` items in calendar.""" """Get list of ``Event`` items in calendar."""
return self._parse(self.text, (Event,)) return self._filter_items(self.items, Event)
@property @property
def todos(self): def todos(self):
"""Get list of ``Todo`` items in calendar.""" """Get list of ``Todo`` items in calendar."""
return self._parse(self.text, (Todo,)) return self._filter_items(self.items, Todo)
@property @property
def journals(self): def journals(self):
"""Get list of ``Journal`` items in calendar.""" """Get list of ``Journal`` items in calendar."""
return self._parse(self.text, (Journal,)) return self._filter_items(self.items, Journal)
@property @property
def timezones(self): def timezones(self):
"""Get list of ``Timezone`` items in calendar.""" """Get list of ``Timezone`` items in calendar."""
return self._parse(self.text, (Timezone,)) return self._filter_items(self.items, Timezone)
@property @property
def cards(self): def cards(self):
"""Get list of ``Card`` items in address book.""" """Get list of ``Card`` items in address book."""
return self._parse(self.text, (Card,)) return self._filter_items(self.items, Card)
@property @property
def owner_url(self): def owner_url(self):

View File

@ -117,6 +117,8 @@ class Collection(ical.Collection):
modification_time = time.gmtime(os.path.getmtime(self._path)) modification_time = time.gmtime(os.path.getmtime(self._path))
return time.strftime("%a, %d %b %Y %H:%M:%S +0000", modification_time) return time.strftime("%a, %d %b %Y %H:%M:%S +0000", modification_time)
def get_item(self, name):
return self._items.get(name)
@property @property
@contextmanager @contextmanager
def props(self): def props(self):