senthil2421 commited on
Commit
9d7a165
·
1 Parent(s): 8302f42

arch: remove unused projects folder from cloud_backend

Browse files
projects/__init__.py DELETED
File without changes
projects/__pycache__/__init__.cpython-310.pyc DELETED
Binary file (143 Bytes)
 
projects/__pycache__/registry.cpython-310.pyc DELETED
Binary file (2.76 kB)
 
projects/__pycache__/service.cpython-310.pyc DELETED
Binary file (5.61 kB)
 
projects/registry.py DELETED
@@ -1,73 +0,0 @@
1
- """projects/registry.py — Project persistence in SQLite."""
2
-
3
- from __future__ import annotations
4
-
5
- from datetime import datetime, timezone
6
-
7
- from database.connection import get_db
8
- from models.project import Project
9
-
10
-
11
- async def upsert_project(project: Project) -> None:
12
- db = await get_db()
13
- await db.execute(
14
- """INSERT INTO projects (id, name, path, created_at, last_opened, status)
15
- VALUES (?,?,?,?,?,?)
16
- ON CONFLICT(id) DO UPDATE SET
17
- name=excluded.name,
18
- path=excluded.path,
19
- last_opened=excluded.last_opened,
20
- status=excluded.status
21
- """,
22
- (
23
- project.id,
24
- project.name,
25
- project.path,
26
- project.created_at,
27
- project.last_opened,
28
- project.status,
29
- ),
30
- )
31
- await db.commit()
32
-
33
-
34
- async def list_projects(limit: int = 200, offset: int = 0) -> list[Project]:
35
- db = await get_db()
36
- async with db.execute(
37
- """SELECT id, name, path, created_at, last_opened, status
38
- FROM projects
39
- ORDER BY datetime(last_opened) DESC
40
- LIMIT ? OFFSET ?
41
- """,
42
- (limit, offset),
43
- ) as cur:
44
- rows = await cur.fetchall()
45
- return [Project(**dict(r)) for r in rows]
46
-
47
-
48
- async def delete_project(project_id: str) -> bool:
49
- db = await get_db()
50
- cur = await db.execute("DELETE FROM projects WHERE id = ?", (project_id,))
51
- await db.commit()
52
- return (cur.rowcount or 0) > 0
53
-
54
-
55
- async def get_project(project_id: str) -> Project | None:
56
- db = await get_db()
57
- async with db.execute(
58
- "SELECT id, name, path, created_at, last_opened, status FROM projects WHERE id = ?",
59
- (project_id,),
60
- ) as cur:
61
- row = await cur.fetchone()
62
- return Project(**dict(row)) if row else None
63
-
64
-
65
- async def touch_last_opened(project_id: str) -> None:
66
- db = await get_db()
67
- now = datetime.now(timezone.utc).isoformat()
68
- await db.execute(
69
- "UPDATE projects SET last_opened = ? WHERE id = ?",
70
- (now, project_id),
71
- )
72
- await db.commit()
73
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
projects/service.py DELETED
@@ -1,186 +0,0 @@
1
- """
2
- projects/service.py — Active project session + model workspace linking.
3
-
4
- Tracks which project is currently open (via the `session` DB table) and
5
- copies freshly-downloaded model files into the project's models/ folder
6
- so the benchmark engine and other workspaces can locate them.
7
- """
8
- from __future__ import annotations
9
-
10
- import os
11
- import shutil
12
- import uuid
13
- from pathlib import Path
14
- from datetime import datetime, timezone
15
-
16
- from database.connection import get_db
17
- from observability.logger import get_logger, audit
18
- from models.model import Model, ModelMetrics
19
- from registry.registry import upsert_model
20
-
21
- log = get_logger("projects.service")
22
-
23
-
24
- async def import_local_model(
25
- name: str,
26
- task: str,
27
- framework: str,
28
- source_file_path: str
29
- ) -> Model:
30
- """Import a local model file into the active project."""
31
- project_id = await get_active_project_id()
32
- project_path = await get_active_project_path()
33
-
34
- if not project_id or not project_path:
35
- raise ValueError("No active project found. Please open a project first.")
36
-
37
- src = Path(source_file_path)
38
- if not src.exists():
39
- raise FileNotFoundError(f"Source model file not found: {source_file_path}")
40
-
41
- # Create destination directory in project
42
- model_id = f"local-{uuid.uuid4().hex[:12]}"
43
- dest_dir = Path(project_path) / "models" / model_id
44
- dest_dir.mkdir(parents=True, exist_ok=True)
45
-
46
- dest_path = dest_dir / src.name
47
- shutil.copy2(src, dest_path)
48
-
49
- # Calculate size
50
- size_bytes = dest_path.stat().st_size
51
- size_label = f"{size_bytes / (1024*1024):.1f} MB" if size_bytes > 1024*1024 else f"{size_bytes / 1024:.1f} KB"
52
-
53
- # Create model entry
54
- now = datetime.now(timezone.utc).isoformat()
55
- model = Model(
56
- id=model_id,
57
- name=name,
58
- task=task,
59
- framework=framework,
60
- source="local",
61
- provider="Local Import",
62
- size=size_bytes,
63
- size_label=size_label,
64
- local_path=str(dest_path),
65
- project_id=project_id,
66
- downloaded=True,
67
- status="cached",
68
- created_at=now,
69
- updated_at=now,
70
- metrics=ModelMetrics()
71
- )
72
-
73
- await upsert_model(model)
74
- await audit("model_imported_locally", model_id=model_id, payload={"name": name, "project_id": project_id})
75
- log.info("model_imported_locally", model_id=model_id, name=name, path=str(dest_path))
76
-
77
- return model
78
-
79
-
80
- # ── Session helpers ───────────────────────────────────────────────────────────
81
-
82
- async def set_active_project(project_id: str, project_path: str) -> None:
83
- """Persist the currently open project in the session table."""
84
- db = await get_db()
85
- await db.execute(
86
- "INSERT INTO session (key, value) VALUES ('active_project_id', ?)"
87
- " ON CONFLICT(key) DO UPDATE SET value=excluded.value",
88
- (project_id,),
89
- )
90
- await db.execute(
91
- "INSERT INTO session (key, value) VALUES ('active_project_path', ?)"
92
- " ON CONFLICT(key) DO UPDATE SET value=excluded.value",
93
- (project_path,),
94
- )
95
- await db.commit()
96
- log.info("active_project_set", project_id=project_id, path=project_path)
97
-
98
-
99
- async def get_active_project_id() -> str | None:
100
- """Return the ID of the currently open project, or None."""
101
- db = await get_db()
102
- async with db.execute(
103
- "SELECT value FROM session WHERE key = 'active_project_id'"
104
- ) as cur:
105
- row = await cur.fetchone()
106
- return row["value"] if row else None
107
-
108
-
109
- async def get_active_project_path() -> str | None:
110
- """Return the filesystem path of the currently open project, or None."""
111
- db = await get_db()
112
- async with db.execute(
113
- "SELECT value FROM session WHERE key = 'active_project_path'"
114
- ) as cur:
115
- row = await cur.fetchone()
116
- return row["value"] if row else None
117
-
118
-
119
- # ── Workspace model linking ───────────────────────────────────────────────────
120
-
121
- async def link_model_to_active_project(model_id: str, source_path: str) -> None:
122
- """Copy the downloaded model file into the active project's models/ folder.
123
-
124
- This is a best-effort operation — if no project is open, or if the copy
125
- fails for any reason, we log and continue rather than failing the download.
126
- """
127
- project_path = await get_active_project_path()
128
- if not project_path:
129
- log.debug("link_model_skipped_no_project", model_id=model_id)
130
- return
131
-
132
- src = Path(source_path)
133
- if not src.exists():
134
- log.warning("link_model_source_missing", model_id=model_id, path=source_path)
135
- return
136
-
137
- dest_dir = Path(project_path) / "models" / model_id
138
- dest_dir.mkdir(parents=True, exist_ok=True)
139
- dest = dest_dir / src.name
140
-
141
- if dest.exists():
142
- log.debug("link_model_already_exists", model_id=model_id, dest=str(dest))
143
- return
144
-
145
- try:
146
- shutil.copy2(src, dest)
147
- log.info("model_linked_to_project", model_id=model_id, project=project_path, dest=str(dest))
148
- except OSError as exc:
149
- log.warning("link_model_copy_failed", model_id=model_id, error=str(exc))
150
-
151
-
152
- async def link_dataset_to_active_project(dataset_id: str, source_path: str) -> None:
153
- """Copy the imported dataset folder into the active project's datasets/ folder.
154
-
155
- This is a best-effort operation — if no project is open, or if the copy
156
- fails for any reason, we log and continue rather than failing the import.
157
- """
158
- project_path = await get_active_project_path()
159
- if not project_path:
160
- log.debug("link_dataset_skipped_no_project", dataset_id=dataset_id)
161
- return
162
-
163
- src = Path(source_path)
164
- if not src.exists():
165
- log.warning("link_dataset_source_missing", dataset_id=dataset_id, path=source_path)
166
- return
167
-
168
- dest_dir = Path(project_path) / "datasets" / dataset_id
169
-
170
- if dest_dir.exists():
171
- log.debug("link_dataset_already_exists", dataset_id=dataset_id, dest=str(dest_dir))
172
- return
173
-
174
- try:
175
- if src.is_dir():
176
- shutil.copytree(src, dest_dir, dirs_exist_ok=True)
177
- else:
178
- # If it's a file (e.g. zip that wasn't extracted yet), just copy it
179
- dest_dir.parent.mkdir(parents=True, exist_ok=True)
180
- shutil.copy2(src, dest_dir)
181
-
182
- log.info("dataset_linked_to_project", dataset_id=dataset_id, project=project_path, dest=str(dest_dir))
183
- return dest_dir
184
- except OSError as exc:
185
- log.warning("link_dataset_copy_failed", dataset_id=dataset_id, error=str(exc))
186
- return None