try/catch of objects avoiding not serving any object in case an object has no valid contents

also log duration of how many objects are read per folder
This commit is contained in:
Peter Bieringer 2016-09-17 12:52:42 +02:00
parent 0c1dbc30bd
commit cd97aab72c

View File

@ -34,6 +34,7 @@ import stat
import subprocess
import threading
import time
import datetime
from contextlib import contextmanager
from hashlib import md5
from importlib import import_module
@ -699,6 +700,7 @@ class Collection(BaseCollection):
if not os.path.exists(self._filesystem_path):
return None
items = []
time_begin = datetime.datetime.now()
for href in os.listdir(self._filesystem_path):
if not is_safe_filesystem_path_component(href):
self.logger.debug("Skipping component: %s", href)
@ -707,7 +709,12 @@ class Collection(BaseCollection):
if os.path.isfile(path):
self.logger.debug("Read object: %s", path)
with open(path, encoding=self.encoding, newline="") as fd:
items.append(vobject.readOne(fd.read()))
try:
items.append(vobject.readOne(fd.read()))
except:
self.logger.error("Object broken (skip): %s", path)
time_end = datetime.datetime.now()
self.logger.info("Collection read %d items in %s sec from %s", len(items),(time_end - time_begin).total_seconds(), self._filesystem_path)
if self.get_meta("tag") == "VCALENDAR":
collection = vobject.iCalendar()
for item in items: