Skip to content

Commit

Permalink
fix pprobe toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyu17 committed Jun 14, 2024
1 parent 887a4f9 commit 4659161
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 37 deletions.
50 changes: 18 additions & 32 deletions pprobe/toggle/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
"""


@dataclass
class ToggleStatus:
name: str
status: str
default_status: str
# @dataclass
# class ToggleStatus:
# name: str
# status: str
# default_status: str


class ToggleManager():
Expand All @@ -42,9 +42,6 @@ def __init__(self):
self.default_toggle_path = self.get_path("hook.toggle.default")
self.running_toggle_path = self.get_path("hook.toggle.running")
self._init_toggles()
print(self.default_toggle)
print("===================")
print(self.running_toggle)

def get_path(self, toggle_filename):
with importlib.resources.path("pprobe.toggle", "__init__.py") as toggle_path:
Expand Down Expand Up @@ -122,7 +119,6 @@ def _save_toggles_to_file(self, file_path, toggle_dict):
print(f"Error writing to {file_path}: {e}")


# TODO
def show_status(self):
"""
when printing:
Expand All @@ -131,33 +127,22 @@ def show_status(self):
"""

print(HELLO_PPROBE)


def colorize(value):
"""Return the value in green if True, in red if False."""
if value in (True, "True"):
return f"\033[92m{value}\033[0m" # 绿色
elif value in (False, "False"):
return f"\033[91m{value}\033[0m" # 红色
return value

status_in_color = []

for name, value in self.running_toggle.items():
status = colorize(value)
default_value = self.default_toggle.get(name, "False")
status = ToggleStatus(name, value, default_value)
status_in_color.append(status)


# for entry in flag_data:
# status = entry.value
# if entry.value == "True":
# # True显示为绿色
# status = f"\033[92m{entry.value}\033[0m" # 绿色
# elif entry.value == "False":
# # False显示为红色
# status = f"\033[91m{entry.value}\033[0m" # 红色

# default_status = entry.default_value
# if entry.default_value == "True":
# # True显示为绿色
# default_status = f"\033[92m{entry.default_value}\033[0m" # 绿色
# elif entry.default_value == "False":
# # False显示为红色
# default_status = f"\033[91m{entry.default_value}\033[0m" # 红色

# status_in_color.append((entry.name, status, default_status))
default_status = colorize(default_value)
status_in_color.append((name, status, default_status))

table = tabulate(
status_in_color,
Expand All @@ -166,6 +151,7 @@ def show_status(self):
)
print(f"\n{table}\n")


def main():
parser = argparse.ArgumentParser(description="Enable and Disable Options")
parser.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion pprobe/toggle/hook.toggle.default
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
AAA=True
BBB=True
BBB=False
2 changes: 0 additions & 2 deletions pprobe/toggle/hook.toggle.running

This file was deleted.

5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def copy_pth(self):
def copy_toggle(self):
src_file = 'pprobe/toggle/hook.toggle.default'
dst_file = 'pprobe/toggle/hook.toggle.running'
dst_build_file = os.path.join(self.build_lib, dst_file)
try:
shutil.copyfile(src_file, dst_file)
print(f"Copied {src_file} to {dst_file}")
shutil.copyfile(src_file, dst_build_file)
print(f"Copied {src_file} to {dst_build_file}")
except FileNotFoundError:
print(f"Source file {src_file} does not exist")

Expand Down

0 comments on commit 4659161

Please sign in to comment.