forked from gbit-is/ruv_downloader_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_cache.py
executable file
·69 lines (48 loc) · 1.21 KB
/
manage_cache.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
#!/usr/bin/env python
import requests
import json
import dbm
import os
import sys
import re
import os
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
from ruv_downloader import manage_kvs, pprint
kvs = manage_kvs()
def print_help():
print()
print("usage is: ")
print(sys.argv[0] + " <list|get|delete> [key] ")
print()
print(sys.argv[0] + " list # lists all keys in cache")
print(sys.argv[0] + " get {name-of-key} # prints out the information of that key")
print(sys.argv[0] + " delete {name-of-key} # delete a key")
print()
if len(sys.argv) == 1:
print_help()
exit()
arg_1 = sys.argv[1].lower()
if arg_1 == "list":
kvs.list_keys(True)
elif arg_1 == "get":
if len(sys.argv) != 3:
print_help()
exit()
key = sys.argv[2]
if kvs.exists(key):
key_data, is_json = kvs.decode_key(key)
if is_json:
pprint(key_data,False)
else:
print(key_data)
else:
print("Key " + key + " does not exist")
elif arg_1 == "delete":
if len(sys.argv) != 3:
print_help()
exit()
key = sys.argv[2]
kvs.delete_key(key)
else:
print_help()
exit()