diff --git a/drive/app/unstable/listeh.py b/drive/app/unstable/listeh.py new file mode 100644 index 00000000..f30c75e5 --- /dev/null +++ b/drive/app/unstable/listeh.py @@ -0,0 +1,38 @@ +from argparse import ArgumentParser +from pathlib import Path +import asyncio +import re +import sys + +from ..lib import create_default_drive + + +async def main(args: list[str]) -> int: + parser = ArgumentParser("lseh") + parser.add_argument("path", type=str) + kwargs = parser.parse_args(args) + path = Path(kwargs.path) + + async with create_default_drive() as drive: + parent = await drive.get_node_by_path(path) + children = await drive.get_children(parent) + g = ((to_eid(_.name), _.name) for _ in children) + pair_list = [(eid, name) for eid, name in g if eid is not None] + pair_list.sort(reverse=True) + name_list = (name for _eid, name in pair_list) + for name in name_list: + print(name) + + return 0 + + +def to_eid(name: str) -> int | None: + m = re.search(r"\[(\d+)\]\.7z$", name) + if not m: + return None + eid = int(m.group(1)) + return eid + + +if __name__ == "__main__": + sys.exit(asyncio.run(main(sys.argv[1:]))) diff --git a/drive/legacy/shell/sort.py b/drive/legacy/shell/sort.py deleted file mode 100755 index 033ef09d..00000000 --- a/drive/legacy/shell/sort.py +++ /dev/null @@ -1,28 +0,0 @@ -#! /usr/bin/env python3 - -import json -import sys -import re - - -def main(): - name_list: list[tuple[int, str]] = [] - data: dict[str, str] = json.load(sys.stdin) - - for _k, name in data.items(): - m = re.search(r'\[(\d+)\]\.7z$', name) - if not m: - continue - eid = int(m.group(1)) - name_list.append((eid, name)) - - name_list.sort(reverse=True) - - for eid, name in name_list: - print(name) - - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/drive/listeh.sh b/drive/listeh.sh new file mode 100755 index 00000000..5c343ef3 --- /dev/null +++ b/drive/listeh.sh @@ -0,0 +1,3 @@ +#! /bin/sh + +poetry run -- python3 -m app.unstable.listeh "$@"