more logging, reset cancel imort

This commit is contained in:
j 2016-01-23 18:07:25 +05:30
parent 216fd0c232
commit cded8b586a
4 changed files with 25 additions and 2 deletions

View file

@ -328,6 +328,8 @@ def _import(data):
mode copy|move
}
'''
if 'cancel' in state.activity:
del state.activity['cancel']
state.tasks.queue('import', data)
return {}
actions.register(_import, 'import', cache=False)

View file

@ -371,9 +371,11 @@ class Item(db.Model):
break
def update_cover(self):
logger.debug('update cover %s', self.id)
key = 'cover:%s'%self.id
cover = None
if 'cover' in self.meta and self.meta['cover']:
logger.debug('download cover %s %s', self.id, self.meta['cover'])
try:
cover = ox.cache.read_url(self.meta['cover'])
except:
@ -389,7 +391,9 @@ class Item(db.Model):
self.info['coverRatio'] = self.info['previewRatio']
elif 'coverRatio' in self.info:
del self.info['coverRatio']
logger.debug('clear cover:%s:', self.id)
icons.clear('cover:%s:' % self.id)
logger.debug('update_cover done')
def get_preview(self):
key = 'preview:%s'%self.id
@ -400,6 +404,7 @@ class Item(db.Model):
icons[key] = preview
def update_preview(self):
logger.debug('update_preview %s', self.id)
key = 'preview:%s'%self.id
preview = self.extract_preview()
if preview:
@ -416,7 +421,9 @@ class Item(db.Model):
self.info['previewRatio'] = self.info['coverRatio']
elif 'previewRatio' in self.info:
del self.info['previewRatio']
logger.debug('clear preview:%s:', self.id)
icons.clear('preview:%s:' % self.id)
logger.debug('update_preview done %s', self.id)
def update_icons(self):
self.update_cover()
@ -438,7 +445,8 @@ class Item(db.Model):
if 'isbn' in self.meta:
data = meta.lookup('isbn', self.meta['isbn'])
if data:
self.meta.update(data)
for key in data:
self.meta[key] = data[key]
def queue_download(self):
u = state.user()

View file

@ -52,17 +52,23 @@ def remove_missing():
def add_file(id, f, prefix, from_=None):
user = state.user()
path = f[len(prefix):]
logger.debug('extract metadata %s %s', id, path)
data = media.metadata(f, from_)
logger.debug('create file %s %s', id, path)
file = File.get_or_create(id, data, path)
item = file.item
item.add_user(user)
item.added = datetime.utcnow()
logger.debug('load metadata %s %s', id, path)
item.load_metadata()
Changelog.record(user, 'additem', item.id, file.info)
Changelog.record(user, 'edititem', item.id, item.meta)
logger.debug('extract icons %s %s', id, path)
item.update_icons()
item.modified = datetime.utcnow()
logger.debug('save item %s', id)
item.update()
logger.debug('added file %s', id)
return file
def run_scan():
@ -103,8 +109,12 @@ def run_scan():
def run_import(options=None):
options = options or {}
logger.debug('run_import')
if state.activity.get('cancel'):
logger.debug('import canceled')
state.activity = {}
return
state.activity = {}
prefs = settings.preferences
prefix = os.path.expanduser(options.get('path', prefs['importPath']))
if os.path.islink(prefix):
@ -148,6 +158,7 @@ def run_import(options=None):
books.append(f)
count += 1
if state.activity.get('cancel'):
logger.debug('active import canceled')
state.activity = {}
return
if count % 1000 == 0:

View file

@ -29,6 +29,7 @@ class Tasks(Thread):
if m:
try:
action, data = m
logger.debug('run task %s', action)
if action == 'ping':
trigger_event('pong', data)
elif action == 'import':
@ -47,6 +48,7 @@ class Tasks(Thread):
sync_metadata(*data)
else:
trigger_event('error', {'error': 'unknown action'})
logger.debug('finished task %s', action)
except:
logger.debug('task failed', exc_info=1)
self.q.task_done()