add group logic and sort ls output

This commit is contained in:
2026-10-02 22:18:40 +02:00
parent 0c86a95df6
commit 4917185c81
2 changed files with 7 additions and 18 deletions
+5 -17
View File
@@ -99,17 +99,6 @@ def get_standalone_pages() -> List[str]:
pages = [e.name for e in entries if e.is_file()]
return pages
def with_last(iterable):
it = iter(iterable)
try:
prev = next(it)
except StopIteration:
return
for item in it:
yield prev, False
prev = item
yield prev, True
def get_mm_info() -> dict:
dirname = os.path.dirname(__file__)
absolute_path = os.path.join(dirname, DIR_PATH)
@@ -162,10 +151,10 @@ def edit_page(args: dict):
data[k] = args[k]
try:
page = {}
with open(page_path(data["name"]), "r") as fp:
with open(page_path(data["name"], args["group"]), "r") as fp:
page = json.load(fp)
page.update(data)
with open(page_path(data["name"]), "w") as fp:
with open(page_path(data["name"], args["group"]), "w") as fp:
json.dump(page, fp, indent=4)
except FileNotFoundError:
print_error(f"Page {data['name']} doesn't exist.")
@@ -237,16 +226,15 @@ def list_pages():
try:
# List standalone Pages
pages = get_standalone_pages()
for page in pages:
for page in sorted(pages):
print(f"{bcolors.BOLD}{bcolors.BLUE}+ {bcolors.ENDC}{page[:-5]}")
# List groups
groups = get_groups()
for group in groups:
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}+ {bcolors.ENDC}{dir_item.name[:-5]}")
for dir_item in sorted(os.listdir(DIR_PATH + group)):
print(f"{bcolors.BOLD}{bcolors.BLUE}+ {bcolors.ENDC}{dir_item[:-5]}")
except FileNotFoundError:
print_error("Page-Path corrupted, restart mm.")