forked from eshepelyuk/cmak-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson2zk.py
33 lines (23 loc) · 826 Bytes
/
json2zk.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
import click
import logging
from kazoo.client import KazooClient
from pathlib import Path
FORMAT = '%(asctime)-15s %(message)s'
logging.basicConfig(format=FORMAT, level=logging.INFO)
@click.command()
@click.argument("zk_url", type=str)
@click.argument("zk_root", type=str)
@click.argument('json_dir', type=click.Path(exists=True, dir_okay=True, file_okay=False))
def json2zk(zk_url, zk_root, json_dir):
zk = KazooClient(hosts=zk_url)
zk.start()
for json_file in Path(json_dir).glob("*.json"):
dst = f"{zk_root}/{json_file.stem}"
logging.info(f"Setting {dst} from {json_file}.")
if zk.exists(dst):
zk.set(dst, json_file.read_bytes())
else:
zk.create(dst, json_file.read_bytes(), makepath=True)
zk.stop()
if __name__ == "__main__":
json2zk()