more logging, reset cancel imort
This commit is contained in:
parent
216fd0c232
commit
cded8b586a
4 changed files with 25 additions and 2 deletions
|
@ -328,6 +328,8 @@ def _import(data):
|
||||||
mode copy|move
|
mode copy|move
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
if 'cancel' in state.activity:
|
||||||
|
del state.activity['cancel']
|
||||||
state.tasks.queue('import', data)
|
state.tasks.queue('import', data)
|
||||||
return {}
|
return {}
|
||||||
actions.register(_import, 'import', cache=False)
|
actions.register(_import, 'import', cache=False)
|
||||||
|
|
|
@ -371,9 +371,11 @@ class Item(db.Model):
|
||||||
break
|
break
|
||||||
|
|
||||||
def update_cover(self):
|
def update_cover(self):
|
||||||
|
logger.debug('update cover %s', self.id)
|
||||||
key = 'cover:%s'%self.id
|
key = 'cover:%s'%self.id
|
||||||
cover = None
|
cover = None
|
||||||
if 'cover' in self.meta and self.meta['cover']:
|
if 'cover' in self.meta and self.meta['cover']:
|
||||||
|
logger.debug('download cover %s %s', self.id, self.meta['cover'])
|
||||||
try:
|
try:
|
||||||
cover = ox.cache.read_url(self.meta['cover'])
|
cover = ox.cache.read_url(self.meta['cover'])
|
||||||
except:
|
except:
|
||||||
|
@ -389,7 +391,9 @@ class Item(db.Model):
|
||||||
self.info['coverRatio'] = self.info['previewRatio']
|
self.info['coverRatio'] = self.info['previewRatio']
|
||||||
elif 'coverRatio' in self.info:
|
elif 'coverRatio' in self.info:
|
||||||
del self.info['coverRatio']
|
del self.info['coverRatio']
|
||||||
|
logger.debug('clear cover:%s:', self.id)
|
||||||
icons.clear('cover:%s:' % self.id)
|
icons.clear('cover:%s:' % self.id)
|
||||||
|
logger.debug('update_cover done')
|
||||||
|
|
||||||
def get_preview(self):
|
def get_preview(self):
|
||||||
key = 'preview:%s'%self.id
|
key = 'preview:%s'%self.id
|
||||||
|
@ -400,6 +404,7 @@ class Item(db.Model):
|
||||||
icons[key] = preview
|
icons[key] = preview
|
||||||
|
|
||||||
def update_preview(self):
|
def update_preview(self):
|
||||||
|
logger.debug('update_preview %s', self.id)
|
||||||
key = 'preview:%s'%self.id
|
key = 'preview:%s'%self.id
|
||||||
preview = self.extract_preview()
|
preview = self.extract_preview()
|
||||||
if preview:
|
if preview:
|
||||||
|
@ -416,7 +421,9 @@ class Item(db.Model):
|
||||||
self.info['previewRatio'] = self.info['coverRatio']
|
self.info['previewRatio'] = self.info['coverRatio']
|
||||||
elif 'previewRatio' in self.info:
|
elif 'previewRatio' in self.info:
|
||||||
del self.info['previewRatio']
|
del self.info['previewRatio']
|
||||||
|
logger.debug('clear preview:%s:', self.id)
|
||||||
icons.clear('preview:%s:' % self.id)
|
icons.clear('preview:%s:' % self.id)
|
||||||
|
logger.debug('update_preview done %s', self.id)
|
||||||
|
|
||||||
def update_icons(self):
|
def update_icons(self):
|
||||||
self.update_cover()
|
self.update_cover()
|
||||||
|
@ -438,7 +445,8 @@ class Item(db.Model):
|
||||||
if 'isbn' in self.meta:
|
if 'isbn' in self.meta:
|
||||||
data = meta.lookup('isbn', self.meta['isbn'])
|
data = meta.lookup('isbn', self.meta['isbn'])
|
||||||
if data:
|
if data:
|
||||||
self.meta.update(data)
|
for key in data:
|
||||||
|
self.meta[key] = data[key]
|
||||||
|
|
||||||
def queue_download(self):
|
def queue_download(self):
|
||||||
u = state.user()
|
u = state.user()
|
||||||
|
|
|
@ -52,17 +52,23 @@ def remove_missing():
|
||||||
def add_file(id, f, prefix, from_=None):
|
def add_file(id, f, prefix, from_=None):
|
||||||
user = state.user()
|
user = state.user()
|
||||||
path = f[len(prefix):]
|
path = f[len(prefix):]
|
||||||
|
logger.debug('extract metadata %s %s', id, path)
|
||||||
data = media.metadata(f, from_)
|
data = media.metadata(f, from_)
|
||||||
|
logger.debug('create file %s %s', id, path)
|
||||||
file = File.get_or_create(id, data, path)
|
file = File.get_or_create(id, data, path)
|
||||||
item = file.item
|
item = file.item
|
||||||
item.add_user(user)
|
item.add_user(user)
|
||||||
item.added = datetime.utcnow()
|
item.added = datetime.utcnow()
|
||||||
|
logger.debug('load metadata %s %s', id, path)
|
||||||
item.load_metadata()
|
item.load_metadata()
|
||||||
Changelog.record(user, 'additem', item.id, file.info)
|
Changelog.record(user, 'additem', item.id, file.info)
|
||||||
Changelog.record(user, 'edititem', item.id, item.meta)
|
Changelog.record(user, 'edititem', item.id, item.meta)
|
||||||
|
logger.debug('extract icons %s %s', id, path)
|
||||||
item.update_icons()
|
item.update_icons()
|
||||||
item.modified = datetime.utcnow()
|
item.modified = datetime.utcnow()
|
||||||
|
logger.debug('save item %s', id)
|
||||||
item.update()
|
item.update()
|
||||||
|
logger.debug('added file %s', id)
|
||||||
return file
|
return file
|
||||||
|
|
||||||
def run_scan():
|
def run_scan():
|
||||||
|
@ -103,8 +109,12 @@ def run_scan():
|
||||||
|
|
||||||
def run_import(options=None):
|
def run_import(options=None):
|
||||||
options = options or {}
|
options = options or {}
|
||||||
|
|
||||||
logger.debug('run_import')
|
logger.debug('run_import')
|
||||||
|
if state.activity.get('cancel'):
|
||||||
|
logger.debug('import canceled')
|
||||||
|
state.activity = {}
|
||||||
|
return
|
||||||
|
state.activity = {}
|
||||||
prefs = settings.preferences
|
prefs = settings.preferences
|
||||||
prefix = os.path.expanduser(options.get('path', prefs['importPath']))
|
prefix = os.path.expanduser(options.get('path', prefs['importPath']))
|
||||||
if os.path.islink(prefix):
|
if os.path.islink(prefix):
|
||||||
|
@ -148,6 +158,7 @@ def run_import(options=None):
|
||||||
books.append(f)
|
books.append(f)
|
||||||
count += 1
|
count += 1
|
||||||
if state.activity.get('cancel'):
|
if state.activity.get('cancel'):
|
||||||
|
logger.debug('active import canceled')
|
||||||
state.activity = {}
|
state.activity = {}
|
||||||
return
|
return
|
||||||
if count % 1000 == 0:
|
if count % 1000 == 0:
|
||||||
|
|
|
@ -29,6 +29,7 @@ class Tasks(Thread):
|
||||||
if m:
|
if m:
|
||||||
try:
|
try:
|
||||||
action, data = m
|
action, data = m
|
||||||
|
logger.debug('run task %s', action)
|
||||||
if action == 'ping':
|
if action == 'ping':
|
||||||
trigger_event('pong', data)
|
trigger_event('pong', data)
|
||||||
elif action == 'import':
|
elif action == 'import':
|
||||||
|
@ -47,6 +48,7 @@ class Tasks(Thread):
|
||||||
sync_metadata(*data)
|
sync_metadata(*data)
|
||||||
else:
|
else:
|
||||||
trigger_event('error', {'error': 'unknown action'})
|
trigger_event('error', {'error': 'unknown action'})
|
||||||
|
logger.debug('finished task %s', action)
|
||||||
except:
|
except:
|
||||||
logger.debug('task failed', exc_info=1)
|
logger.debug('task failed', exc_info=1)
|
||||||
self.q.task_done()
|
self.q.task_done()
|
||||||
|
|
Loading…
Reference in a new issue