-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
executable file
·74 lines (58 loc) · 2.25 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
""" cli.py
Command-line interface for PriorityStoreLite. Requires click
$ pip3 install click
Author: Brian Tuan
"""
import click
from api import PriorityStoreLite
from pprint import PrettyPrinter
@click.command()
@click.option("-d", "--config_dir", help="Path to directory containing configuration files.")
@click.option("-c", "--command", help="PriorityStore API command.", required=True)
@click.option("-v", "--verbose", default=True, is_flag=True, help="Toggle for verbosity.")
def run(command, config_dir, verbose):
if not config_dir:
config_dir = "config"
psl = PriorityStoreLite(config_dir)
p = PrettyPrinter(indent=4)
cmd = command.strip().split(' ')
if cmd[0] == 'ls':
print("Listing files...")
p.pprint(psl.list_files())
if cmd[0] == 'info':
print("Details on the system...")
psl.print_stats()
#sys.stdout = Logger()
elif cmd[0] == 'del':
if len(cmd) != 2:
print('ERROR: del command requires two arguments.')
rc = psl.delete_file(cmd[1])
if rc is None:
print('ERROR: {} does not exist in the filesystem.'.format(cmd[1]))
elif cmd[0] == 'get':
if len(cmd) == 2:
rc = psl.retrieve_file(cmd[1])
if rc is None:
print('ERROR: {} does not exist in the filesystem.'.format(cmd[1]))
elif len(cmd) == 3:
rc = psl.retrieve_file(cmd[1], output=cmd[2])
if rc is None:
print('ERROR: {} does not exist in the filesystem.'.format(cmd[1]))
elif cmd[0] == 'put':
if len(cmd) == 2:
rc = psl.create_file(cmd[1])
if rc is None:
print('ERROR: {} already exists in the filesystem.'.format(cmd[1]))
elif len(cmd) == 3:
rc = psl.create_file(cmd[1], node=cmd[2])
if rc is None:
print('ERROR: {} already exists in the filesystem, storage is full, '.format(cmd[1]) + ' OR ' +
'{} is not a valid user@FQDN specification.'.format(cmd[2]))
else:
print('ERROR: syntax --- ./cli.py put <filename> <node>')
else:
print("Command not recognized: " + command)
return psl
if __name__ == '__main__':
run()