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
1a0bf45c
Commit
1a0bf45c
authored
Jun 06, 2021
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check file/folder permissions before update
parent
67874e07
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
26 deletions
+55
-26
admin.py
cps/admin.py
+2
-1
main.js
cps/static/js/main.js
+1
-3
updater.py
cps/updater.py
+52
-22
No files found.
cps/admin.py
View file @
1a0bf45c
...
@@ -1671,7 +1671,8 @@ def get_updater_status():
...
@@ -1671,7 +1671,8 @@ def get_updater_status():
"9"
:
_
(
u'Update failed:'
)
+
u' '
+
_
(
u'Connection error'
),
"9"
:
_
(
u'Update failed:'
)
+
u' '
+
_
(
u'Connection error'
),
"10"
:
_
(
u'Update failed:'
)
+
u' '
+
_
(
u'Timeout while establishing connection'
),
"10"
:
_
(
u'Update failed:'
)
+
u' '
+
_
(
u'Timeout while establishing connection'
),
"11"
:
_
(
u'Update failed:'
)
+
u' '
+
_
(
u'General error'
),
"11"
:
_
(
u'Update failed:'
)
+
u' '
+
_
(
u'General error'
),
"12"
:
_
(
u'Update failed:'
)
+
u' '
+
_
(
u'Update File Could Not be Saved in Temp Dir'
)
"12"
:
_
(
u'Update failed:'
)
+
u' '
+
_
(
u'Update file could not be saved in temp dir'
),
"13"
:
_
(
u'Update failed:'
)
+
u' '
+
_
(
u'Files could not be replaced during update'
)
}
}
status
[
'text'
]
=
text
status
[
'text'
]
=
text
updater_thread
.
status
=
0
updater_thread
.
status
=
0
...
...
cps/static/js/main.js
View file @
1a0bf45c
...
@@ -239,14 +239,13 @@ $(function() {
...
@@ -239,14 +239,13 @@ $(function() {
dataType
:
"json"
,
dataType
:
"json"
,
url
:
window
.
location
.
pathname
+
"/../../get_updater_status"
,
url
:
window
.
location
.
pathname
+
"/../../get_updater_status"
,
success
:
function
success
(
data
)
{
success
:
function
success
(
data
)
{
// console.log(data.status);
$
(
"#DialogContent"
).
html
(
updateText
[
data
.
status
]);
$
(
"#DialogContent"
).
html
(
updateText
[
data
.
status
]);
if
(
data
.
status
>
6
)
{
if
(
data
.
status
>
6
)
{
cleanUp
();
cleanUp
();
}
}
},
},
error
:
function
error
()
{
error
:
function
error
()
{
$
(
"#DialogContent"
).
html
(
updateText
[
7
]);
$
(
"#DialogContent"
).
html
(
updateText
[
11
]);
cleanUp
();
cleanUp
();
},
},
timeout
:
2000
timeout
:
2000
...
@@ -442,7 +441,6 @@ $(function() {
...
@@ -442,7 +441,6 @@ $(function() {
success
:
function
success
(
data
)
{
success
:
function
success
(
data
)
{
updateText
=
data
.
text
;
updateText
=
data
.
text
;
$
(
"#DialogContent"
).
html
(
updateText
[
data
.
status
]);
$
(
"#DialogContent"
).
html
(
updateText
[
data
.
status
]);
// console.log(data.status);
updateTimerID
=
setInterval
(
updateTimer
,
2000
);
updateTimerID
=
setInterval
(
updateTimer
,
2000
);
}
}
});
});
...
...
cps/updater.py
View file @
1a0bf45c
...
@@ -94,7 +94,7 @@ class Updater(threading.Thread):
...
@@ -94,7 +94,7 @@ class Updater(threading.Thread):
return
False
return
False
self
.
status
=
4
self
.
status
=
4
log
.
debug
(
u'Replacing files'
)
log
.
debug
(
u'Replacing files'
)
self
.
update_source
(
foldername
,
constants
.
BASE_DIR
)
if
self
.
update_source
(
foldername
,
constants
.
BASE_DIR
):
self
.
status
=
6
self
.
status
=
6
log
.
debug
(
u'Preparing restart of server'
)
log
.
debug
(
u'Preparing restart of server'
)
time
.
sleep
(
2
)
time
.
sleep
(
2
)
...
@@ -102,6 +102,9 @@ class Updater(threading.Thread):
...
@@ -102,6 +102,9 @@ class Updater(threading.Thread):
self
.
status
=
7
self
.
status
=
7
time
.
sleep
(
2
)
time
.
sleep
(
2
)
return
True
return
True
else
:
self
.
status
=
13
except
requests
.
exceptions
.
HTTPError
as
ex
:
except
requests
.
exceptions
.
HTTPError
as
ex
:
log
.
error
(
u'HTTP Error
%
s'
,
ex
)
log
.
error
(
u'HTTP Error
%
s'
,
ex
)
self
.
status
=
8
self
.
status
=
8
...
@@ -181,6 +184,28 @@ class Updater(threading.Thread):
...
@@ -181,6 +184,28 @@ class Updater(threading.Thread):
rf
.
append
(
item
)
rf
.
append
(
item
)
return
rf
return
rf
@
classmethod
def
check_permissions
(
cls
,
root_src_dir
,
root_dst_dir
):
access
=
True
remove_path
=
len
(
root_src_dir
)
+
1
for
src_dir
,
__
,
files
in
os
.
walk
(
root_src_dir
):
root_dir
=
os
.
path
.
join
(
root_dst_dir
,
src_dir
[
remove_path
:])
# Skip non existing folders on check
if
not
os
.
path
.
isdir
(
root_dir
):
# root_dir.lstrip(os.sep).startswith('.') or
continue
if
not
os
.
access
(
root_dir
,
os
.
R_OK
|
os
.
W_OK
):
log
.
debug
(
"Missing permissions for {}"
.
format
(
root_dir
))
access
=
False
for
file_
in
files
:
curr_file
=
os
.
path
.
join
(
root_dir
,
file_
)
# Skip non existing files on check
if
not
os
.
path
.
isfile
(
curr_file
):
# or curr_file.startswith('.'):
continue
if
not
os
.
access
(
curr_file
,
os
.
R_OK
|
os
.
W_OK
):
log
.
debug
(
"Missing permissions for {}"
.
format
(
curr_file
))
access
=
False
return
access
@
classmethod
@
classmethod
def
moveallfiles
(
cls
,
root_src_dir
,
root_dst_dir
):
def
moveallfiles
(
cls
,
root_src_dir
,
root_dst_dir
):
new_permissions
=
os
.
stat
(
root_dst_dir
)
new_permissions
=
os
.
stat
(
root_dst_dir
)
...
@@ -269,6 +294,7 @@ class Updater(threading.Thread):
...
@@ -269,6 +294,7 @@ class Updater(threading.Thread):
remove_items
=
self
.
reduce_dirs
(
rf
,
new_list
)
remove_items
=
self
.
reduce_dirs
(
rf
,
new_list
)
if
self
.
check_permissions
(
source
,
destination
):
self
.
moveallfiles
(
source
,
destination
)
self
.
moveallfiles
(
source
,
destination
)
for
item
in
remove_items
:
for
item
in
remove_items
:
...
@@ -283,6 +309,10 @@ class Updater(threading.Thread):
...
@@ -283,6 +309,10 @@ class Updater(threading.Thread):
except
OSError
:
except
OSError
:
log
.
debug
(
"Could not remove:
%
s"
,
item_path
)
log
.
debug
(
"Could not remove:
%
s"
,
item_path
)
shutil
.
rmtree
(
source
,
ignore_errors
=
True
)
shutil
.
rmtree
(
source
,
ignore_errors
=
True
)
return
True
else
:
log
.
debug
(
"Permissions missing for update"
)
return
False
@
staticmethod
@
staticmethod
def
is_venv
():
def
is_venv
():
...
@@ -572,5 +602,5 @@ class Updater(threading.Thread):
...
@@ -572,5 +602,5 @@ class Updater(threading.Thread):
status
[
'message'
]
=
_
(
u'Timeout while establishing connection'
)
status
[
'message'
]
=
_
(
u'Timeout while establishing connection'
)
except
(
requests
.
exceptions
.
RequestException
,
ValueError
):
except
(
requests
.
exceptions
.
RequestException
,
ValueError
):
status
[
'message'
]
=
_
(
u'General error'
)
status
[
'message'
]
=
_
(
u'General error'
)
log
.
debug
(
'Updater status:
%
s'
,
status
[
'message'
]
)
log
.
debug
(
'Updater status:
{}'
.
format
(
status
[
'message'
]
or
"OK"
)
)
return
status
,
commit
return
status
,
commit
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