change layout and populate pages

This commit is contained in:
2026-10-02 22:02:25 +02:00
parent b3217f480b
commit 0c86a95df6
16 changed files with 43 additions and 28 deletions
+13 -8
View File
@@ -44,8 +44,11 @@ def init_function() -> None:
# |___|_|_|_|\_/|___|_| |___|__,|_|
def page_path(hostname: str) -> str:
return DIR_PATH + f"{hostname}.json"
def page_path(hostname: str, group: str=None) -> str:
if group and os.path.exists(DIR_PATH + group):
return DIR_PATH + group + f"/{hostname}.json"
else:
return DIR_PATH + f"{hostname}.json"
# checks if the executed command needs a "name" argument
def name_required() -> bool:
@@ -76,6 +79,7 @@ def parse_args() -> dict:
parser.add_argument("--ipv6", required=False)
parser.add_argument("--os", required=False)
parser.add_argument("--desc", required=False)
parser.add_argument("--group", required=False)
parser.add_argument("--force", required=False,
action='store_true')
@@ -173,11 +177,12 @@ def add_page(args: dict):
for k in KEY_ORDER:
if k in args and args[k]:
data[k] = args[k]
try:
if os.path.exists(page_path(data["name"])) and not args["force"]:
if os.path.exists(page_path(data["name"], args["group"])) and not args["force"]:
print_error(f"Page {data['name']} already exists, use --force to overwrite.")
exit()
with open(page_path(data["name"]), "w") as fp:
with open(page_path(data["name"], args["group"]), "w") as fp:
json.dump(data, fp, indent=4)
except FileNotFoundError:
print_error("Page-Path corrupted, restart mm.")
@@ -238,10 +243,10 @@ def list_pages():
# List groups
groups = get_groups()
for group in groups:
print(f"{bcolors.BOLD}{group}{bcolors.ENDC}")
print(f"{bcolors.BOLD}--- {group} ---{bcolors.ENDC}")
for dir_item, is_last in with_last(os.scandir(DIR_PATH + group)):
prefix = "`--" if is_last else "|--"
print(f"{bcolors.BOLD}{bcolors.BLUE}{prefix}+ {bcolors.ENDC}{dir_item.name[:-5]}")
# prefix = "`--" if is_last else "|--"
print(f"{bcolors.BOLD}{bcolors.BLUE}+ {bcolors.ENDC}{dir_item.name[:-5]}")
except FileNotFoundError:
print_error("Page-Path corrupted, restart mm.")
@@ -255,7 +260,7 @@ match args["action"]:
case "rm": delete_item(args["name"])
case "view": print_page(args["name"])
case "ls": list_pages()
case "test": print(get_groups())
case "test": print(args)
case _: print_welcome()