-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
56 lines (46 loc) · 1.55 KB
/
client.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
#!/usr/bin/env python3
import sys
if sys.version_info < (3, 6):
print('Use python >= 3.6', file=sys.stderr)
sys.exit(1)
import os
import argparse
import textwrap
import json
try:
from storage.storageclient import StorageClient
except Exception as e:
print(f"storage module is not found {str(e)}")
sys.exit(1)
def parse_argument():
"""Parsing arguments"""
parser = argparse.ArgumentParser(
prog='client.py',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''\
Client part of KV storage
--------------------------------
commands while running:
auth authorize client
set {[-r,--raw],[-f,--file]} db_name key={json_value} send request to set value by key
get {[-r,--raw],[-f,--file]} db_name key1&key2 send request get value by key
exit exit client
'''))
return parser.parse_args()
def main():
"""Enter point of program"""
parser = parse_argument()
conf_path = StorageClient.config_path
if not os.path.exists(StorageClient.config_path):
print(f"settings {conf_path} not found")
sys.exit(1)
with open(conf_path, "r") as f:
conf = json.loads(f.read())
client = StorageClient(
conf["cluster_node_host"],
conf["cluster_node_port"],
with_checker=conf["with_checker"],
debug=conf["debug"])
client.run()
if __name__ == '__main__':
main()