Fix for #617
Task table: Status column and task messages have been localized Cleaned up the use of the task fields 'typ' and 'type' to be taskType and taskMessage
This commit is contained in:
parent
54f8680058
commit
ee686b5379
|
@ -73,10 +73,10 @@ def convert_book_format(book_id, calibrepath, old_book_format, new_book_format,
|
||||||
# read settings and append converter task to queue
|
# read settings and append converter task to queue
|
||||||
if kindle_mail:
|
if kindle_mail:
|
||||||
settings = ub.get_mail_settings()
|
settings = ub.get_mail_settings()
|
||||||
text = _(u"Convert: %(book)s" , book=book.title)
|
text = _(u"%(format)s: %(book)s", format=new_book_format, book=book.title)
|
||||||
else:
|
else:
|
||||||
settings = dict()
|
settings = dict()
|
||||||
text = _(u"Convert to %(format)s: %(book)s", format=new_book_format, book=book.title)
|
text = _(u"%(format)s: %(book)s", format=new_book_format, book=book.title)
|
||||||
settings['old_book_format'] = old_book_format
|
settings['old_book_format'] = old_book_format
|
||||||
settings['new_book_format'] = new_book_format
|
settings['new_book_format'] = new_book_format
|
||||||
global_WorkerThread.add_convert(file_path, book.id, user_id, text, settings, kindle_mail)
|
global_WorkerThread.add_convert(file_path, book.id, user_id, text, settings, kindle_mail)
|
||||||
|
@ -568,11 +568,13 @@ def get_current_version_info():
|
||||||
return {'hash': content[0], 'datetime': content[1]}
|
return {'hash': content[0], 'datetime': content[1]}
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def render_task_status(tasklist):
|
def render_task_status(tasklist):
|
||||||
#helper function to apply localize status information in tasklist entries
|
#helper function to apply localize status information in tasklist entries
|
||||||
renderedtasklist=list()
|
renderedtasklist=list()
|
||||||
|
|
||||||
for task in tasklist:
|
for task in tasklist:
|
||||||
|
# localize the task status
|
||||||
if isinstance( task['status'], int ):
|
if isinstance( task['status'], int ):
|
||||||
if task['status'] == worker.STAT_WAITING:
|
if task['status'] == worker.STAT_WAITING:
|
||||||
task['status'] = _('Waiting')
|
task['status'] = _('Waiting')
|
||||||
|
@ -584,7 +586,20 @@ def render_task_status(tasklist):
|
||||||
task['status'] = _('Finished')
|
task['status'] = _('Finished')
|
||||||
else:
|
else:
|
||||||
task['status'] = _('Unknown Status')
|
task['status'] = _('Unknown Status')
|
||||||
|
|
||||||
|
# localize the task type
|
||||||
|
if isinstance( task['taskType'], int ):
|
||||||
|
if task['taskType'] == worker.TASK_EMAIL:
|
||||||
|
task['taskMessage'] = _('EMAIL: ') + task['taskMessage']
|
||||||
|
elif task['taskType'] == worker.TASK_CONVERT:
|
||||||
|
task['taskMessage'] = _('CONVERT: ') + task['taskMessage']
|
||||||
|
elif task['taskType'] == worker.TASK_UPLOAD:
|
||||||
|
task['taskMessage'] = _('UPLOAD: ') + task['taskMessage']
|
||||||
|
elif task['taskType'] == worker.TASK_CONVERT_ANY:
|
||||||
|
task['taskMessage'] = _('CONVERT: ') + task['taskMessage']
|
||||||
|
else:
|
||||||
|
task['taskMessage'] = _('Unknown Task: ') + task['taskMessage']
|
||||||
|
|
||||||
renderedtasklist.append(task)
|
renderedtasklist.append(task)
|
||||||
|
|
||||||
return renderedtasklist
|
return renderedtasklist
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
{% if g.user.role_admin() %}
|
{% if g.user.role_admin() %}
|
||||||
<th data-halign="right" data-align="right" data-field="user" data-sortable="true">{{_('User')}}</th>
|
<th data-halign="right" data-align="right" data-field="user" data-sortable="true">{{_('User')}}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<th data-halign="right" data-align="right" data-field="type" data-sortable="true">{{_('Task')}}</th>
|
<th data-halign="right" data-align="right" data-field="taskMessage" data-sortable="true">{{_('Task')}}</th>
|
||||||
<th data-halign="right" data-align="right" data-field="status" data-sortable="true">{{_('Status')}}</th>
|
<th data-halign="right" data-align="right" data-field="status" data-sortable="true">{{_('Status')}}</th>
|
||||||
<th data-halign="right" data-align="right" data-field="progress" data-sortable="true" data-sorter="elementSorter">{{_('Progress')}}</th>
|
<th data-halign="right" data-align="right" data-field="progress" data-sortable="true" data-sorter="elementSorter">{{_('Progress')}}</th>
|
||||||
<th data-halign="right" data-align="right" data-field="runtime" data-sortable="true" data-sort-name="rt">{{_('Runtime')}}</th>
|
<th data-halign="right" data-align="right" data-field="runtime" data-sortable="true" data-sort-name="rt">{{_('Runtime')}}</th>
|
||||||
|
|
|
@ -33,12 +33,12 @@ from email.utils import formatdate
|
||||||
from email.utils import make_msgid
|
from email.utils import make_msgid
|
||||||
|
|
||||||
chunksize = 8192
|
chunksize = 8192
|
||||||
|
# task 'status' consts
|
||||||
STAT_WAITING = 0
|
STAT_WAITING = 0
|
||||||
STAT_FAIL = 1
|
STAT_FAIL = 1
|
||||||
STAT_STARTED = 2
|
STAT_STARTED = 2
|
||||||
STAT_FINISH_SUCCESS = 3
|
STAT_FINISH_SUCCESS = 3
|
||||||
|
#taskType consts
|
||||||
TASK_EMAIL = 1
|
TASK_EMAIL = 1
|
||||||
TASK_CONVERT = 2
|
TASK_CONVERT = 2
|
||||||
TASK_UPLOAD = 3
|
TASK_UPLOAD = 3
|
||||||
|
@ -169,11 +169,11 @@ class WorkerThread(threading.Thread):
|
||||||
doLock.acquire()
|
doLock.acquire()
|
||||||
if self.current != self.last:
|
if self.current != self.last:
|
||||||
doLock.release()
|
doLock.release()
|
||||||
if self.queue[self.current]['typ'] == TASK_EMAIL:
|
if self.queue[self.current]['taskType'] == TASK_EMAIL:
|
||||||
self.send_raw_email()
|
self.send_raw_email()
|
||||||
if self.queue[self.current]['typ'] == TASK_CONVERT:
|
if self.queue[self.current]['taskType'] == TASK_CONVERT:
|
||||||
self.convert_any_format()
|
self.convert_any_format()
|
||||||
if self.queue[self.current]['typ'] == TASK_CONVERT_ANY:
|
if self.queue[self.current]['taskType'] == TASK_CONVERT_ANY:
|
||||||
self.convert_any_format()
|
self.convert_any_format()
|
||||||
# TASK_UPLOAD is handled implicitly
|
# TASK_UPLOAD is handled implicitly
|
||||||
self.current += 1
|
self.current += 1
|
||||||
|
@ -203,7 +203,7 @@ class WorkerThread(threading.Thread):
|
||||||
def get_taskstatus(self):
|
def get_taskstatus(self):
|
||||||
if self.current < len(self.queue):
|
if self.current < len(self.queue):
|
||||||
if self.queue[self.current]['status'] == STAT_STARTED:
|
if self.queue[self.current]['status'] == STAT_STARTED:
|
||||||
if self.queue[self.current]['typ'] == TASK_EMAIL:
|
if self.queue[self.current]['taskType'] == TASK_EMAIL:
|
||||||
self.UIqueue[self.current]['progress'] = self.get_send_status()
|
self.UIqueue[self.current]['progress'] = self.get_send_status()
|
||||||
self.UIqueue[self.current]['runtime'] = self._formatRuntime(
|
self.UIqueue[self.current]['runtime'] = self._formatRuntime(
|
||||||
datetime.now() - self.queue[self.current]['starttime'])
|
datetime.now() - self.queue[self.current]['starttime'])
|
||||||
|
@ -215,7 +215,7 @@ class WorkerThread(threading.Thread):
|
||||||
self.UIqueue[self.current]['status'] = STAT_STARTED
|
self.UIqueue[self.current]['status'] = STAT_STARTED
|
||||||
self.queue[self.current]['starttime'] = datetime.now()
|
self.queue[self.current]['starttime'] = datetime.now()
|
||||||
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
|
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
|
||||||
curr_task = self.queue[self.current]['typ']
|
curr_task = self.queue[self.current]['taskType']
|
||||||
filename = self.convert_ebook_format()
|
filename = self.convert_ebook_format()
|
||||||
if filename:
|
if filename:
|
||||||
if web.ub.config.config_use_google_drive:
|
if web.ub.config.config_use_google_drive:
|
||||||
|
@ -223,7 +223,7 @@ class WorkerThread(threading.Thread):
|
||||||
if curr_task == TASK_CONVERT:
|
if curr_task == TASK_CONVERT:
|
||||||
self.add_email(_(u'Send to Kindle'), self.queue[self.current]['path'], filename,
|
self.add_email(_(u'Send to Kindle'), self.queue[self.current]['path'], filename,
|
||||||
self.queue[self.current]['settings'], self.queue[self.current]['kindle'],
|
self.queue[self.current]['settings'], self.queue[self.current]['kindle'],
|
||||||
self.UIqueue[self.current]['user'], _(u"E-mail: %(book)s", book=self.queue[self.current]['title']))
|
self.UIqueue[self.current]['user'], _(u"%(book)s", book=self.queue[self.current]['title']))
|
||||||
|
|
||||||
|
|
||||||
def convert_ebook_format(self):
|
def convert_ebook_format(self):
|
||||||
|
@ -339,7 +339,7 @@ class WorkerThread(threading.Thread):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def add_convert(self, file_path, bookid, user_name, typ, settings, kindle_mail=None):
|
def add_convert(self, file_path, bookid, user_name, taskMessage, settings, kindle_mail=None):
|
||||||
addLock = threading.Lock()
|
addLock = threading.Lock()
|
||||||
addLock.acquire()
|
addLock.acquire()
|
||||||
if self.last >= 20:
|
if self.last >= 20:
|
||||||
|
@ -350,15 +350,15 @@ class WorkerThread(threading.Thread):
|
||||||
if kindle_mail:
|
if kindle_mail:
|
||||||
task = TASK_CONVERT
|
task = TASK_CONVERT
|
||||||
self.queue.append({'file_path':file_path, 'bookid':bookid, 'starttime': 0, 'kindle': kindle_mail,
|
self.queue.append({'file_path':file_path, 'bookid':bookid, 'starttime': 0, 'kindle': kindle_mail,
|
||||||
'status': STAT_WAITING, 'typ': task, 'settings':settings})
|
'status': STAT_WAITING, 'taskType': task, 'settings':settings})
|
||||||
self.UIqueue.append({'user': user_name, 'formStarttime': '', 'progress': " 0 %", 'type': typ,
|
self.UIqueue.append({'user': user_name, 'formStarttime': '', 'progress': " 0 %", 'taskMessage': taskMessage,
|
||||||
'runtime': '0 s', 'status': STAT_WAITING,'id': self.id } )
|
'runtime': '0 s', 'status': STAT_WAITING,'id': self.id, 'taskType': task } )
|
||||||
|
|
||||||
self.last=len(self.queue)
|
self.last=len(self.queue)
|
||||||
addLock.release()
|
addLock.release()
|
||||||
|
|
||||||
|
|
||||||
def add_email(self, subject, filepath, attachment, settings, recipient, user_name, typ,
|
def add_email(self, subject, filepath, attachment, settings, recipient, user_name, taskMessage,
|
||||||
text=_(u'This e-mail has been sent via Calibre-Web.')):
|
text=_(u'This e-mail has been sent via Calibre-Web.')):
|
||||||
# if more than 20 entries in the list, clean the list
|
# if more than 20 entries in the list, clean the list
|
||||||
addLock = threading.Lock()
|
addLock = threading.Lock()
|
||||||
|
@ -369,13 +369,13 @@ class WorkerThread(threading.Thread):
|
||||||
self.id += 1
|
self.id += 1
|
||||||
self.queue.append({'subject':subject, 'attachment':attachment, 'filepath':filepath,
|
self.queue.append({'subject':subject, 'attachment':attachment, 'filepath':filepath,
|
||||||
'settings':settings, 'recipent':recipient, 'starttime': 0,
|
'settings':settings, 'recipent':recipient, 'starttime': 0,
|
||||||
'status': STAT_WAITING, 'typ': TASK_EMAIL, 'text':text})
|
'status': STAT_WAITING, 'taskType': TASK_EMAIL, 'text':text})
|
||||||
self.UIqueue.append({'user': user_name, 'formStarttime': '', 'progress': " 0 %", 'type': typ,
|
self.UIqueue.append({'user': user_name, 'formStarttime': '', 'progress': " 0 %", 'taskMessage': taskMessage,
|
||||||
'runtime': '0 s', 'status': STAT_WAITING,'id': self.id })
|
'runtime': '0 s', 'status': STAT_WAITING,'id': self.id, 'taskType': TASK_EMAIL })
|
||||||
self.last=len(self.queue)
|
self.last=len(self.queue)
|
||||||
addLock.release()
|
addLock.release()
|
||||||
|
|
||||||
def add_upload(self, user_name, typ):
|
def add_upload(self, user_name, taskMessage):
|
||||||
# if more than 20 entries in the list, clean the list
|
# if more than 20 entries in the list, clean the list
|
||||||
addLock = threading.Lock()
|
addLock = threading.Lock()
|
||||||
addLock.acquire()
|
addLock.acquire()
|
||||||
|
@ -383,9 +383,9 @@ class WorkerThread(threading.Thread):
|
||||||
self.delete_completed_tasks()
|
self.delete_completed_tasks()
|
||||||
# progress=100%, runtime=0, and status finished
|
# progress=100%, runtime=0, and status finished
|
||||||
self.id += 1
|
self.id += 1
|
||||||
self.queue.append({'starttime': datetime.now(), 'status': STAT_FINISH_SUCCESS, 'typ': TASK_UPLOAD})
|
self.queue.append({'starttime': datetime.now(), 'status': STAT_FINISH_SUCCESS, 'taskType': TASK_UPLOAD})
|
||||||
self.UIqueue.append({'user': user_name, 'formStarttime': '', 'progress': "100 %", 'type': typ,
|
self.UIqueue.append({'user': user_name, 'formStarttime': '', 'progress': "100 %", 'taskMessage': taskMessage,
|
||||||
'runtime': '0 s', 'status': _('Finished'),'id': self.id })
|
'runtime': '0 s', 'status': _('Finished'),'id': self.id, 'taskType': TASK_UPLOAD})
|
||||||
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
|
self.UIqueue[self.current]['formStarttime'] = self.queue[self.current]['starttime']
|
||||||
self.last=len(self.queue)
|
self.last=len(self.queue)
|
||||||
addLock.release()
|
addLock.release()
|
||||||
|
@ -502,3 +502,4 @@ class StderrLogger(object):
|
||||||
self.buffer = ''
|
self.buffer = ''
|
||||||
else:
|
else:
|
||||||
self.buffer += message
|
self.buffer += message
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user