py27 support (I think) and some clean up
This commit is contained in:
parent
a000de0270
commit
59d56d5c83
|
@ -1,42 +1,15 @@
|
|||
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import smtplib
|
||||
import socket
|
||||
import time
|
||||
import threading
|
||||
|
||||
try:
|
||||
import queue
|
||||
except ImportError:
|
||||
import Queue as queue
|
||||
from glob import glob
|
||||
from shutil import copyfile
|
||||
from datetime import datetime
|
||||
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
from email.MIMEBase import MIMEBase
|
||||
from email.MIMEMultipart import MIMEMultipart
|
||||
from email.MIMEText import MIMEText
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
from email.mime.base import MIMEBase
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
from email import encoders
|
||||
from email.utils import formatdate
|
||||
from email.utils import make_msgid
|
||||
from email.generator import Generator
|
||||
from flask_babel import gettext as _
|
||||
|
||||
from cps import calibre_db, db
|
||||
from cps import logger, config
|
||||
from cps.subproc_wrapper import process_open
|
||||
from cps import gdriveutils
|
||||
from flask_babel import gettext as _
|
||||
from cps import calibre_db
|
||||
from cps import logger
|
||||
import abc
|
||||
|
||||
log = logger.create()
|
||||
|
@ -86,9 +59,6 @@ class WorkerThread(threading.Thread):
|
|||
self.doLock = threading.Lock()
|
||||
self.queue = ImprovedQueue()
|
||||
|
||||
# todo: figure this stuff out and where it should goes
|
||||
self.asyncSMTP = None
|
||||
|
||||
self.start()
|
||||
|
||||
@classmethod
|
||||
|
@ -121,13 +91,6 @@ class WorkerThread(threading.Thread):
|
|||
|
||||
self.queue.task_done()
|
||||
|
||||
def get_send_status(self):
|
||||
raise NotImplementedError
|
||||
# if self.asyncSMTP:
|
||||
# return self.asyncSMTP.getTransferStatus()
|
||||
# else:
|
||||
# return "0 %"
|
||||
|
||||
def _delete_completed_tasks(self):
|
||||
raise NotImplementedError()
|
||||
# for index, task in reversed(list(enumerate(self.UIqueue))):
|
||||
|
@ -140,7 +103,8 @@ class WorkerThread(threading.Thread):
|
|||
# self.current -= 1
|
||||
# self.last = len(self.queue)
|
||||
|
||||
class CalibreTask(metaclass=abc.ABCMeta):
|
||||
class CalibreTask:
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
def __init__(self, message):
|
||||
self._progress = 0
|
||||
|
|
|
@ -14,12 +14,14 @@ from cps import logger, config
|
|||
from cps.subproc_wrapper import process_open
|
||||
from flask_babel import gettext as _
|
||||
|
||||
from cps.tasks.email import TaskEmail
|
||||
from cps import gdriveutils
|
||||
log = logger.create()
|
||||
|
||||
|
||||
class TaskConvert(CalibreTask):
|
||||
def __init__(self, file_path, bookid, taskMessage, settings, kindle_mail):
|
||||
super().__init__(taskMessage)
|
||||
super(TaskConvert, self).__init__(taskMessage)
|
||||
self.file_path = file_path
|
||||
self.bookid = bookid
|
||||
self.settings = settings
|
||||
|
@ -31,14 +33,16 @@ class TaskConvert(CalibreTask):
|
|||
self.worker_thread = worker_thread
|
||||
filename = self._convert_ebook_format()
|
||||
# todo: re-enable this (need to set up gdrive to test with)
|
||||
# if filename:
|
||||
# if config.config_use_google_drive:
|
||||
# gdriveutils.updateGdriveCalibreFromLocal()
|
||||
# if curr_task == TASK_CONVERT:
|
||||
# self.add_email(self.queue[index]['settings']['subject'], self.queue[index]['path'],
|
||||
# filename, self.queue[index]['settings'], self.queue[index]['kindle'],
|
||||
# self.UIqueue[index]['user'], self.queue[index]['title'],
|
||||
# self.queue[index]['settings']['body'], internal=True)
|
||||
if filename:
|
||||
if config.config_use_google_drive:
|
||||
gdriveutils.updateGdriveCalibreFromLocal()
|
||||
if self.kindle_mail:
|
||||
# if we're sending to kindle after converting, create a one-off task and run it immediately
|
||||
# todo: figure out how to incorporate this into the progress
|
||||
task = TaskEmail(self.settings['subject'], self.results["path"],
|
||||
filename, self.settings, self.kindle_mail,
|
||||
self.settings['subject'], self.settings['body'], internal=True)
|
||||
task.start()
|
||||
|
||||
self._handleSuccess()
|
||||
pass
|
||||
|
|
|
@ -99,7 +99,7 @@ class EmailSSL(EmailBase, smtplib.SMTP_SSL):
|
|||
|
||||
class TaskEmail(CalibreTask):
|
||||
def __init__(self, subject, filepath, attachment, settings, recipient, taskMessage, text, internal=False):
|
||||
super().__init__(taskMessage)
|
||||
super(TaskEmail, self).__init__(taskMessage)
|
||||
self.subject = subject
|
||||
self.attachment = attachment
|
||||
self.settings = settings
|
||||
|
|
|
@ -5,7 +5,7 @@ from cps.services.worker import CalibreTask, STAT_FINISH_SUCCESS
|
|||
|
||||
class TaskUpload(CalibreTask):
|
||||
def __init__(self, taskMessage):
|
||||
super().__init__(taskMessage)
|
||||
super(TaskUpload, self).__init__(taskMessage)
|
||||
self.start_time = self.end_time = datetime.now()
|
||||
self.stat = STAT_FINISH_SUCCESS
|
||||
self.progress = 1
|
||||
|
|
Loading…
Reference in New Issue
Block a user