return dic
def load_idxfiles(self):
- datalist = {}
-
- def on_load_record(id, metadata_dic):
- datalist[id] = self._init_extra_data(metadata_dic)
-
print "load_cache"
- cachefile.load_cache(self.bbs_type, on_load_record)
+ iterable = cachefile.load_cache(self.bbs_type)
+ iterable = itertools.imap(self._init_extra_data, iterable)
+ datalist = dict([(dic["id"], dic) for dic in iterable])
+
print "load_idx"
self._load_modified_idxfiles(datalist)
print "save_cache"
return line
-def load_cache(bbs_type, func):
- """ Loads metadata from .cache file
+def load_cache(bbs_type):
+ """ Loads metadata from .cache file. This is generator.
- loads metadata and invokes handler per one thread
+ loads metadata and yield per one thread
- func: invoked at loading one thread's metadata
- should be of the form:
- def handler_example(id, metadata_dic):
- where the first argument is thread id and
- the second metadata dic which key is in metadata_namelist
+ metadata dic key is in metadata_namelist
"""
cachefile_path = misc.get_board_cache_path(bbs_type)
# only if id exists
if "id" in dic and dic["id"]:
- func(dic["id"], dic)
+ yield dic
except IOError:
traceback.print_exc()