Verified Commit c0d116f4 authored by Štěpán Henek's avatar Štěpán Henek 🐻
Browse files

python3: division and encode/decode fixes

parent ef5a1453
Pipeline #39413 passed with stage
in 41 seconds
......@@ -234,7 +234,7 @@ def encrypt_backup(backup, password):
# stderr=PIPE -> to catch error
###
process = Popen(cmd, stdin=PIPE, stderr=PIPE)
error = process.communicate(password)[1]
error = process.communicate(password.encode())[1]
if process.returncode != 0:
raise SSBackupsException(
"Command << {cmd} >> failed having this on stderr << {error} >>.".format(
......@@ -256,6 +256,7 @@ def decrypt_backup(target, backup, password):
:param target: where to store backup after downloading and decrypting
:param backup: content of backup
:param password: passphrase
:type password: str
:return: None
"""
tmp_file = open(target + '.gpg', 'wb')
......@@ -287,7 +288,7 @@ def decrypt_backup(target, backup, password):
# stderr=PIPE -> to catch error
###
process = Popen(cmd, stdin=PIPE, stderr=PIPE)
error = process.communicate(password)[1]
error = process.communicate(password.encode())[1]
if process.returncode != 0:
raise SSBackupsException(
"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,
###
# 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:
raise SSBackupsException(
"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):
content_type=True
)
status_code = res.split('\n')[-2]
if int(status_code) / 100 != 2:
if int(status_code) // 100 != 2:
raise SSBackupsException(
"Could not delete backup.",
ERR_CODE_API_CALL
)
def backup_ondemand(reg_code, url, backup_id):
"""
Wrapper to action ondemand and its call_rest_api
......@@ -436,7 +441,7 @@ def backup_ondemand(reg_code, url, backup_id):
content_type=True
)
status_code = res.split('\n')[-2]
if int(status_code) / 100 != 2:
if int(status_code) // 100 != 2:
raise SSBackupsException(
"Could not mark backup as on-demand.",
ERR_CODE_API_CALL
......@@ -468,7 +473,7 @@ def backup_create(reg_code, url, backup, password):
status_code, content_type = res.split('\n')[-2:]
res = ''.join(res.split('\n')[0:-2])
if int(status_code) / 100 == 2:
if int(status_code) // 100 == 2:
try:
return json.loads(res)
except JsonError as exc:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment