From 8a24550db07e13c30ec8487bb58383b47f8c7a16 Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:15:47 +0330 Subject: [PATCH] Import source: sort_root Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- sort_root.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 sort_root.py diff --git a/sort_root.py b/sort_root.py new file mode 100644 index 0000000..67cc773 --- /dev/null +++ b/sort_root.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +"""Sort the gdrive root (parent of UH) into type folders.""" +import json, subprocess + +REMOTE = "gdrive:" +BASE = ["rclone"] + +SKIP_DIRS = {"Google AI Studio", "Photos", "UH", "Untitled folder", + "Models", "Videos", "Archives", "Docs", "Config", "ZIM"} + +def rclone(*args): + cmd = BASE + list(args) + print(f" $ {' '.join(str(a) for a in cmd)}") + r = subprocess.run(cmd, capture_output=True, text=True) + if r.returncode != 0: + print(f" ERROR: {r.stderr.strip()}") + return r.returncode == 0 + +def classify(name: str) -> str: + ext = name.rsplit(".", 1)[-1].lower() if "." in name else "" + if ext == "gguf": + return "Models" + if ext == "zim": + return "ZIM" + if ext in ("mp4", "mkv", "avi", "mov", "webm"): + return "Videos" + if ext in ("zip", "rar", "7z", "tar", "gz", "bz2"): + return "Archives" + if ext in ("conf", "ovpn", "cfg", "ini", "toml", "yaml", "yml"): + return "Config" + if ext in ("docx", "doc", "pdf", "txt", "md", "csv", "xlsx"): + return "Docs" + return "Other" + +print("Listing root...") +r = subprocess.run(BASE + ["lsjson", REMOTE], capture_output=True, text=True) +files = json.loads(r.stdout) + +groups: dict[str, list] = {} +for f in files: + if f["IsDir"]: + print(f" [skip dir] {f['Name']}") + continue + folder = classify(f["Name"]) + groups.setdefault(folder, []).append(f["Name"]) + +print("\n=== Move plan ===") +for folder, names in sorted(groups.items()): + print(f"\nšŸ“ {folder}/ ({len(names)} files)") + for n in names: + print(f" {n}") + +print("\n=== Executing ===") +created: set = set() +ok = err = 0 +for folder, names in sorted(groups.items()): + if folder not in created: + print(f"\nCreating folder: {folder}/") + rclone("mkdir", f"{REMOTE}{folder}") + created.add(folder) + for name in names: + print(f"\nMoving → {folder}/{name[:70]}") + if rclone("moveto", f"{REMOTE}{name}", f"{REMOTE}{folder}/{name}"): + ok += 1 + else: + err += 1 + +print(f"\n=== Done: {ok} moved, {err} errors ===")