Skip to content

Commit

Permalink
chore: activating storaged hosts optmized
Browse files Browse the repository at this point in the history
  • Loading branch information
wey-gu committed May 24, 2024
1 parent 0a30b93 commit 0d81069
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/nebulagraph_lite/nebulagraph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import json
import shutil
import socket
import subprocess
Expand Down Expand Up @@ -482,8 +483,16 @@ def activate_storaged(self):
raise Exception("graphd did not become ready in 50 seconds")
with connection_pool.session_context("root", "nebula") as session:
session.execute(f'ADD HOSTS "{self.host}":9779')
result = session.execute_json("SHOW HOSTS")
fancy_dict_print({"SHOW HOSTS": result})
time.sleep(12)
result_byte = session.execute_json("SHOW HOSTS")
result = result_byte.decode("utf-8")
result_dict = json.loads(result)
fancy_dict_print(
{
"Message": "Activating storaged...",
"Result of `SHOW HOSTS`": result_dict,
}
)

def load_basketballplayer_dataset(self):
# udocker_create_command = f"ps | grep nebula-console || udocker --debug --allow-root create --name=nebula-console {self._container_image_prefix}vesoft/nebula-console:v3"
Expand Down
29 changes: 24 additions & 5 deletions src/nebulagraph_lite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,36 @@ def fancy_print(text: str, color: str = "random") -> None:
print(f"\033[1;3;{color}m{text}\033[0m")


def fancy_dict_print(d: dict, color: str = None) -> None:
def fancy_dict_print(d: dict, color: str = None, indent: int = 0) -> None:
"""
Print a dict in color from COLORS_rgb.
Recursively print a dict in color from COLORS_rgb, supporting nested dictionaries and lists.
"""
color_keys = list(COLORS_rgb.keys())
indent_space = " " * indent
for i, (key, value) in enumerate(d.items()):
if color is None or color not in COLORS_rgb:
color = COLORS_rgb[color_keys[i % len(color_keys)]]
selected_color = COLORS_rgb[color_keys[i % len(color_keys)]]
else:
color = COLORS_rgb[color]
print(f"\033[1;3;{color}m{key}: {value}\033[0m")
selected_color = COLORS_rgb[color]
if isinstance(value, dict):
print(f"\033[1;3;{selected_color}m{indent_space}{key}:\033[0m")
fancy_dict_print(value, color, indent + 4)
elif isinstance(value, list):
print(f"\033[1;3;{selected_color}m{indent_space}{key}:\033[0m")
if not all(isinstance(item, (dict, list)) for item in value):
print(
f"\033[1;3;{selected_color}m{indent_space} {', '.join(map(str, value))}\033[0m"
)
else:
for item in value:
if isinstance(item, dict):
fancy_dict_print(item, color, indent + 4)
else:
print(
f"\033[1;3;{selected_color}m{indent_space} {item}\033[0m"
)
else:
print(f"\033[1;3;{selected_color}m{indent_space}{key}: {value}\033[0m")


def get_pid_by_port(port):
Expand Down

0 comments on commit 0d81069

Please sign in to comment.