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
36229076
Commit
36229076
authored
Feb 03, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor subprocess calls
parent
7f340739
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
28 deletions
+71
-28
converter.py
cps/converter.py
+6
-3
helper.py
cps/helper.py
+2
-6
subproc_wrapper.py
cps/subproc_wrapper.py
+42
-0
web.py
cps/web.py
+0
-1
worker.py
cps/worker.py
+21
-18
No files found.
cps/converter.py
View file @
36229076
...
...
@@ -19,17 +19,19 @@
import
os
import
subprocess
#
import subprocess
import
ub
import
re
from
flask_babel
import
gettext
as
_
from
subproc_wrapper
import
process_open
def
versionKindle
():
versions
=
_
(
u'not installed'
)
if
os
.
path
.
exists
(
ub
.
config
.
config_converterpath
):
try
:
p
=
subprocess
.
Popen
(
ub
.
config
.
config_converterpath
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
=
process_open
(
ub
.
config
.
config_converterpath
)
# p = subprocess.Popen(ub.config.config_converterpath, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p
.
wait
()
for
lines
in
p
.
stdout
.
readlines
():
if
isinstance
(
lines
,
bytes
):
...
...
@@ -45,7 +47,8 @@ def versionCalibre():
versions
=
_
(
u'not installed'
)
if
os
.
path
.
exists
(
ub
.
config
.
config_converterpath
):
try
:
p
=
subprocess
.
Popen
([
ub
.
config
.
config_converterpath
,
'--version'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
=
process_open
([
ub
.
config
.
config_converterpath
,
'--version'
])
# p = subprocess.Popen([ub.config.config_converterpath, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p
.
wait
()
for
lines
in
p
.
stdout
.
readlines
():
if
isinstance
(
lines
,
bytes
):
...
...
cps/helper.py
View file @
36229076
...
...
@@ -22,7 +22,6 @@
import
db
import
ub
from
flask
import
current_app
as
app
# import logging
from
tempfile
import
gettempdir
import
sys
import
os
...
...
@@ -36,18 +35,15 @@ from flask_babel import gettext as _
from
flask_login
import
current_user
from
babel.dates
import
format_datetime
from
datetime
import
datetime
# import threading
import
shutil
import
requests
# import zipfile
try
:
import
gdriveutils
as
gd
except
ImportError
:
pass
import
web
# import server
import
random
import
subprocess
from
subproc_wrapper
import
process_open
try
:
import
unidecode
...
...
@@ -496,7 +492,7 @@ def check_unrar(unrarLocation):
try
:
if
sys
.
version_info
<
(
3
,
0
):
unrarLocation
=
unrarLocation
.
encode
(
sys
.
getfilesystemencoding
())
p
=
subprocess
.
Popen
(
unrarLocation
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
=
process_open
(
unrarLocation
)
p
.
wait
()
for
lines
in
p
.
stdout
.
readlines
():
if
isinstance
(
lines
,
bytes
):
...
...
cps/subproc_wrapper.py
0 → 100644
View file @
36229076
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
# Copyright (C) 2018-2019 OzzieIsaacs
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
subprocess
import
os
import
sys
def
process_open
(
command
,
quotes
=
(),
env
=
None
,
sout
=
subprocess
.
PIPE
):
# Linux py2.7 encode as list without quotes no empty element for parameters
# linux py3.x no encode and as list without quotes no empty element for parameters
# windows py2.7 encode as string with quotes empty element for parameters is okay
# windows py 3.x no encode and as string with quotes empty element for parameters is okay
# separate handling for windows and linux
if
os
.
name
==
'nt'
:
for
key
,
element
in
enumerate
(
command
):
if
key
in
quotes
:
command
[
key
]
=
'"'
+
element
+
'"'
exc_command
=
" "
.
join
(
command
)
if
sys
.
version_info
<
(
3
,
0
):
exc_command
=
exc_command
.
encode
(
sys
.
getfilesystemencoding
())
else
:
if
sys
.
version_info
<
(
3
,
0
):
exc_command
=
[
x
.
encode
(
sys
.
getfilesystemencoding
())
for
x
in
command
]
# return subprocess.Popen(exc_command, shell=False, stdout=subprocess.PIPE, universal_newlines=True, env=env)
return
subprocess
.
Popen
(
exc_command
,
shell
=
False
,
stdout
=
sout
,
universal_newlines
=
True
,
env
=
env
)
cps/web.py
View file @
36229076
...
...
@@ -84,7 +84,6 @@ from flask_dance.consumer import oauth_authorized, oauth_error
from
sqlalchemy.orm.exc
import
NoResultFound
from
oauth
import
OAuthBackend
import
hashlib
>>>>>>>
master
try
:
from
googleapiclient.errors
import
HttpError
...
...
cps/worker.py
View file @
36229076
...
...
@@ -31,7 +31,9 @@ import web
from
flask_babel
import
gettext
as
_
import
re
import
gdriveutils
as
gd
import
subprocess
# import subprocess
from
subproc_wrapper
import
process_open
try
:
from
StringIO
import
StringIO
...
...
@@ -271,36 +273,37 @@ class WorkerThread(threading.Thread):
# check which converter to use kindlegen is "1"
if
format_old_ext
==
'.epub'
and
format_new_ext
==
'.mobi'
:
if
web
.
ub
.
config
.
config_ebookconverter
==
1
:
if
os
.
name
==
'nt'
:
'''
if os.name == 'nt':
command = web.ub.config.config_converterpath + u' "' + file_path + u'.epub"'
if sys.version_info < (3, 0):
command = command.encode(sys.getfilesystemencoding())
else
:
command
=
[
web
.
ub
.
config
.
config_converterpath
,
file_path
+
u'.epub'
]
if
sys
.
version_info
<
(
3
,
0
):
command
=
[
x
.
encode
(
sys
.
getfilesystemencoding
())
for
x
in
command
]
else:'''
command
=
[
web
.
ub
.
config
.
config_converterpath
,
file_path
+
u'.epub'
]
quotes
=
(
1
)
if
web
.
ub
.
config
.
config_ebookconverter
==
2
:
# Linux py2.7 encode as list without quotes no empty element for parameters
# linux py3.x no encode and as list without quotes no empty element for parameters
# windows py2.7 encode as string with quotes empty element for parameters is okay
# windows py 3.x no encode and as string with quotes empty element for parameters is okay
# separate handling for windows and linux
if
os
.
name
==
'nt'
:
quotes
=
(
1
,
2
)
'''if os.name == 'nt':
command = web.ub.config.config_converterpath + u' "' + file_path + format_old_ext + u'" "' +
\
file_path + format_new_ext + u'" ' + web.ub.config.config_calibre
if sys.version_info < (3, 0):
command = command.encode(sys.getfilesystemencoding())
else
:
command
=
[
web
.
ub
.
config
.
config_converterpath
,
(
file_path
+
format_old_ext
),
(
file_path
+
format_new_ext
)]
if
web
.
ub
.
config
.
config_calibre
:
parameters
=
web
.
ub
.
config
.
config_calibre
.
split
(
" "
)
for
param
in
parameters
:
command
.
append
(
param
)
if
sys
.
version_info
<
(
3
,
0
):
command
=
[
x
.
encode
(
sys
.
getfilesystemencoding
())
for
x
in
command
]
p
=
subprocess
.
Popen
(
command
,
stdout
=
subprocess
.
PIPE
,
universal_newlines
=
True
)
else:'''
command
=
[
web
.
ub
.
config
.
config_converterpath
,
(
file_path
+
format_old_ext
),
(
file_path
+
format_new_ext
)]
index
=
3
if
web
.
ub
.
config
.
config_calibre
:
parameters
=
web
.
ub
.
config
.
config_calibre
.
split
(
" "
)
for
param
in
parameters
:
command
.
append
(
param
)
quotes
.
append
(
index
)
index
+=
1
p
=
process_open
(
command
,
quotes
)
# p = subprocess.Popen(command, stdout=subprocess.PIPE, universal_newlines=True)
except
OSError
as
e
:
self
.
_handleError
(
_
(
u"Ebook-converter failed:
%(error)
s"
,
error
=
e
))
return
...
...
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