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
6ec4e0a6
Commit
6ec4e0a6
authored
Feb 21, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bugfix Updater
Improved logging
parent
709fa88c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
18 deletions
+23
-18
cps.py
cps.py
+2
-2
helper.py
cps/helper.py
+13
-11
web.py
cps/web.py
+8
-5
No files found.
cps.py
View file @
6ec4e0a6
...
@@ -22,8 +22,8 @@ if __name__ == '__main__':
...
@@ -22,8 +22,8 @@ if __name__ == '__main__':
IOLoop
.
instance
()
.
start
()
IOLoop
.
instance
()
.
start
()
if
web
.
helper
.
global_task
==
0
:
if
web
.
helper
.
global_task
==
0
:
print
(
"Performing restart of Calibre-web"
)
web
.
app
.
logger
.
info
(
"Performing restart of Calibre-web"
)
os
.
execl
(
sys
.
executable
,
sys
.
executable
,
*
sys
.
argv
)
os
.
execl
(
sys
.
executable
,
sys
.
executable
,
*
sys
.
argv
)
else
:
else
:
print
(
"Performing shutdown of Calibre-web"
)
web
.
app
.
logger
.
info
(
"Performing shutdown of Calibre-web"
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
cps/helper.py
View file @
6ec4e0a6
...
@@ -338,7 +338,7 @@ class Updater(threading.Thread):
...
@@ -338,7 +338,7 @@ class Updater(threading.Thread):
def
reduce_files
(
self
,
remove_items
,
exclude_items
):
def
reduce_files
(
self
,
remove_items
,
exclude_items
):
rf
=
[]
rf
=
[]
for
item
in
remove_items
:
for
item
in
remove_items
:
if
not
item
in
exclude_items
:
if
not
item
.
startswith
(
exclude_items
)
:
rf
.
append
(
item
)
rf
.
append
(
item
)
return
rf
return
rf
...
@@ -347,15 +347,14 @@ class Updater(threading.Thread):
...
@@ -347,15 +347,14 @@ class Updater(threading.Thread):
if
sys
.
platform
==
"win32"
or
sys
.
platform
==
"darwin"
:
if
sys
.
platform
==
"win32"
or
sys
.
platform
==
"darwin"
:
change_permissions
=
False
change_permissions
=
False
else
:
else
:
app
.
logger
.
debug
(
'Update on OS-System : '
+
sys
.
platform
)
logging
.
getLogger
(
'cps.web'
)
.
debug
(
'Update on OS-System : '
+
sys
.
platform
)
# print('OS-System: '+sys.platform )
new_permissions
=
os
.
stat
(
root_dst_dir
)
new_permissions
=
os
.
stat
(
root_dst_dir
)
# print new_permissions
# print new_permissions
for
src_dir
,
dirs
,
files
in
os
.
walk
(
root_src_dir
):
for
src_dir
,
dirs
,
files
in
os
.
walk
(
root_src_dir
):
dst_dir
=
src_dir
.
replace
(
root_src_dir
,
root_dst_dir
,
1
)
dst_dir
=
src_dir
.
replace
(
root_src_dir
,
root_dst_dir
,
1
)
if
not
os
.
path
.
exists
(
dst_dir
):
if
not
os
.
path
.
exists
(
dst_dir
):
os
.
makedirs
(
dst_dir
)
os
.
makedirs
(
dst_dir
)
# print
('Create-Dir: '+dst_dir)
logging
.
getLogger
(
'cps.web'
)
.
debug
(
'Create-Dir: '
+
dst_dir
)
if
change_permissions
:
if
change_permissions
:
# print('Permissions: User '+str(new_permissions.st_uid)+' Group '+str(new_permissions.st_uid))
# print('Permissions: User '+str(new_permissions.st_uid)+' Group '+str(new_permissions.st_uid))
os
.
chown
(
dst_dir
,
new_permissions
.
st_uid
,
new_permissions
.
st_gid
)
os
.
chown
(
dst_dir
,
new_permissions
.
st_uid
,
new_permissions
.
st_gid
)
...
@@ -365,27 +364,28 @@ class Updater(threading.Thread):
...
@@ -365,27 +364,28 @@ class Updater(threading.Thread):
if
os
.
path
.
exists
(
dst_file
):
if
os
.
path
.
exists
(
dst_file
):
if
change_permissions
:
if
change_permissions
:
permission
=
os
.
stat
(
dst_file
)
permission
=
os
.
stat
(
dst_file
)
# print
('Remove file before copy: '+dst_file)
logging
.
getLogger
(
'cps.web'
)
.
debug
(
'Remove file before copy: '
+
dst_file
)
os
.
remove
(
dst_file
)
os
.
remove
(
dst_file
)
else
:
else
:
if
change_permissions
:
if
change_permissions
:
permission
=
new_permissions
permission
=
new_permissions
shutil
.
move
(
src_file
,
dst_dir
)
shutil
.
move
(
src_file
,
dst_dir
)
# print
('Move File '+src_file+' to '+dst_dir)
logging
.
getLogger
(
'cps.web'
)
.
debug
(
'Move File '
+
src_file
+
' to '
+
dst_dir
)
if
change_permissions
:
if
change_permissions
:
try
:
try
:
os
.
chown
(
dst_file
,
permission
.
st_uid
,
permission
.
st_uid
)
os
.
chown
(
dst_file
,
permission
.
st_uid
,
permission
.
st_uid
)
# print('Permissions: User '+str(new_permissions.st_uid)+' Group '+str(new_permissions.st_uid))
# print('Permissions: User '+str(new_permissions.st_uid)+' Group '+str(new_permissions.st_uid))
except
:
except
:
e
=
sys
.
exc_info
()
e
=
sys
.
exc_info
()
# print
('Fail '+str(dst_file)+' error: '+str(e))
logging
.
getLogger
(
'cps.web'
)
.
debug
(
'Fail '
+
str
(
dst_file
)
+
' error: '
+
str
(
e
))
return
return
def
update_source
(
self
,
source
,
destination
):
def
update_source
(
self
,
source
,
destination
):
# destination files
# destination files
old_list
=
list
()
old_list
=
list
()
exclude
=
(
exclude
=
(
[
'vendor'
+
os
.
sep
+
'kindlegen.exe'
,
'vendor'
+
os
.
sep
+
'kindlegen'
,
'/app.db'
,
'vendor'
,
'/update.py'
])
'vendor'
+
os
.
sep
+
'kindlegen.exe'
,
'vendor'
+
os
.
sep
+
'kindlegen'
,
os
.
sep
+
'app.db'
,
os
.
sep
+
'vendor'
,
os
.
sep
+
'calibre-web.log'
)
for
root
,
dirs
,
files
in
os
.
walk
(
destination
,
topdown
=
True
):
for
root
,
dirs
,
files
in
os
.
walk
(
destination
,
topdown
=
True
):
for
name
in
files
:
for
name
in
files
:
old_list
.
append
(
os
.
path
.
join
(
root
,
name
)
.
replace
(
destination
,
''
))
old_list
.
append
(
os
.
path
.
join
(
root
,
name
)
.
replace
(
destination
,
''
))
...
@@ -410,12 +410,14 @@ class Updater(threading.Thread):
...
@@ -410,12 +410,14 @@ class Updater(threading.Thread):
for
item
in
remove_items
:
for
item
in
remove_items
:
item_path
=
os
.
path
.
join
(
destination
,
item
[
1
:])
item_path
=
os
.
path
.
join
(
destination
,
item
[
1
:])
if
os
.
path
.
isdir
(
item_path
):
if
os
.
path
.
isdir
(
item_path
):
app
.
logger
.
debug
(
"Delete dir "
+
item_path
)
logging
.
getLogger
(
'cps.web'
)
.
debug
(
"Delete dir "
+
item_path
)
shutil
.
rmtree
(
item_path
)
shutil
.
rmtree
(
item_path
)
else
:
else
:
try
:
try
:
app
.
logger
.
debug
(
"Delete file "
+
item_path
)
logging
.
getLogger
(
'cps.web'
)
.
debug
(
"Delete file "
+
item_path
)
log_from_thread
(
"Delete file "
+
item_path
)
os
.
remove
(
item_path
)
os
.
remove
(
item_path
)
except
:
except
:
app
.
logger
.
debug
(
"Could not remove:"
+
item_path
)
logging
.
getLogger
(
'cps.web'
)
.
debug
(
"Could not remove:"
+
item_path
)
shutil
.
rmtree
(
source
,
ignore_errors
=
True
)
shutil
.
rmtree
(
source
,
ignore_errors
=
True
)
cps/web.py
View file @
6ec4e0a6
...
@@ -744,7 +744,10 @@ def get_updater_status():
...
@@ -744,7 +744,10 @@ def get_updater_status():
helper
.
updater_thread
.
start
()
helper
.
updater_thread
.
start
()
status
[
'status'
]
=
helper
.
updater_thread
.
get_update_status
()
status
[
'status'
]
=
helper
.
updater_thread
.
get_update_status
()
elif
request
.
method
==
"GET"
:
elif
request
.
method
==
"GET"
:
status
[
'status'
]
=
helper
.
updater_thread
.
get_update_status
()
try
:
status
[
'status'
]
=
helper
.
updater_thread
.
get_update_status
()
except
:
status
[
'status'
]
=
7
return
json
.
dumps
(
status
)
return
json
.
dumps
(
status
)
...
@@ -1044,9 +1047,9 @@ def stats():
...
@@ -1044,9 +1047,9 @@ def stats():
@
login_required
@
login_required
@
admin_required
@
admin_required
def
shutdown
():
def
shutdown
():
global
global_task
#
global global_task
task
=
int
(
request
.
args
.
get
(
"parameter"
)
.
strip
())
task
=
int
(
request
.
args
.
get
(
"parameter"
)
.
strip
())
global_task
=
task
helper
.
global_task
=
task
if
task
==
1
or
task
==
0
:
# valid commandos received
if
task
==
1
or
task
==
0
:
# valid commandos received
# close all database connections
# close all database connections
db
.
session
.
close
()
db
.
session
.
close
()
...
@@ -1611,7 +1614,7 @@ def basic_configuration():
...
@@ -1611,7 +1614,7 @@ def basic_configuration():
def
configuration_helper
(
origin
):
def
configuration_helper
(
origin
):
global
global_task
#
global global_task
reboot_required
=
False
reboot_required
=
False
db_change
=
False
db_change
=
False
success
=
False
success
=
False
...
@@ -1686,7 +1689,7 @@ def configuration_helper(origin):
...
@@ -1686,7 +1689,7 @@ def configuration_helper(origin):
# stop tornado server
# stop tornado server
server
=
IOLoop
.
instance
()
server
=
IOLoop
.
instance
()
server
.
add_callback
(
server
.
stop
)
server
.
add_callback
(
server
.
stop
)
global_task
=
0
helper
.
global_task
=
0
app
.
logger
.
info
(
'Reboot required, restarting'
)
app
.
logger
.
info
(
'Reboot required, restarting'
)
if
origin
:
if
origin
:
success
=
True
success
=
True
...
...
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