Import source: sort_root
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
@@ -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 ===")
|
||||
Reference in New Issue
Block a user