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
41960ada
Commit
41960ada
authored
May 09, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Autodetect binaries
parent
0a02caad
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
18 deletions
+59
-18
config_sql.py
cps/config_sql.py
+38
-10
editbooks.py
cps/editbooks.py
+16
-8
ub.py
cps/ub.py
+5
-0
No files found.
cps/config_sql.py
View file @
41960ada
...
@@ -117,17 +117,12 @@ class _Settings(_Base):
...
@@ -117,17 +117,12 @@ class _Settings(_Base):
config_ldap_group_members_field
=
Column
(
String
,
default
=
'memberUid'
)
config_ldap_group_members_field
=
Column
(
String
,
default
=
'memberUid'
)
config_ldap_group_name
=
Column
(
String
,
default
=
'calibreweb'
)
config_ldap_group_name
=
Column
(
String
,
default
=
'calibreweb'
)
# config_ebookconverter = Column(Integer, default=0)
config_kepubifypath
=
Column
(
String
,
default
=
None
)
config_kepubifypath
=
Column
(
String
)
config_converterpath
=
Column
(
String
,
default
=
None
)
config_converterpath
=
Column
(
String
)
config_calibre
=
Column
(
String
)
config_calibre
=
Column
(
String
)
config_rarfile_location
=
Column
(
String
)
config_rarfile_location
=
Column
(
String
,
default
=
None
)
config_upload_formats
=
Column
(
String
,
default
=
','
.
join
(
constants
.
EXTENSIONS_UPLOAD
))
config_upload_formats
=
Column
(
String
,
default
=
','
.
join
(
constants
.
EXTENSIONS_UPLOAD
))
config_automatic_kepub
=
Column
(
Boolean
,
default
=
False
)
config_kepubify_path
=
Column
(
String
)
config_kepub_cache_dir
=
Column
(
String
)
config_updatechannel
=
Column
(
Integer
,
default
=
constants
.
UPDATE_STABLE
)
config_updatechannel
=
Column
(
Integer
,
default
=
constants
.
UPDATE_STABLE
)
config_reverse_proxy_login_header_name
=
Column
(
String
)
config_reverse_proxy_login_header_name
=
Column
(
String
)
...
@@ -271,7 +266,8 @@ class _ConfigSQL(object):
...
@@ -271,7 +266,8 @@ class _ConfigSQL(object):
setattr
(
self
,
k
,
v
)
setattr
(
self
,
k
,
v
)
if
self
.
config_google_drive_watch_changes_response
:
if
self
.
config_google_drive_watch_changes_response
:
self
.
config_google_drive_watch_changes_response
=
json
.
loads
(
self
.
config_google_drive_watch_changes_response
)
self
.
config_google_drive_watch_changes_response
=
\
json
.
loads
(
self
.
config_google_drive_watch_changes_response
)
have_metadata_db
=
bool
(
self
.
config_calibre_dir
)
have_metadata_db
=
bool
(
self
.
config_calibre_dir
)
if
have_metadata_db
:
if
have_metadata_db
:
...
@@ -280,6 +276,16 @@ class _ConfigSQL(object):
...
@@ -280,6 +276,16 @@ class _ConfigSQL(object):
have_metadata_db
=
os
.
path
.
isfile
(
db_file
)
have_metadata_db
=
os
.
path
.
isfile
(
db_file
)
self
.
db_configured
=
have_metadata_db
self
.
db_configured
=
have_metadata_db
if
self
.
config_converterpath
==
None
:
self
.
config_converterpath
=
autodetect_calibre_binary
()
if
self
.
config_kepubifypath
==
None
:
self
.
config_kepubifypath
=
autodetect_kepubify_binary
()
if
self
.
config_rarfile_location
==
None
:
self
.
config_rarfile_location
=
autodetect_unrar_binary
()
logger
.
setup
(
self
.
config_logfile
,
self
.
config_log_level
)
logger
.
setup
(
self
.
config_logfile
,
self
.
config_log_level
)
def
save
(
self
):
def
save
(
self
):
...
@@ -337,6 +343,7 @@ def _migrate_table(session, orm_class):
...
@@ -337,6 +343,7 @@ def _migrate_table(session, orm_class):
if
changed
:
if
changed
:
session
.
commit
()
session
.
commit
()
def
autodetect_calibre_binary
():
def
autodetect_calibre_binary
():
if
sys
.
platform
==
"win32"
:
if
sys
.
platform
==
"win32"
:
calibre_path
=
[
"C:
\\
program files
\
calibre
\
calibre-convert.exe"
,
calibre_path
=
[
"C:
\\
program files
\
calibre
\
calibre-convert.exe"
,
...
@@ -346,8 +353,29 @@ def autodetect_calibre_binary():
...
@@ -346,8 +353,29 @@ def autodetect_calibre_binary():
for
element
in
calibre_path
:
for
element
in
calibre_path
:
if
os
.
path
.
isfile
(
element
)
and
os
.
access
(
element
,
os
.
X_OK
):
if
os
.
path
.
isfile
(
element
)
and
os
.
access
(
element
,
os
.
X_OK
):
return
element
return
element
return
None
return
""
def
autodetect_unrar_binary
():
if
sys
.
platform
==
"win32"
:
calibre_path
=
[
"C:
\\
program files
\\
WinRar
\\
unRAR.exe"
,
"C:
\\
program files(x86)
\\
WinRar
\\
unRAR.exe"
]
else
:
calibre_path
=
[
"/usr/bin/unrar"
]
for
element
in
calibre_path
:
if
os
.
path
.
isfile
(
element
)
and
os
.
access
(
element
,
os
.
X_OK
):
return
element
return
""
def
autodetect_kepubify_binary
():
if
sys
.
platform
==
"win32"
:
calibre_path
=
[
"C:
\\
program files
\\
kepubify
\\
kepubify-windows-64Bit.exe"
,
"C:
\\
program files(x86)
\\
kepubify
\\
kepubify-windows-64Bit.exe"
]
else
:
calibre_path
=
[
"/opt/kepubify/kepubify-linux-64bit"
,
"/opt/kepubify/kepubify-linux-32bit"
]
for
element
in
calibre_path
:
if
os
.
path
.
isfile
(
element
)
and
os
.
access
(
element
,
os
.
X_OK
):
return
element
return
""
def
_migrate_database
(
session
):
def
_migrate_database
(
session
):
# make sure the table is created, if it does not exist
# make sure the table is created, if it does not exist
...
...
cps/editbooks.py
View file @
41960ada
...
@@ -24,7 +24,7 @@ from __future__ import division, print_function, unicode_literals
...
@@ -24,7 +24,7 @@ from __future__ import division, print_function, unicode_literals
import
os
import
os
from
datetime
import
datetime
from
datetime
import
datetime
import
json
import
json
from
shutil
import
move
,
copyfile
from
shutil
import
copyfile
from
uuid
import
uuid4
from
uuid
import
uuid4
from
flask
import
Blueprint
,
request
,
flash
,
redirect
,
url_for
,
abort
,
Markup
,
Response
from
flask
import
Blueprint
,
request
,
flash
,
redirect
,
url_for
,
abort
,
Markup
,
Response
...
@@ -267,19 +267,27 @@ def render_edit_book(book_id):
...
@@ -267,19 +267,27 @@ def render_edit_book(book_id):
# Option for showing convertbook button
# Option for showing convertbook button
valid_source_formats
=
list
()
valid_source_formats
=
list
()
allowed_conversion_formats
=
list
()
kepub_possible
=
None
if
config
.
config_converterpath
:
if
config
.
config_converterpath
:
for
file
in
book
.
data
:
for
file
in
book
.
data
:
if
file
.
format
.
lower
()
in
constants
.
EXTENSIONS_CONVERT
:
if
file
.
format
.
lower
()
in
constants
.
EXTENSIONS_CONVERT
:
valid_source_formats
.
append
(
file
.
format
.
lower
())
valid_source_formats
.
append
(
file
.
format
.
lower
())
if
config
.
config_kepubifypath
and
'epub'
in
[
file
.
format
.
lower
()
for
file
in
book
.
data
]:
kepub_possible
=
True
if
not
config
.
config_converterpath
:
valid_source_formats
.
append
(
'epub'
)
# Determine what formats don't already exist
# Determine what formats don't already exist
allowed_conversion_formats
=
constants
.
EXTENSIONS_CONVERT
.
copy
()
if
config
.
config_converterpath
:
for
file
in
book
.
data
:
allowed_conversion_formats
=
constants
.
EXTENSIONS_CONVERT
.
copy
()
try
:
for
file
in
book
.
data
:
allowed_conversion_formats
.
remove
(
file
.
format
.
lower
())
try
:
except
Exception
:
allowed_conversion_formats
.
remove
(
file
.
format
.
lower
())
log
.
warning
(
'
%
s already removed from list.'
,
file
.
format
.
lower
())
except
Exception
:
log
.
warning
(
'
%
s already removed from list.'
,
file
.
format
.
lower
())
if
kepub_possible
:
allowed_conversion_formats
.
append
(
'kepub'
)
return
render_title_template
(
'book_edit.html'
,
book
=
book
,
authors
=
author_names
,
cc
=
cc
,
return
render_title_template
(
'book_edit.html'
,
book
=
book
,
authors
=
author_names
,
cc
=
cc
,
title
=
_
(
u"edit metadata"
),
page
=
"editbook"
,
title
=
_
(
u"edit metadata"
),
page
=
"editbook"
,
conversion_formats
=
allowed_conversion_formats
,
conversion_formats
=
allowed_conversion_formats
,
...
...
cps/ub.py
View file @
41960ada
...
@@ -107,6 +107,11 @@ def get_sidebar_config(kwargs=None):
...
@@ -107,6 +107,11 @@ def get_sidebar_config(kwargs=None):
{
"glyph"
:
"glyphicon-trash"
,
"text"
:
_
(
'Archived Books'
),
"link"
:
'web.books_list'
,
"id"
:
"archived"
,
{
"glyph"
:
"glyphicon-trash"
,
"text"
:
_
(
'Archived Books'
),
"link"
:
'web.books_list'
,
"id"
:
"archived"
,
"visibility"
:
constants
.
SIDEBAR_ARCHIVED
,
'public'
:
(
not
g
.
user
.
is_anonymous
),
"page"
:
"archived"
,
"visibility"
:
constants
.
SIDEBAR_ARCHIVED
,
'public'
:
(
not
g
.
user
.
is_anonymous
),
"page"
:
"archived"
,
"show_text"
:
_
(
'Show archived books'
),
"config_show"
:
content
})
"show_text"
:
_
(
'Show archived books'
),
"config_show"
:
content
})
sidebar
.
append
(
{
"glyph"
:
"glyphicon-th-list"
,
"text"
:
_
(
'Books List'
),
"link"
:
'web.books_list'
,
"id"
:
"list"
,
"visibility"
:
constants
.
SIDEBAR_LIST
,
'public'
:
(
not
g
.
user
.
is_anonymous
),
"page"
:
"list"
,
"show_text"
:
_
(
'Show Books List'
),
"config_show"
:
content
})
return
sidebar
return
sidebar
...
...
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