mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-09-29 03:22:21 +02:00
Squash Odysseus development history
This commit is contained in:
+33
-15
@@ -13,31 +13,47 @@ import json
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from src.constants import MEMORY_FILE, SKILLS_FILE
|
||||
|
||||
|
||||
def claim_json_entries(entries, owner):
|
||||
count = 0
|
||||
for entry in entries:
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
if not entry.get("owner"):
|
||||
entry["owner"] = owner
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
def owner_arg(argv):
|
||||
if len(argv) < 2 or not argv[1].strip():
|
||||
return None
|
||||
return argv[1].strip()
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
owner = owner_arg(sys.argv)
|
||||
if not owner:
|
||||
print("Usage: python scripts/claim_ownerless.py <username>")
|
||||
sys.exit(1)
|
||||
|
||||
owner = sys.argv[1]
|
||||
print(f"Claiming all ownerless data for: {owner}\n")
|
||||
|
||||
# 1. Memories (JSON files)
|
||||
for label, path in [
|
||||
("memory.json", "data/memory.json"),
|
||||
("skills.json", "data/skills.json"),
|
||||
("memory.json", MEMORY_FILE),
|
||||
("skills.json", SKILLS_FILE),
|
||||
]:
|
||||
if not os.path.exists(path):
|
||||
print(f" {label}: not found, skipping")
|
||||
continue
|
||||
with open(path, "r") as f:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
entries = json.load(f)
|
||||
count = 0
|
||||
for e in entries:
|
||||
if not e.get("owner"):
|
||||
e["owner"] = owner
|
||||
count += 1
|
||||
count = claim_json_entries(entries, owner)
|
||||
if count:
|
||||
with open(path, "w") as f:
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
json.dump(entries, f, ensure_ascii=False, indent=2)
|
||||
print(f" {label}: claimed {count} entries")
|
||||
|
||||
@@ -58,10 +74,12 @@ def main():
|
||||
count = db.query(Session).filter(Session.owner == None).update({"owner": owner})
|
||||
print(f" sessions: claimed {count}")
|
||||
|
||||
# Documents
|
||||
count = db.query(Document).filter(Document.session_id.in_(
|
||||
db.query(Session.id).filter(Session.owner == owner)
|
||||
)).update({"session_id": Document.session_id}, synchronize_session=False)
|
||||
# Documents (have their own owner column; claim the ownerless ones,
|
||||
# mirroring the sessions/gallery/comparisons blocks). The old query set
|
||||
# session_id to itself — a no-op — and never set owner, so ownerless
|
||||
# documents stayed ownerless and invisible in the user's Library.
|
||||
count = db.query(Document).filter(Document.owner == None).update({"owner": owner})
|
||||
print(f" documents: claimed {count}")
|
||||
|
||||
# Gallery
|
||||
if GalleryImage:
|
||||
|
||||
Reference in New Issue
Block a user