Split of TaskCache into separate module

This commit is contained in:
Tomas Babej 2015-03-12 21:50:25 +01:00
parent 7268a659b5
commit f987eda6d5
2 changed files with 39 additions and 35 deletions

38
taskwiki/cache.py Normal file
View file

@ -0,0 +1,38 @@
import vim
class TaskCache(object):
"""
A cache that holds all the tasks in the given file and prevents
multiple redundant taskwarrior calls.
"""
def __init__(self, tw):
self.cache = dict()
self.tw = tw
def __getitem__(self, key):
task = self.cache.get(key)
if task is None:
task = VimwikiTask(vim.current.buffer[key], key, self.tw, self)
self.cache[key] = task
return task
def __iter__(self):
# iterated_cache = {
while self.cache.keys():
for key in list(self.cache.keys()):
task = self.cache[key]
if all([t.line_number not in self.cache.keys()
for t in task.add_dependencies]):
del self.cache[key]
yield task
def reset(self):
self.cache = dict()
# def update_tasks(self):
# tasks = [t

View file

@ -26,41 +26,7 @@ How this plugin works:
tw = TaskWarrior()
local_timezone = pytz.timezone('Europe/Bratislava')
class TaskCache(object):
"""
A cache that holds all the tasks in the given file and prevents
multiple redundant taskwarrior calls.
"""
def __init__(self):
self.cache = dict()
def __getitem__(self, key):
task = self.cache.get(key)
if task is None:
task = VimwikiTask(vim.current.buffer[key], key, tw, self)
self.cache[key] = task
return task
def __iter__(self):
# iterated_cache = {
while self.cache.keys():
for key in list(self.cache.keys()):
task = self.cache[key]
if all([t.line_number not in self.cache.keys()
for t in task.add_dependencies]):
del self.cache[key]
yield task
def reset(self):
self.cache = dict()
# def update_tasks(self):
# tasks = [t
cache = TaskCache()
cache = TaskCache(tw)
def update_from_tw():