kycli 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kycli-0.1.0/PKG-INFO +10 -0
- kycli-0.1.0/kycli/__init__.py +0 -0
- kycli-0.1.0/kycli/cli.py +56 -0
- kycli-0.1.0/kycli/kycore.c +11106 -0
- kycli-0.1.0/kycli.egg-info/PKG-INFO +10 -0
- kycli-0.1.0/kycli.egg-info/SOURCES.txt +10 -0
- kycli-0.1.0/kycli.egg-info/dependency_links.txt +1 -0
- kycli-0.1.0/kycli.egg-info/entry_points.txt +6 -0
- kycli-0.1.0/kycli.egg-info/top_level.txt +1 -0
- kycli-0.1.0/pyproject.toml +25 -0
- kycli-0.1.0/setup.cfg +4 -0
- kycli-0.1.0/setup.py +35 -0
kycli-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: kycli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Your KV store CLI tool
|
|
5
|
+
Author: Your Name
|
|
6
|
+
Author-email: you@example.com
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Cython
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
File without changes
|
kycli-0.1.0/kycli/cli.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
import pickle
|
|
4
|
+
from kycli.kycore import Kycore
|
|
5
|
+
|
|
6
|
+
DATA_FILE = "kvdata.pkl"
|
|
7
|
+
|
|
8
|
+
def load_data(kv):
|
|
9
|
+
import os
|
|
10
|
+
if os.path.exists(kv.data_path) and os.path.getsize(kv.data_path) > 0:
|
|
11
|
+
with open(kv.data_path, "rb") as f:
|
|
12
|
+
store_data = pickle.load(f)
|
|
13
|
+
kv.load_store(store_data)
|
|
14
|
+
|
|
15
|
+
def save_data(kv):
|
|
16
|
+
with open(DATA_FILE, "wb") as f:
|
|
17
|
+
pickle.dump(kv.store, f)
|
|
18
|
+
|
|
19
|
+
def print_help():
|
|
20
|
+
print("""
|
|
21
|
+
Available commands:
|
|
22
|
+
kys <key> <value> - Save key-value
|
|
23
|
+
kyg <key> - Get value by key
|
|
24
|
+
kyl - List keys
|
|
25
|
+
kyd <key> - Delete key
|
|
26
|
+
kyh - Help
|
|
27
|
+
""")
|
|
28
|
+
|
|
29
|
+
def main():
|
|
30
|
+
kv = Kycore()
|
|
31
|
+
load_data(kv)
|
|
32
|
+
|
|
33
|
+
args = sys.argv[1:]
|
|
34
|
+
prog = os.path.basename(sys.argv[0])
|
|
35
|
+
|
|
36
|
+
if prog in ["kys", "save"] and len(args) == 2:
|
|
37
|
+
kv.save(args[0], args[1])
|
|
38
|
+
save_data(kv)
|
|
39
|
+
print(f"Saved: {args[0]}")
|
|
40
|
+
|
|
41
|
+
elif prog in ["kyg", "getkey"] and len(args) == 1:
|
|
42
|
+
print(kv.getkey(args[0]))
|
|
43
|
+
|
|
44
|
+
elif prog in ["kyd", "delete"] and len(args) == 1:
|
|
45
|
+
print(kv.delete(args[0]))
|
|
46
|
+
save_data(kv)
|
|
47
|
+
|
|
48
|
+
elif prog in ["kyl", "listkeys"]:
|
|
49
|
+
print("Keys:", ", ".join(kv.listkeys()))
|
|
50
|
+
|
|
51
|
+
elif prog in ["kyh", "help"]:
|
|
52
|
+
print_help()
|
|
53
|
+
|
|
54
|
+
else:
|
|
55
|
+
print("Invalid command or arguments.")
|
|
56
|
+
print_help()
|