-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup-workspaces.py
More file actions
executable file
·69 lines (61 loc) · 2.63 KB
/
Copy pathcleanup-workspaces.py
File metadata and controls
executable file
·69 lines (61 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
import os
import shutil
import sqlite3
def main():
script_dir = os.path.dirname(os.path.abspath(__file__))
repo_root = os.path.abspath(os.path.join(script_dir, ".."))
# Locate DB
db_path = os.getenv("DATABASE_PATH")
if not db_path:
db_path = os.path.join(repo_root, "apps", "api", "state.db")
print(f"Using database: {db_path}")
if os.path.exists(db_path):
conn = sqlite3.connect(db_path)
try:
cursor = conn.cursor()
# Fetch all workspace local paths before truncating
try:
cursor.execute("SELECT local_path FROM engineering_workspaces")
paths = [row[0] for row in cursor.fetchall() if row[0]]
except Exception as e:
print(f"Could not fetch workspaces: {e}")
paths = []
# Delete directories
for path in paths:
if os.path.exists(path):
print(f"Deleting workspace directory: {path}")
try:
shutil.rmtree(path)
except Exception as e:
print(f"Error deleting {path}: {e}")
# Truncate tables
tables_to_truncate = ["engineering_workspaces", "agent_contexts", "chat_messages"]
for table in tables_to_truncate:
print(f"Truncating table: {table}")
try:
cursor.execute(f"DELETE FROM {table}")
except Exception as e:
print(f"Error truncating table {table}: {e}")
conn.commit()
print("Database tables truncated successfully.")
finally:
conn.close()
else:
print("Database file does not exist, skipping database truncation.")
# Also clean ~/workspace and ~/wright directories if they exist
home_dir = os.path.expanduser("~")
for parent_name in ["workspace", "wright"]:
parent_dir = os.path.join(home_dir, parent_name)
if os.path.exists(parent_dir) and os.path.isdir(parent_dir):
print(f"Cleaning subdirectories under: {parent_dir}")
for item in os.listdir(parent_dir):
item_path = os.path.join(parent_dir, item)
if os.path.isdir(item_path) and not item.startswith("."):
print(f"Deleting directory: {item_path}")
try:
shutil.rmtree(item_path)
except Exception as e:
print(f"Error deleting {item_path}: {e}")
if __name__ == "__main__":
main()