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
b4122e98
Commit
b4122e98
authored
Sep 19, 2018
by
bodybybuddha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Partial fix to #617. Local status messages now work.
parent
0bb148e6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
8 deletions
+38
-8
helper.py
cps/helper.py
+21
-0
web.py
cps/web.py
+11
-2
worker.py
cps/worker.py
+6
-6
No files found.
cps/helper.py
View file @
b4122e98
...
@@ -567,3 +567,24 @@ def get_current_version_info():
...
@@ -567,3 +567,24 @@ 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
:
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'
)
renderedtasklist
.
append
(
task
)
return
renderedtasklist
\ No newline at end of file
cps/web.py
View file @
b4122e98
...
@@ -85,6 +85,7 @@ import hashlib
...
@@ -85,6 +85,7 @@ import hashlib
from
redirect
import
redirect_back
from
redirect
import
redirect_back
import
time
import
time
import
server
import
server
import
copy
try
:
try
:
import
cPickle
import
cPickle
except
ImportError
:
except
ImportError
:
...
@@ -873,6 +874,7 @@ def get_metadata_calibre_companion(uuid):
...
@@ -873,6 +874,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
:
...
@@ -893,7 +895,11 @@ def get_email_status_json():
...
@@ -893,7 +895,11 @@ 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
...
@@ -1626,6 +1632,7 @@ def bookmark(book_id, book_format):
...
@@ -1626,6 +1632,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
:
...
@@ -1647,8 +1654,10 @@ def get_tasks_status():
...
@@ -1647,8 +1654,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
=
UI
answer
,
title
=
_
(
u"Tasks"
))
@
app
.
route
(
"/admin"
)
@
app
.
route
(
"/admin"
)
...
...
cps/worker.py
View file @
b4122e98
...
@@ -212,7 +212,7 @@ class WorkerThread(threading.Thread):
...
@@ -212,7 +212,7 @@ 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
][
'typ'
]
...
@@ -352,7 +352,7 @@ class WorkerThread(threading.Thread):
...
@@ -352,7 +352,7 @@ class WorkerThread(threading.Thread):
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
,
'typ'
:
task
,
'settings'
:
settings
})
self
.
UIqueue
.
append
({
'user'
:
user_name
,
'formStarttime'
:
''
,
'progress'
:
" 0
%
"
,
'type'
:
typ
,
self
.
UIqueue
.
append
({
'user'
:
user_name
,
'formStarttime'
:
''
,
'progress'
:
" 0
%
"
,
'type'
:
typ
,
'runtime'
:
'0 s'
,
'status'
:
_
(
'Waiting'
)
,
'id'
:
self
.
id
}
)
'runtime'
:
'0 s'
,
'status'
:
STAT_WAITING
,
'id'
:
self
.
id
}
)
self
.
last
=
len
(
self
.
queue
)
self
.
last
=
len
(
self
.
queue
)
addLock
.
release
()
addLock
.
release
()
...
@@ -371,7 +371,7 @@ class WorkerThread(threading.Thread):
...
@@ -371,7 +371,7 @@ class WorkerThread(threading.Thread):
'settings'
:
settings
,
'recipent'
:
recipient
,
'starttime'
:
0
,
'settings'
:
settings
,
'recipent'
:
recipient
,
'starttime'
:
0
,
'status'
:
STAT_WAITING
,
'typ'
:
TASK_EMAIL
,
'text'
:
text
})
'status'
:
STAT_WAITING
,
'typ'
:
TASK_EMAIL
,
'text'
:
text
})
self
.
UIqueue
.
append
({
'user'
:
user_name
,
'formStarttime'
:
''
,
'progress'
:
" 0
%
"
,
'type'
:
typ
,
self
.
UIqueue
.
append
({
'user'
:
user_name
,
'formStarttime'
:
''
,
'progress'
:
" 0
%
"
,
'type'
:
typ
,
'runtime'
:
'0 s'
,
'status'
:
_
(
'Waiting'
)
,
'id'
:
self
.
id
})
'runtime'
:
'0 s'
,
'status'
:
STAT_WAITING
,
'id'
:
self
.
id
})
self
.
last
=
len
(
self
.
queue
)
self
.
last
=
len
(
self
.
queue
)
addLock
.
release
()
addLock
.
release
()
...
@@ -395,7 +395,7 @@ class WorkerThread(threading.Thread):
...
@@ -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
()
...
@@ -473,7 +473,7 @@ class WorkerThread(threading.Thread):
...
@@ -473,7 +473,7 @@ class WorkerThread(threading.Thread):
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):
...
@@ -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'
])
...
...
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