summaryrefslogtreecommitdiffstats
path: root/cli/objects
diff options
context:
space:
mode:
Diffstat (limited to 'cli/objects')
-rw-r--r--cli/objects/live.py22
-rw-r--r--cli/objects/scopes.py6
2 files changed, 13 insertions, 15 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)
diff --git a/cli/objects/scopes.py b/cli/objects/scopes.py
index 5779f78..88f5521 100644
--- a/cli/objects/scopes.py
+++ b/cli/objects/scopes.py
@@ -41,7 +41,7 @@ class OgScope():
@staticmethod
def list_scopes(rest, args):
- parser = argparse.ArgumentParser(prog='ogcli list scope')
+ parser = argparse.ArgumentParser(prog='ogcli list scopes')
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument('--client-ip',
action='append',
@@ -58,7 +58,7 @@ class OgScope():
ips.add(ip)
res = rest.get('/scopes')
- json_data = json.loads(r.text)
+ json_data = json.loads(res.text)
if parsed_args.name:
path = _get_client_path(json_data, None, parsed_args.name)
@@ -72,6 +72,6 @@ class OgScope():
for i, item in enumerate(path):
print(' ' * i + item)
else:
- print_json(r.text)
+ print_json(res.text)
return 0