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
a836df9a
Commit
a836df9a
authored
Jul 14, 2019
by
Daniel Pavel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more robust disposing of database session
avoid spamming the log with debug messages from libraries
parent
be64961d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
28 deletions
+33
-28
.gitignore
.gitignore
+1
-0
__init__.py
cps/__init__.py
+1
-0
admin.py
cps/admin.py
+0
-4
config_sql.py
cps/config_sql.py
+10
-4
db.py
cps/db.py
+7
-9
logger.py
cps/logger.py
+7
-2
ub.py
cps/ub.py
+7
-9
No files found.
.gitignore
View file @
a836df9a
...
...
@@ -14,6 +14,7 @@ build/
*.egg-info/
.installed.cfg
*.egg
.pylint.d
# calibre-web
*.db
...
...
cps/__init__.py
View file @
a836df9a
...
...
@@ -64,6 +64,7 @@ lm.anonymous_user = ub.Anonymous
ub
.
init_db
(
cli
.
settingspath
)
# pylint: disable=no-member
config
=
config_sql
.
load_configuration
(
ub
.
session
)
from
.
import
db
,
services
...
...
cps/admin.py
View file @
a836df9a
...
...
@@ -27,10 +27,6 @@ import base64
import
json
import
time
from
datetime
import
datetime
,
timedelta
# try:
# from imp import reload
# except ImportError:
# pass
from
babel
import
Locale
as
LC
from
babel.dates
import
format_datetime
...
...
cps/config_sql.py
View file @
a836df9a
...
...
@@ -52,7 +52,7 @@ class _Settings(_Base):
config_random_books
=
Column
(
Integer
,
default
=
4
)
config_authors_max
=
Column
(
Integer
,
default
=
0
)
config_read_column
=
Column
(
Integer
,
default
=
0
)
config_title_regex
=
Column
(
String
,
default
=
u
'^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)
\
s+'
)
config_title_regex
=
Column
(
String
,
default
=
r
'^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+'
)
config_log_level
=
Column
(
SmallInteger
,
default
=
logger
.
DEFAULT_LOG_LEVEL
)
config_access_log
=
Column
(
SmallInteger
,
default
=
0
)
config_uploading
=
Column
(
SmallInteger
,
default
=
0
)
...
...
@@ -106,7 +106,6 @@ class _Settings(_Base):
# Class holds all application specific settings in calibre-web
class
_ConfigSQL
(
object
):
# pylint: disable=no-member
def
__init__
(
self
,
session
):
self
.
_session
=
session
self
.
_settings
=
None
...
...
@@ -226,8 +225,14 @@ class _ConfigSQL(object):
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
.
db_configured
=
(
self
.
config_calibre_dir
and
(
not
self
.
config_use_google_drive
or
os
.
path
.
exists
(
self
.
config_calibre_dir
+
'/metadata.db'
)))
have_metadata_db
=
bool
(
self
.
config_calibre_dir
)
if
have_metadata_db
:
if
not
self
.
config_use_google_drive
:
db_file
=
os
.
path
.
join
(
self
.
config_calibre_dir
,
'metadata.db'
)
have_metadata_db
=
os
.
path
.
isfile
(
db_file
)
self
.
db_configured
=
have_metadata_db
logger
.
setup
(
self
.
config_logfile
,
self
.
config_log_level
)
def
save
(
self
):
...
...
@@ -264,6 +269,7 @@ def _migrate_table(session, orm_class):
log
.
debug
(
"
%
s:
%
s"
,
column_name
,
err
)
column_default
=
""
if
column
.
default
is
None
else
(
"DEFAULT
%
r"
%
column
.
default
.
arg
)
alter_table
=
"ALTER TABLE
%
s ADD COLUMN `
%
s`
%
s
%
s"
%
(
orm_class
.
__tablename__
,
column_name
,
column
.
type
,
column_default
)
log
.
debug
(
alter_table
)
session
.
execute
(
alter_table
)
changed
=
True
...
...
cps/db.py
View file @
a836df9a
...
...
@@ -407,16 +407,14 @@ def setup_db(config):
def
dispose
():
global
session
engine
=
None
if
session
:
engine
=
session
.
bind
try
:
session
.
close
()
except
:
pass
session
=
None
if
engine
:
try
:
engine
.
dispose
()
old_session
=
session
session
=
None
if
old_session
:
try
:
old_session
.
close
()
except
:
pass
if
old_session
.
bind
:
try
:
old_session
.
bind
.
dispose
()
except
:
pass
for
attr
in
list
(
Books
.
__dict__
.
keys
()):
if
attr
.
startswith
(
"custom_column_"
):
...
...
cps/logger.py
View file @
a836df9a
...
...
@@ -97,15 +97,20 @@ def setup(log_file, log_level=None):
'''
log_file
=
_absolute_log_file
(
log_file
,
DEFAULT_LOG_FILE
)
log_level
=
log_level
or
DEFAULT_LOG_LEVEL
logging
.
getLogger
(
__package__
)
.
setLevel
(
log_level
)
r
=
logging
.
root
r
.
setLevel
(
log_level
or
DEFAULT_LOG_LEVEL
)
if
log_level
>=
logging
.
INFO
or
os
.
environ
.
get
(
'FLASK_DEBUG'
):
# avoid spamming the log with debug messages from libraries
r
.
setLevel
(
log_level
)
previous_handler
=
r
.
handlers
[
0
]
if
r
.
handlers
else
None
if
previous_handler
:
# if the log_file has not changed, don't create a new handler
if
getattr
(
previous_handler
,
'baseFilename'
,
None
)
==
log_file
:
return
r
.
debug
(
"logging to
%
s level
%
s"
,
log_file
,
r
.
level
)
logging
.
debug
(
"logging to
%
s level
%
s"
,
log_file
,
r
.
level
)
if
log_file
==
LOG_TO_STDERR
:
file_handler
=
StreamHandler
()
...
...
cps/ub.py
View file @
a836df9a
...
...
@@ -478,13 +478,11 @@ def init_db(app_db_path):
def
dispose
():
global
session
engine
=
None
if
session
:
engine
=
session
.
bind
try
:
session
.
close
()
except
:
pass
session
=
None
if
engine
:
try
:
engine
.
dispose
()
old_session
=
session
session
=
None
if
old_session
:
try
:
old_session
.
close
()
except
:
pass
if
old_session
.
bind
:
try
:
old_session
.
bind
.
dispose
()
except
:
pass
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