summaryrefslogtreecommitdiffstats
path: root/cli/objects/live.py
diff options
context:
space:
mode:
Diffstat (limited to 'cli/objects/live.py')
-rw-r--r--cli/objects/live.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/cli/objects/live.py b/cli/objects/live.py
index e7403b5..ca8824a 100644
--- a/cli/objects/live.py
+++ b/cli/objects/live.py
@@ -97,7 +97,6 @@ class OgLive():
print(f'Request failed for {file_url}: {e}')
return 1
- err = 0
if response.status_code == 200:
try:
with open(local_path, 'wb') as f:
@@ -106,17 +105,9 @@ class OgLive():
f.write(chunk)
except OSError as e:
print(f'File system error occurred: {e}')
- err = 1
+ return 1
else:
print(f'ERROR: Failed to download {live_file}. Status code: {response.status_code}')
- err = 1
-
- if err:
- try:
- if os.path.exists(local_path):
- os.remove(local_path)
- except OSError as e:
- print(f'ERROR: Failed to delete file {live_file}: {e}')
return 1
return 0
@@ -137,6 +128,7 @@ class OgLive():
download_err = OgLive._download_from_server('ogrelive.json',
local_extension=OgLive.tmp_extension)
if download_err:
+ OgLive._delete_tmp_live_files('')
return 1
remote_json = os.path.join(local_live_dir, 'ogrelive.json')
@@ -211,6 +203,7 @@ class OgLive():
live_file + '.full.sum'),
local_extension=OgLive.tmp_extension)
if download_err:
+ OgLive._delete_tmp_live_files(live_name)
return download_err
file_path = os.path.join(local_dir, live_file)
@@ -231,6 +224,7 @@ class OgLive():
live_file),
local_extension=OgLive.tmp_extension)
if download_err:
+ OgLive._delete_tmp_live_files(live_name)
return download_err
if not OgLive._is_same_checksum(file_path_tmp, checksum_path_tmp):
@@ -239,6 +233,12 @@ class OgLive():
return 1
print(f'Checksum is OK for {live_file}')
+
+ for file_name in os.listdir(local_dir):
+ if not file_name.endswith(OgLive.tmp_extension):
+ continue
+ file_path_tmp = os.path.join(local_dir, file_name)
+ file_path = file_path_tmp[:-len(OgLive.tmp_extension)]
try:
shutil.move(file_path_tmp, file_path)
except OSError as e:
@@ -246,8 +246,6 @@ class OgLive():
OgLive._delete_tmp_live_files(live_name)
return 1
- OgLive._delete_tmp_live_files(live_name)
-
payload = {'name': live_name}
res = rest.post('/oglive/add', payload=payload)