From 0704e315bae03ed64ed623a96b29ca58fcc6d149 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 28 May 2014 17:36:26 +0200 Subject: [PATCH] scan in tasks queue --- oml/downloads.py | 2 -- oml/media/__init__.py | 2 +- oml/server.py | 4 ++-- oml/tasks.py | 3 ++- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/oml/downloads.py b/oml/downloads.py index 1f417cf..7199626 100644 --- a/oml/downloads.py +++ b/oml/downloads.py @@ -35,8 +35,6 @@ class Downloads(Thread): def run(self): time.sleep(2) with self._app.app_context(): - import item.scan - item.scan.run_scan() while self._running: self.download_next() time.sleep(0.5) diff --git a/oml/media/__init__.py b/oml/media/__init__.py index 3270bf6..1c88946 100644 --- a/oml/media/__init__.py +++ b/oml/media/__init__.py @@ -54,7 +54,7 @@ def metadata(f, from_=None): data[key] = info[key] if key in opf_info: data[key] = opf_info[key] - if key in data[key]: + if key in data: if isinstance(data[key], basestring): data[key] = data[key].replace('\x00', '') elif isinstance(data[key], list): diff --git a/oml/server.py b/oml/server.py index d50ec4b..83433ab 100644 --- a/oml/server.py +++ b/oml/server.py @@ -17,6 +17,7 @@ import state import node.server import oxtornado from cache import Cache +import tasks from item.icons import IconHandler from item.handlers import EpubHandler, ReaderHandler, FileHandler @@ -68,13 +69,12 @@ def run(): state.main = IOLoop.instance() state.cache = Cache(ttl=10) + state.tasks = tasks.Tasks(app) def start_node(): import user import downloads import nodes - import tasks - state.tasks = tasks.Tasks(app) state.node = node.server.start(app) state.nodes = nodes.Nodes(app) state.downloads = downloads.Downloads(app) diff --git a/oml/tasks.py b/oml/tasks.py index 660122b..dae2d92 100644 --- a/oml/tasks.py +++ b/oml/tasks.py @@ -20,6 +20,7 @@ class Tasks(Thread): Thread.__init__(self) self.daemon = True self.start() + self.queue('scan') def run(self): import item.scan @@ -46,6 +47,6 @@ class Tasks(Thread): self.q.join() return Thread.join(self) - def queue(self, action, data): + def queue(self, action, data=None): self.q.put((action, data))