summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--cli/cli.py6
-rw-r--r--[-rwxr-xr-x]cli/config.py (renamed from config.py)0
-rw-r--r--cli/objects/live.py22
-rw-r--r--cli/objects/scopes.py6
5 files changed, 17 insertions, 19 deletions
diff --git a/README.md b/README.md
index e58887e..405567d 100644
--- a/README.md
+++ b/README.md
@@ -143,7 +143,7 @@ ogcli setup disk --type dos --part 1,LINUX,EXT4,40G --part 4,CACHE,CACHE,10G --f
##### Fetching a classroom id
```
-ogcli list scope
+ogcli list scopes
{'scope': [{'name': 'Unidad Organizativa (Default)', 'type': 'center', 'id': 1, 'scope': [{'name': 'Aula virtual', 'type': 'room', 'id': 1, ...
```
diff --git a/cli/cli.py b/cli/cli.py
index 0e34cd0..2fdabf0 100644
--- a/cli/cli.py
+++ b/cli/cli.py
@@ -20,7 +20,7 @@ from cli.objects.center import OgCenter
from cli.objects.room import OgRoom
from cli.objects.folder import OgFolder
from cli.objects.session import OgSession
-from config import cfg
+from cli.config import cfg
import argparse
import requests
import sys
@@ -82,7 +82,7 @@ class OgCLI():
self.rest = OgREST(cfg['ip'], cfg['port'], cfg['api_token'])
def list(self, args):
- choices = ['clients', 'scope', 'modes', 'hardware',
+ choices = ['clients', 'scopes', 'modes', 'hardware',
'client', 'images', 'disks', 'servers', 'repos', 'live']
parser = argparse.ArgumentParser(prog='ogcli list')
parser.add_argument('item', choices=choices)
@@ -102,7 +102,7 @@ class OgCLI():
ret = OgClient.list_client_hardware(self.rest, args[1:])
elif parsed_args.item == 'modes':
ret = OgModes.list_available_modes(self.rest)
- elif parsed_args.item == 'scope':
+ elif parsed_args.item == 'scopes':
ret = OgScope.list_scopes(self.rest, args[1:])
elif parsed_args.item == 'images':
ret = OgImage.list_images(self.rest)
diff --git a/config.py b/cli/config.py
index 5a79698..5a79698 100755..100644
--- a/config.py
+++ b/cli/config.py
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