add group logic and sort ls output
This commit is contained in:
@@ -99,17 +99,6 @@ def get_standalone_pages() -> List[str]:
|
|||||||
pages = [e.name for e in entries if e.is_file()]
|
pages = [e.name for e in entries if e.is_file()]
|
||||||
return pages
|
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:
|
def get_mm_info() -> dict:
|
||||||
dirname = os.path.dirname(__file__)
|
dirname = os.path.dirname(__file__)
|
||||||
absolute_path = os.path.join(dirname, DIR_PATH)
|
absolute_path = os.path.join(dirname, DIR_PATH)
|
||||||
@@ -162,10 +151,10 @@ def edit_page(args: dict):
|
|||||||
data[k] = args[k]
|
data[k] = args[k]
|
||||||
try:
|
try:
|
||||||
page = {}
|
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 = json.load(fp)
|
||||||
page.update(data)
|
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)
|
json.dump(page, fp, indent=4)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print_error(f"Page {data['name']} doesn't exist.")
|
print_error(f"Page {data['name']} doesn't exist.")
|
||||||
@@ -237,16 +226,15 @@ def list_pages():
|
|||||||
try:
|
try:
|
||||||
# List standalone Pages
|
# List standalone Pages
|
||||||
pages = get_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]}")
|
print(f"{bcolors.BOLD}{bcolors.BLUE}+ {bcolors.ENDC}{page[:-5]}")
|
||||||
|
|
||||||
# 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 in sorted(os.listdir(DIR_PATH + group)):
|
||||||
# prefix = "`--" if is_last else "|--"
|
print(f"{bcolors.BOLD}{bcolors.BLUE}+ {bcolors.ENDC}{dir_item[:-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.")
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"name": "fhain1"
|
"name": "fhain1",
|
||||||
|
"desc": "automation"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user