From 59d56d5c83266cc154c43dde4b3c3fffacc5ed90 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 23 Aug 2020 21:21:55 -0400 Subject: [PATCH] py27 support (I think) and some clean up --- cps/services/worker.py | 46 +++++------------------------------------- cps/tasks/convert.py | 22 +++++++++++--------- cps/tasks/email.py | 2 +- cps/tasks/upload.py | 2 +- 4 files changed, 20 insertions(+), 52 deletions(-) diff --git a/cps/services/worker.py b/cps/services/worker.py index 61a4bae2..7056314c 100644 --- a/cps/services/worker.py +++ b/cps/services/worker.py @@ -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 diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 0039539a..2b6c6db4 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -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 diff --git a/cps/tasks/email.py b/cps/tasks/email.py index be951c6b..3b2db6eb 100644 --- a/cps/tasks/email.py +++ b/cps/tasks/email.py @@ -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 diff --git a/cps/tasks/upload.py b/cps/tasks/upload.py index 5f797c50..ce2cb07b 100644 --- a/cps/tasks/upload.py +++ b/cps/tasks/upload.py @@ -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