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
+12 -7
View File
@@ -44,7 +44,10 @@ def init_function() -> None:
# |___|_|_|_|\_/|___|_| |___|__,|_| # |___|_|_|_|\_/|___|_| |___|__,|_|
def page_path(hostname: str) -> str: 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" return DIR_PATH + f"{hostname}.json"
# checks if the executed command needs a "name" argument # checks if the executed command needs a "name" argument
@@ -76,6 +79,7 @@ def parse_args() -> dict:
parser.add_argument("--ipv6", required=False) parser.add_argument("--ipv6", required=False)
parser.add_argument("--os", required=False) parser.add_argument("--os", required=False)
parser.add_argument("--desc", required=False) parser.add_argument("--desc", required=False)
parser.add_argument("--group", required=False)
parser.add_argument("--force", required=False, parser.add_argument("--force", required=False,
action='store_true') action='store_true')
@@ -173,11 +177,12 @@ def add_page(args: dict):
for k in KEY_ORDER: for k in KEY_ORDER:
if k in args and args[k]: if k in args and args[k]:
data[k] = args[k] data[k] = args[k]
try: 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.") print_error(f"Page {data['name']} already exists, use --force to overwrite.")
exit() 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) json.dump(data, fp, indent=4)
except FileNotFoundError: except FileNotFoundError:
print_error("Page-Path corrupted, restart mm.") print_error("Page-Path corrupted, restart mm.")
@@ -238,10 +243,10 @@ def list_pages():
# List groups # List groups
groups = get_groups() groups = get_groups()
for group in 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)): for dir_item, is_last in with_last(os.scandir(DIR_PATH + group)):
prefix = "`--" if is_last else "|--" # prefix = "`--" if is_last else "|--"
print(f"{bcolors.BOLD}{bcolors.BLUE}{prefix}+ {bcolors.ENDC}{dir_item.name[:-5]}") print(f"{bcolors.BOLD}{bcolors.BLUE}+ {bcolors.ENDC}{dir_item.name[:-5]}")
except FileNotFoundError: except FileNotFoundError:
print_error("Page-Path corrupted, restart mm.") print_error("Page-Path corrupted, restart mm.")
@@ -255,7 +260,7 @@ match args["action"]:
case "rm": delete_item(args["name"]) case "rm": delete_item(args["name"])
case "view": print_page(args["name"]) case "view": print_page(args["name"])
case "ls": list_pages() case "ls": list_pages()
case "test": print(get_groups()) case "test": print(args)
case _: print_welcome() case _: print_welcome()
-3
View File
@@ -1,3 +0,0 @@
{
"name": "Strato3"
}
+3
View File
@@ -0,0 +1,3 @@
{
"name": "strato1"
}
+3
View File
@@ -0,0 +1,3 @@
{
"name": "strato2"
}
+3
View File
@@ -0,0 +1,3 @@
{
"name": "strato3"
}
+3
View File
@@ -0,0 +1,3 @@
{
"name": "strato4"
}
+3
View File
@@ -0,0 +1,3 @@
{
"name": "strato5"
}
+3
View File
@@ -0,0 +1,3 @@
{
"name": "strato6"
}
-3
View File
@@ -1,3 +0,0 @@
{
"name": "test"
}
+3
View File
@@ -0,0 +1,3 @@
{
"name": "fhain1"
}
-4
View File
@@ -1,4 +0,0 @@
{
"name": "onpremdmz123",
"ipv4": "192.168.178.121"
}
+3
View File
@@ -0,0 +1,3 @@
{
"name": "pi1"
}
+3
View File
@@ -0,0 +1,3 @@
{
"name": "pi2"
}
-4
View File
@@ -1,4 +0,0 @@
{
"name": "pi3",
"os": "Alpine-Linux"
}
+3
View File
@@ -0,0 +1,3 @@
{
"name": "machine"
}
-6
View File
@@ -1,6 +0,0 @@
{
"name": "machine1",
"ipv4": "192.168.178.3",
"ipv6": "fe80::ef13:270b:7cb6:d728",
"os": "Automation and Testserver"
}