kin: KIN-070 Исправить sync с Obsidian: auto-create vault dir + корректный vault_path
- obsidian_sync.py: заменить проверку is_dir() на mkdir(parents=True, exist_ok=True) вместо ошибки при отсутствующей директории — автоматически создаём её - test_obsidian_sync.py: обновить тест #9 под новое поведение (директория создаётся) - БД fix: исправлен obsidian_vault_path (убраны лишние кавычки и /kin суффикс), теперь путь указывает на vault root, а не на подпапку проекта Результат: Exported: 79 decisions, errors: [] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8007960332
commit
71c697bf68
2 changed files with 34 additions and 31 deletions
|
|
@ -141,36 +141,39 @@ def sync_obsidian(conn: sqlite3.Connection, project_id: str) -> dict:
|
|||
vault_path = Path(vault_path_str)
|
||||
errors: list[str] = []
|
||||
|
||||
# --- Создаём vault_path если не существует ---
|
||||
try:
|
||||
vault_path.mkdir(parents=True, exist_ok=True)
|
||||
except Exception as e:
|
||||
errors.append(f"Cannot create vault path {vault_path_str}: {e}")
|
||||
return {"exported_decisions": 0, "tasks_updated": 0, "errors": errors, "vault_path": vault_path_str}
|
||||
|
||||
# --- Export decisions ---
|
||||
exported_count = 0
|
||||
if not vault_path.is_dir():
|
||||
errors.append(f"Vault path does not exist or is not a directory: {vault_path_str}")
|
||||
else:
|
||||
try:
|
||||
decisions = models.get_decisions(conn, project_id)
|
||||
created_files = export_decisions_to_md(project_id, decisions, vault_path)
|
||||
exported_count = len(created_files)
|
||||
except Exception as e:
|
||||
errors.append(f"Export error: {e}")
|
||||
try:
|
||||
decisions = models.get_decisions(conn, project_id)
|
||||
created_files = export_decisions_to_md(project_id, decisions, vault_path)
|
||||
exported_count = len(created_files)
|
||||
except Exception as e:
|
||||
errors.append(f"Export error: {e}")
|
||||
|
||||
# --- Import checkboxes ---
|
||||
tasks_updated = 0
|
||||
if vault_path.is_dir():
|
||||
try:
|
||||
checkboxes = parse_task_checkboxes(vault_path, project_id)
|
||||
for item in checkboxes:
|
||||
if not item["done"]:
|
||||
continue
|
||||
task = models.get_task(conn, item["task_id"])
|
||||
if task is None:
|
||||
continue
|
||||
if task.get("project_id") != project_id:
|
||||
continue
|
||||
if task.get("status") != "done":
|
||||
models.update_task(conn, item["task_id"], status="done")
|
||||
tasks_updated += 1
|
||||
except Exception as e:
|
||||
errors.append(f"Import error: {e}")
|
||||
try:
|
||||
checkboxes = parse_task_checkboxes(vault_path, project_id)
|
||||
for item in checkboxes:
|
||||
if not item["done"]:
|
||||
continue
|
||||
task = models.get_task(conn, item["task_id"])
|
||||
if task is None:
|
||||
continue
|
||||
if task.get("project_id") != project_id:
|
||||
continue
|
||||
if task.get("status") != "done":
|
||||
models.update_task(conn, item["task_id"], status="done")
|
||||
tasks_updated += 1
|
||||
except Exception as e:
|
||||
errors.append(f"Import error: {e}")
|
||||
|
||||
return {
|
||||
"exported_decisions": exported_count,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue