Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Turris
server-side-backups-client
Commits
c0d116f4
Verified
Commit
c0d116f4
authored
Aug 20, 2018
by
Štěpán Henek
🐻
Browse files
python3: division and encode/decode fixes
parent
ef5a1453
Pipeline
#39413
passed with stage
in 41 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/ssbackups.py
View file @
c0d116f4
...
@@ -234,7 +234,7 @@ def encrypt_backup(backup, password):
...
@@ -234,7 +234,7 @@ def encrypt_backup(backup, password):
# stderr=PIPE -> to catch error
# stderr=PIPE -> to catch error
###
###
process
=
Popen
(
cmd
,
stdin
=
PIPE
,
stderr
=
PIPE
)
process
=
Popen
(
cmd
,
stdin
=
PIPE
,
stderr
=
PIPE
)
error
=
process
.
communicate
(
password
)[
1
]
error
=
process
.
communicate
(
password
.
encode
()
)[
1
]
if
process
.
returncode
!=
0
:
if
process
.
returncode
!=
0
:
raise
SSBackupsException
(
raise
SSBackupsException
(
"Command << {cmd} >> failed having this on stderr << {error} >>."
.
format
(
"Command << {cmd} >> failed having this on stderr << {error} >>."
.
format
(
...
@@ -256,6 +256,7 @@ def decrypt_backup(target, backup, password):
...
@@ -256,6 +256,7 @@ def decrypt_backup(target, backup, password):
:param target: where to store backup after downloading and decrypting
:param target: where to store backup after downloading and decrypting
:param backup: content of backup
:param backup: content of backup
:param password: passphrase
:param password: passphrase
:type password: str
:return: None
:return: None
"""
"""
tmp_file
=
open
(
target
+
'.gpg'
,
'wb'
)
tmp_file
=
open
(
target
+
'.gpg'
,
'wb'
)
...
@@ -287,7 +288,7 @@ def decrypt_backup(target, backup, password):
...
@@ -287,7 +288,7 @@ def decrypt_backup(target, backup, password):
# stderr=PIPE -> to catch error
# stderr=PIPE -> to catch error
###
###
process
=
Popen
(
cmd
,
stdin
=
PIPE
,
stderr
=
PIPE
)
process
=
Popen
(
cmd
,
stdin
=
PIPE
,
stderr
=
PIPE
)
error
=
process
.
communicate
(
password
)[
1
]
error
=
process
.
communicate
(
password
.
encode
()
)[
1
]
if
process
.
returncode
!=
0
:
if
process
.
returncode
!=
0
:
raise
SSBackupsException
(
raise
SSBackupsException
(
"Command << {cmd} >> failed having this on stderr << {error} >>."
.
format
(
"Command << {cmd} >> failed having this on stderr << {error} >>."
.
format
(
...
@@ -358,7 +359,12 @@ def call_rest_api(reg_code, url, action, backup_id=None, backup=None, fail=True,
...
@@ -358,7 +359,12 @@ def call_rest_api(reg_code, url, action, backup_id=None, backup=None, fail=True,
###
###
# stderr=open('/dev/null','w') is here to hide progress meter
# stderr=open('/dev/null','w') is here to hide progress meter
###
###
return
check_output
(
cmd
,
stderr
=
open
(
'/dev/null'
,
'w'
))
res
=
check_output
(
cmd
,
stderr
=
open
(
'/dev/null'
,
'w'
))
try
:
return
res
.
decode
()
except
UnicodeDecodeError
:
return
res
except
CalledProcessError
as
exc
:
except
CalledProcessError
as
exc
:
raise
SSBackupsException
(
raise
SSBackupsException
(
"Command << {cmd} >> ended with << return code = {return_code} >> and with output << {output} >>."
.
format
(
"Command << {cmd} >> ended with << return code = {return_code} >> and with output << {output} >>."
.
format
(
...
@@ -410,14 +416,13 @@ def backup_delete(reg_code, url, backup_id):
...
@@ -410,14 +416,13 @@ def backup_delete(reg_code, url, backup_id):
content_type
=
True
content_type
=
True
)
)
status_code
=
res
.
split
(
'
\n
'
)[
-
2
]
status_code
=
res
.
split
(
'
\n
'
)[
-
2
]
if
int
(
status_code
)
/
100
!=
2
:
if
int
(
status_code
)
/
/
100
!=
2
:
raise
SSBackupsException
(
raise
SSBackupsException
(
"Could not delete backup."
,
"Could not delete backup."
,
ERR_CODE_API_CALL
ERR_CODE_API_CALL
)
)
def
backup_ondemand
(
reg_code
,
url
,
backup_id
):
def
backup_ondemand
(
reg_code
,
url
,
backup_id
):
"""
"""
Wrapper to action ondemand and its call_rest_api
Wrapper to action ondemand and its call_rest_api
...
@@ -436,7 +441,7 @@ def backup_ondemand(reg_code, url, backup_id):
...
@@ -436,7 +441,7 @@ def backup_ondemand(reg_code, url, backup_id):
content_type
=
True
content_type
=
True
)
)
status_code
=
res
.
split
(
'
\n
'
)[
-
2
]
status_code
=
res
.
split
(
'
\n
'
)[
-
2
]
if
int
(
status_code
)
/
100
!=
2
:
if
int
(
status_code
)
/
/
100
!=
2
:
raise
SSBackupsException
(
raise
SSBackupsException
(
"Could not mark backup as on-demand."
,
"Could not mark backup as on-demand."
,
ERR_CODE_API_CALL
ERR_CODE_API_CALL
...
@@ -468,7 +473,7 @@ def backup_create(reg_code, url, backup, password):
...
@@ -468,7 +473,7 @@ def backup_create(reg_code, url, backup, password):
status_code
,
content_type
=
res
.
split
(
'
\n
'
)[
-
2
:]
status_code
,
content_type
=
res
.
split
(
'
\n
'
)[
-
2
:]
res
=
''
.
join
(
res
.
split
(
'
\n
'
)[
0
:
-
2
])
res
=
''
.
join
(
res
.
split
(
'
\n
'
)[
0
:
-
2
])
if
int
(
status_code
)
/
100
==
2
:
if
int
(
status_code
)
/
/
100
==
2
:
try
:
try
:
return
json
.
loads
(
res
)
return
json
.
loads
(
res
)
except
JsonError
as
exc
:
except
JsonError
as
exc
:
...
...
Write
Preview
Supports
Markdown
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