Merge remote-tracking branch 'bbb/617'
This commit is contained in:
commit
c582a70498
|
@ -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)
|
||||||
|
@ -540,7 +540,7 @@ class Updater(threading.Thread):
|
||||||
logging.getLogger('cps.web').debug("Could not remove:" + item_path)
|
logging.getLogger('cps.web').debug("Could not remove:" + item_path)
|
||||||
shutil.rmtree(source, ignore_errors=True)
|
shutil.rmtree(source, ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
def check_unrar(unrarLocation):
|
def check_unrar(unrarLocation):
|
||||||
error = False
|
error = False
|
||||||
if os.path.exists(unrarLocation):
|
if os.path.exists(unrarLocation):
|
||||||
|
@ -584,3 +584,39 @@ def get_current_version_info():
|
||||||
if is_sha1(content[0]) and len(content[1]) > 0:
|
if is_sha1(content[0]) and len(content[1]) > 0:
|
||||||
return {'hash': content[0], 'datetime': content[1]}
|
return {'hash': content[0], 'datetime': content[1]}
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def render_task_status(tasklist):
|
||||||
|
#helper function to apply localize status information in tasklist entries
|
||||||
|
renderedtasklist=list()
|
||||||
|
|
||||||
|
for task in tasklist:
|
||||||
|
# localize the task status
|
||||||
|
if isinstance( task['status'], int ):
|
||||||
|
if task['status'] == worker.STAT_WAITING:
|
||||||
|
task['status'] = _('Waiting')
|
||||||
|
elif task['status'] == worker.STAT_FAIL:
|
||||||
|
task['status'] = _('Failed')
|
||||||
|
elif task['status'] == worker.STAT_STARTED:
|
||||||
|
task['status'] = _('Started')
|
||||||
|
elif task['status'] == worker.STAT_FINISH_SUCCESS:
|
||||||
|
task['status'] = _('Finished')
|
||||||
|
else:
|
||||||
|
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)
|
||||||
|
|
||||||
|
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>
|
||||||
|
|
41
cps/web.py
41
cps/web.py
|
@ -54,6 +54,7 @@ import tempfile
|
||||||
from redirect import redirect_back
|
from redirect import redirect_back
|
||||||
import time
|
import time
|
||||||
import server
|
import server
|
||||||
|
import copy
|
||||||
from reverseproxy import ReverseProxied
|
from reverseproxy import ReverseProxied
|
||||||
try:
|
try:
|
||||||
from googleapiclient.errors import HttpError
|
from googleapiclient.errors import HttpError
|
||||||
|
@ -922,6 +923,7 @@ def get_metadata_calibre_companion(uuid):
|
||||||
@login_required
|
@login_required
|
||||||
def get_email_status_json():
|
def get_email_status_json():
|
||||||
answer=list()
|
answer=list()
|
||||||
|
UIanswer = list()
|
||||||
tasks=helper.global_WorkerThread.get_taskstatus()
|
tasks=helper.global_WorkerThread.get_taskstatus()
|
||||||
if not current_user.role_admin():
|
if not current_user.role_admin():
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
|
@ -942,14 +944,18 @@ def get_email_status_json():
|
||||||
if 'starttime' not in task:
|
if 'starttime' not in task:
|
||||||
task['starttime'] = ""
|
task['starttime'] = ""
|
||||||
answer = tasks
|
answer = tasks
|
||||||
js=json.dumps(answer)
|
|
||||||
|
UIanswer = copy.deepcopy(answer)
|
||||||
|
UIanswer = helper.render_task_status(UIanswer)
|
||||||
|
|
||||||
|
js=json.dumps(UIanswer)
|
||||||
response = make_response(js)
|
response = make_response(js)
|
||||||
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
# checks if domain is in database (including wildcards)
|
# checks if domain is in database (including wildcards)
|
||||||
# example SELECT * FROM @TABLE WHERE 'abcdefg' LIKE Name;
|
# example SELECT * FROM @TABLE WHERE 'abcdefg' LIKE Name;
|
||||||
# from https://code.luasoftware.com/tutorials/flask/execute-raw-sql-in-flask-sqlalchemy/
|
# from https://code.luasoftware.com/tutorials/flask/execute-raw-sql-in-flask-sqlalchemy/
|
||||||
def check_valid_domain(domain_text):
|
def check_valid_domain(domain_text):
|
||||||
# result = session.query(Notification).from_statement(text(sql)).params(id=5).all()
|
# result = session.query(Notification).from_statement(text(sql)).params(id=5).all()
|
||||||
|
@ -970,7 +976,7 @@ def check_valid_domain(domain_text):
|
||||||
def edit_domain():
|
def edit_domain():
|
||||||
vals = request.form.to_dict()
|
vals = request.form.to_dict()
|
||||||
answer = ub.session.query(ub.Registration).filter(ub.Registration.id == vals['pk']).first()
|
answer = ub.session.query(ub.Registration).filter(ub.Registration.id == vals['pk']).first()
|
||||||
# domain_name = request.args.get('domain')
|
# domain_name = request.args.get('domain')
|
||||||
answer.domain = vals['value'].replace('*','%').replace('?','_').lower()
|
answer.domain = vals['value'].replace('*','%').replace('?','_').lower()
|
||||||
ub.session.commit()
|
ub.session.commit()
|
||||||
return ""
|
return ""
|
||||||
|
@ -1728,6 +1734,7 @@ def bookmark(book_id, book_format):
|
||||||
def get_tasks_status():
|
def get_tasks_status():
|
||||||
# if current user admin, show all email, otherwise only own emails
|
# if current user admin, show all email, otherwise only own emails
|
||||||
answer=list()
|
answer=list()
|
||||||
|
UIanswer=list()
|
||||||
tasks=helper.global_WorkerThread.get_taskstatus()
|
tasks=helper.global_WorkerThread.get_taskstatus()
|
||||||
if not current_user.role_admin():
|
if not current_user.role_admin():
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
|
@ -1749,8 +1756,10 @@ def get_tasks_status():
|
||||||
task['starttime'] = ""
|
task['starttime'] = ""
|
||||||
answer = tasks
|
answer = tasks
|
||||||
|
|
||||||
|
UIanswer = copy.deepcopy(answer)
|
||||||
|
UIanswer = helper.render_task_status(UIanswer)
|
||||||
# foreach row format row
|
# foreach row format row
|
||||||
return render_title_template('tasks.html', entries=answer, title=_(u"Tasks"))
|
return render_title_template('tasks.html', entries=UIanswer, title=_(u"Tasks"))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/admin")
|
@app.route("/admin")
|
||||||
|
@ -2361,7 +2370,7 @@ def register():
|
||||||
content.nickname = to_save["nickname"]
|
content.nickname = to_save["nickname"]
|
||||||
content.email = to_save["email"]
|
content.email = to_save["email"]
|
||||||
password = helper.generate_random_password()
|
password = helper.generate_random_password()
|
||||||
content.password = generate_password_hash(password)
|
content.password = generate_password_hash(password)
|
||||||
content.role = config.config_default_role
|
content.role = config.config_default_role
|
||||||
content.sidebar_view = config.config_default_show
|
content.sidebar_view = config.config_default_show
|
||||||
try:
|
try:
|
||||||
|
@ -2624,9 +2633,9 @@ def search_to_shelf(shelf_id):
|
||||||
flash(_(u"Books have been added to shelf: %(sname)s", sname=shelf.name), category="success")
|
flash(_(u"Books have been added to shelf: %(sname)s", sname=shelf.name), category="success")
|
||||||
else:
|
else:
|
||||||
flash(_(u"Could not add books to shelf: %(sname)s", sname=shelf.name), category="error")
|
flash(_(u"Could not add books to shelf: %(sname)s", sname=shelf.name), category="error")
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/shelf/remove/<int:shelf_id>/<int:book_id>")
|
@app.route("/shelf/remove/<int:shelf_id>/<int:book_id>")
|
||||||
@login_required
|
@login_required
|
||||||
def remove_from_shelf(shelf_id, book_id):
|
def remove_from_shelf(shelf_id, book_id):
|
||||||
|
@ -2837,7 +2846,7 @@ def profile():
|
||||||
if config.config_public_reg and not check_valid_domain(to_save["email"]):
|
if config.config_public_reg and not check_valid_domain(to_save["email"]):
|
||||||
flash(_(u"E-mail is not from valid domain"), category="error")
|
flash(_(u"E-mail is not from valid domain"), category="error")
|
||||||
return render_title_template("user_edit.html", content=content, downloads=downloads,
|
return render_title_template("user_edit.html", content=content, downloads=downloads,
|
||||||
title=_(u"%(name)s's profile", name=current_user.nickname))
|
title=_(u"%(name)s's profile", name=current_user.nickname))
|
||||||
content.email = to_save["email"]
|
content.email = to_save["email"]
|
||||||
if "show_random" in to_save and to_save["show_random"] == "on":
|
if "show_random" in to_save and to_save["show_random"] == "on":
|
||||||
content.random_books = 1
|
content.random_books = 1
|
||||||
|
@ -3827,7 +3836,7 @@ def upload():
|
||||||
# create the function for sorting...
|
# create the function for sorting...
|
||||||
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
|
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
|
||||||
db.session.connection().connection.connection.create_function('uuid4', 0, lambda: str(uuid4()))
|
db.session.connection().connection.connection.create_function('uuid4', 0, lambda: str(uuid4()))
|
||||||
|
|
||||||
# check if file extension is correct
|
# check if file extension is correct
|
||||||
if '.' in requested_file.filename:
|
if '.' in requested_file.filename:
|
||||||
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
|
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
|
||||||
|
@ -3839,7 +3848,7 @@ def upload():
|
||||||
else:
|
else:
|
||||||
flash(_('File to be uploaded must have an extension'), category="error")
|
flash(_('File to be uploaded must have an extension'), category="error")
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
# extract metadata from file
|
# extract metadata from file
|
||||||
meta = uploader.upload(requested_file)
|
meta = uploader.upload(requested_file)
|
||||||
title = meta.title
|
title = meta.title
|
||||||
|
@ -3883,7 +3892,7 @@ def upload():
|
||||||
else:
|
else:
|
||||||
db_author = db.Authors(authr, helper.get_sorted_author(authr), "")
|
db_author = db.Authors(authr, helper.get_sorted_author(authr), "")
|
||||||
db.session.add(db_author)
|
db.session.add(db_author)
|
||||||
|
|
||||||
# handle series
|
# handle series
|
||||||
db_series = None
|
db_series = None
|
||||||
is_series = db.session.query(db.Series).filter(db.Series.name == series).first()
|
is_series = db.session.query(db.Series).filter(db.Series.name == series).first()
|
||||||
|
@ -3904,7 +3913,7 @@ def upload():
|
||||||
else:
|
else:
|
||||||
db_language = db.Languages(input_language)
|
db_language = db.Languages(input_language)
|
||||||
db.session.add(db_language)
|
db.session.add(db_language)
|
||||||
|
|
||||||
# combine path and normalize path from windows systems
|
# combine path and normalize path from windows systems
|
||||||
path = os.path.join(author_dir, title_dir).replace('\\', '/')
|
path = os.path.join(author_dir, title_dir).replace('\\', '/')
|
||||||
db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 1, 1),
|
db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 1, 1),
|
||||||
|
@ -3916,13 +3925,13 @@ def upload():
|
||||||
db_book.languages.append(db_language)
|
db_book.languages.append(db_language)
|
||||||
file_size = os.path.getsize(saved_filename)
|
file_size = os.path.getsize(saved_filename)
|
||||||
db_data = db.Data(db_book, meta.extension.upper()[1:], file_size, title_dir)
|
db_data = db.Data(db_book, meta.extension.upper()[1:], file_size, title_dir)
|
||||||
|
|
||||||
# handle tags
|
# handle tags
|
||||||
input_tags = tags.split(',')
|
input_tags = tags.split(',')
|
||||||
input_tags = list(map(lambda it: it.strip(), input_tags))
|
input_tags = list(map(lambda it: it.strip(), input_tags))
|
||||||
if input_tags[0] !="":
|
if input_tags[0] !="":
|
||||||
modify_database_object(input_tags, db_book.tags, db.Tags, db.session, 'tags')
|
modify_database_object(input_tags, db_book.tags, db.Tags, db.session, 'tags')
|
||||||
|
|
||||||
# flush content, get db_book.id available
|
# flush content, get db_book.id available
|
||||||
db_book.data.append(db_data)
|
db_book.data.append(db_data)
|
||||||
db.session.add(db_book)
|
db.session.add(db_book)
|
||||||
|
@ -3933,7 +3942,7 @@ def upload():
|
||||||
upload_comment = Markup(meta.description).unescape()
|
upload_comment = Markup(meta.description).unescape()
|
||||||
if upload_comment != "":
|
if upload_comment != "":
|
||||||
db.session.add(db.Comments(upload_comment, book_id))
|
db.session.add(db.Comments(upload_comment, book_id))
|
||||||
|
|
||||||
# save data to database, reread data
|
# save data to database, reread data
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
|
db.session.connection().connection.connection.create_function("title_sort", 1, db.title_sort)
|
||||||
|
@ -3950,7 +3959,7 @@ def upload():
|
||||||
if error:
|
if error:
|
||||||
flash(error, category="error")
|
flash(error, category="error")
|
||||||
uploadText=_(u"File %(file)s uploaded", file=book.title)
|
uploadText=_(u"File %(file)s uploaded", file=book.title)
|
||||||
helper.global_WorkerThread.add_upload(current_user.nickname,
|
helper.global_WorkerThread.add_upload(current_user.nickname,
|
||||||
"<a href=\"" + url_for('show_book', book_id=book.id) + "\">" + uploadText + "</a>")
|
"<a href=\"" + url_for('show_book', book_id=book.id) + "\">" + uploadText + "</a>")
|
||||||
|
|
||||||
# create data for displaying display Full language name instead of iso639.part3language
|
# create data for displaying display Full language name instead of iso639.part3language
|
||||||
|
|
|
@ -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'])
|
||||||
|
@ -212,10 +212,10 @@ class WorkerThread(threading.Thread):
|
||||||
def convert_any_format(self):
|
def convert_any_format(self):
|
||||||
# convert book, and upload in case of google drive
|
# convert book, and upload in case of google drive
|
||||||
self.queue[self.current]['status'] = STAT_STARTED
|
self.queue[self.current]['status'] = STAT_STARTED
|
||||||
self.UIqueue[self.current]['status'] = _('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):
|
||||||
|
@ -232,7 +232,7 @@ class WorkerThread(threading.Thread):
|
||||||
bookid = self.queue[self.current]['bookid']
|
bookid = self.queue[self.current]['bookid']
|
||||||
format_old_ext = u'.' + self.queue[self.current]['settings']['old_book_format'].lower()
|
format_old_ext = u'.' + self.queue[self.current]['settings']['old_book_format'].lower()
|
||||||
format_new_ext = u'.' + self.queue[self.current]['settings']['new_book_format'].lower()
|
format_new_ext = u'.' + self.queue[self.current]['settings']['new_book_format'].lower()
|
||||||
|
|
||||||
# check to see if destination format already exists -
|
# check to see if destination format already exists -
|
||||||
# if it does - mark the conversion task as complete and return a success
|
# if it does - mark the conversion task as complete and return a success
|
||||||
# this will allow send to kindle workflow to continue to work
|
# this will allow send to kindle workflow to continue to work
|
||||||
|
@ -245,12 +245,12 @@ class WorkerThread(threading.Thread):
|
||||||
return file_path + format_new_ext
|
return file_path + format_new_ext
|
||||||
else:
|
else:
|
||||||
web.app.logger.info("Book id %d - target format of %s does not existing. Moving forward with convert.", bookid, format_new_ext)
|
web.app.logger.info("Book id %d - target format of %s does not existing. Moving forward with convert.", bookid, format_new_ext)
|
||||||
|
|
||||||
# check if converter-executable is existing
|
# check if converter-executable is existing
|
||||||
if not os.path.exists(web.ub.config.config_converterpath):
|
if not os.path.exists(web.ub.config.config_converterpath):
|
||||||
self._handleError(_(u"Convertertool %(converter)s not found", converter=web.ub.config.config_converterpath))
|
self._handleError(_(u"Convertertool %(converter)s not found", converter=web.ub.config.config_converterpath))
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# check which converter to use kindlegen is "1"
|
# check which converter to use kindlegen is "1"
|
||||||
if format_old_ext == '.epub' and format_new_ext == '.mobi':
|
if format_old_ext == '.epub' and format_new_ext == '.mobi':
|
||||||
|
@ -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': _('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': _('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()
|
||||||
|
@ -395,7 +395,7 @@ class WorkerThread(threading.Thread):
|
||||||
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']
|
||||||
self.queue[self.current]['status'] = STAT_STARTED
|
self.queue[self.current]['status'] = STAT_STARTED
|
||||||
self.UIqueue[self.current]['status'] = _('Started')
|
self.UIqueue[self.current]['status'] = STAT_STARTED
|
||||||
obj=self.queue[self.current]
|
obj=self.queue[self.current]
|
||||||
# create MIME message
|
# create MIME message
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
|
@ -469,11 +469,11 @@ class WorkerThread(threading.Thread):
|
||||||
if retVal == ' s':
|
if retVal == ' s':
|
||||||
retVal = '0 s'
|
retVal = '0 s'
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def _handleError(self, error_message):
|
def _handleError(self, error_message):
|
||||||
web.app.logger.error(error_message)
|
web.app.logger.error(error_message)
|
||||||
self.queue[self.current]['status'] = STAT_FAIL
|
self.queue[self.current]['status'] = STAT_FAIL
|
||||||
self.UIqueue[self.current]['status'] = _('Failed')
|
self.UIqueue[self.current]['status'] = STAT_FAIL
|
||||||
self.UIqueue[self.current]['progress'] = "100 %"
|
self.UIqueue[self.current]['progress'] = "100 %"
|
||||||
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'])
|
||||||
|
@ -481,7 +481,7 @@ class WorkerThread(threading.Thread):
|
||||||
|
|
||||||
def _handleSuccess(self):
|
def _handleSuccess(self):
|
||||||
self.queue[self.current]['status'] = STAT_FINISH_SUCCESS
|
self.queue[self.current]['status'] = STAT_FINISH_SUCCESS
|
||||||
self.UIqueue[self.current]['status'] = _('Finished')
|
self.UIqueue[self.current]['status'] = STAT_FINISH_SUCCESS
|
||||||
self.UIqueue[self.current]['progress'] = "100 %"
|
self.UIqueue[self.current]['progress'] = "100 %"
|
||||||
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'])
|
||||||
|
@ -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