Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
59d56d5c
Commit
59d56d5c
authored
Aug 24, 2020
by
blitzmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py27 support (I think) and some clean up
parent
a000de02
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
52 deletions
+20
-52
worker.py
cps/services/worker.py
+5
-41
convert.py
cps/tasks/convert.py
+13
-9
email.py
cps/tasks/email.py
+1
-1
upload.py
cps/tasks/upload.py
+1
-1
No files found.
cps/services/worker.py
View file @
59d56d5c
from
__future__
import
division
,
print_function
,
unicode_literals
from
__future__
import
division
,
print_function
,
unicode_literals
import
sys
import
os
import
re
import
smtplib
import
socket
import
time
import
threading
import
threading
try
:
try
:
import
queue
import
queue
except
ImportError
:
except
ImportError
:
import
Queue
as
queue
import
Queue
as
queue
from
glob
import
glob
from
shutil
import
copyfile
from
datetime
import
datetime
from
datetime
import
datetime
try
:
from
cps
import
calibre_db
from
StringIO
import
StringIO
from
cps
import
logger
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
_
import
abc
import
abc
log
=
logger
.
create
()
log
=
logger
.
create
()
...
@@ -86,9 +59,6 @@ class WorkerThread(threading.Thread):
...
@@ -86,9 +59,6 @@ class WorkerThread(threading.Thread):
self
.
doLock
=
threading
.
Lock
()
self
.
doLock
=
threading
.
Lock
()
self
.
queue
=
ImprovedQueue
()
self
.
queue
=
ImprovedQueue
()
# todo: figure this stuff out and where it should goes
self
.
asyncSMTP
=
None
self
.
start
()
self
.
start
()
@
classmethod
@
classmethod
...
@@ -121,13 +91,6 @@ class WorkerThread(threading.Thread):
...
@@ -121,13 +91,6 @@ class WorkerThread(threading.Thread):
self
.
queue
.
task_done
()
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
):
def
_delete_completed_tasks
(
self
):
raise
NotImplementedError
()
raise
NotImplementedError
()
# for index, task in reversed(list(enumerate(self.UIqueue))):
# for index, task in reversed(list(enumerate(self.UIqueue))):
...
@@ -140,7 +103,8 @@ class WorkerThread(threading.Thread):
...
@@ -140,7 +103,8 @@ class WorkerThread(threading.Thread):
# self.current -= 1
# self.current -= 1
# self.last = len(self.queue)
# self.last = len(self.queue)
class
CalibreTask
(
metaclass
=
abc
.
ABCMeta
):
class
CalibreTask
:
__metaclass__
=
abc
.
ABCMeta
def
__init__
(
self
,
message
):
def
__init__
(
self
,
message
):
self
.
_progress
=
0
self
.
_progress
=
0
...
...
cps/tasks/convert.py
View file @
59d56d5c
...
@@ -14,12 +14,14 @@ from cps import logger, config
...
@@ -14,12 +14,14 @@ from cps import logger, config
from
cps.subproc_wrapper
import
process_open
from
cps.subproc_wrapper
import
process_open
from
flask_babel
import
gettext
as
_
from
flask_babel
import
gettext
as
_
from
cps.tasks.email
import
TaskEmail
from
cps
import
gdriveutils
log
=
logger
.
create
()
log
=
logger
.
create
()
class
TaskConvert
(
CalibreTask
):
class
TaskConvert
(
CalibreTask
):
def
__init__
(
self
,
file_path
,
bookid
,
taskMessage
,
settings
,
kindle_mail
):
def
__init__
(
self
,
file_path
,
bookid
,
taskMessage
,
settings
,
kindle_mail
):
super
()
.
__init__
(
taskMessage
)
super
(
TaskConvert
,
self
)
.
__init__
(
taskMessage
)
self
.
file_path
=
file_path
self
.
file_path
=
file_path
self
.
bookid
=
bookid
self
.
bookid
=
bookid
self
.
settings
=
settings
self
.
settings
=
settings
...
@@ -31,14 +33,16 @@ class TaskConvert(CalibreTask):
...
@@ -31,14 +33,16 @@ class TaskConvert(CalibreTask):
self
.
worker_thread
=
worker_thread
self
.
worker_thread
=
worker_thread
filename
=
self
.
_convert_ebook_format
()
filename
=
self
.
_convert_ebook_format
()
# todo: re-enable this (need to set up gdrive to test with)
# todo: re-enable this (need to set up gdrive to test with)
# if filename:
if
filename
:
# if config.config_use_google_drive:
if
config
.
config_use_google_drive
:
# gdriveutils.updateGdriveCalibreFromLocal()
gdriveutils
.
updateGdriveCalibreFromLocal
()
# if curr_task == TASK_CONVERT:
if
self
.
kindle_mail
:
# self.add_email(self.queue[index]['settings']['subject'], self.queue[index]['path'],
# if we're sending to kindle after converting, create a one-off task and run it immediately
# filename, self.queue[index]['settings'], self.queue[index]['kindle'],
# todo: figure out how to incorporate this into the progress
# self.UIqueue[index]['user'], self.queue[index]['title'],
task
=
TaskEmail
(
self
.
settings
[
'subject'
],
self
.
results
[
"path"
],
# self.queue[index]['settings']['body'], internal=True)
filename
,
self
.
settings
,
self
.
kindle_mail
,
self
.
settings
[
'subject'
],
self
.
settings
[
'body'
],
internal
=
True
)
task
.
start
()
self
.
_handleSuccess
()
self
.
_handleSuccess
()
pass
pass
...
...
cps/tasks/email.py
View file @
59d56d5c
...
@@ -99,7 +99,7 @@ class EmailSSL(EmailBase, smtplib.SMTP_SSL):
...
@@ -99,7 +99,7 @@ class EmailSSL(EmailBase, smtplib.SMTP_SSL):
class
TaskEmail
(
CalibreTask
):
class
TaskEmail
(
CalibreTask
):
def
__init__
(
self
,
subject
,
filepath
,
attachment
,
settings
,
recipient
,
taskMessage
,
text
,
internal
=
False
):
def
__init__
(
self
,
subject
,
filepath
,
attachment
,
settings
,
recipient
,
taskMessage
,
text
,
internal
=
False
):
super
()
.
__init__
(
taskMessage
)
super
(
TaskEmail
,
self
)
.
__init__
(
taskMessage
)
self
.
subject
=
subject
self
.
subject
=
subject
self
.
attachment
=
attachment
self
.
attachment
=
attachment
self
.
settings
=
settings
self
.
settings
=
settings
...
...
cps/tasks/upload.py
View file @
59d56d5c
...
@@ -5,7 +5,7 @@ from cps.services.worker import CalibreTask, STAT_FINISH_SUCCESS
...
@@ -5,7 +5,7 @@ from cps.services.worker import CalibreTask, STAT_FINISH_SUCCESS
class
TaskUpload
(
CalibreTask
):
class
TaskUpload
(
CalibreTask
):
def
__init__
(
self
,
taskMessage
):
def
__init__
(
self
,
taskMessage
):
super
()
.
__init__
(
taskMessage
)
super
(
TaskUpload
,
self
)
.
__init__
(
taskMessage
)
self
.
start_time
=
self
.
end_time
=
datetime
.
now
()
self
.
start_time
=
self
.
end_time
=
datetime
.
now
()
self
.
stat
=
STAT_FINISH_SUCCESS
self
.
stat
=
STAT_FINISH_SUCCESS
self
.
progress
=
1
self
.
progress
=
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment