Compare commits
No commits in common. "7e33a689b767136158410a66882f9dcf5aac8018" and "702010c8fc06714e81f95f2997d5642e1c8dcf3a" have entirely different histories.
7e33a689b7
...
702010c8fc
3 changed files with 16 additions and 35 deletions
|
|
@ -7,7 +7,6 @@ from .input.implementations import codes
|
||||||
from .tools import k2m, get_db_file
|
from .tools import k2m, get_db_file
|
||||||
from .tracker import get
|
from .tracker import get
|
||||||
from .integrity import has_valid_times
|
from .integrity import has_valid_times
|
||||||
from .sql import thin_sql_wrapper
|
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
|
|
@ -15,7 +14,7 @@ from collections.abc import Callable
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
def _project_lookup_by_alias(path: Path, alias: str) -> str:
|
def _project_lookup_by_alias(db: Path, alias: str) -> str:
|
||||||
"""
|
"""
|
||||||
Lookup a projects UUID by its (human-readable) alias.
|
Lookup a projects UUID by its (human-readable) alias.
|
||||||
|
|
||||||
|
|
@ -31,8 +30,11 @@ def _project_lookup_by_alias(path: Path, alias: str) -> str:
|
||||||
uuid: str
|
uuid: str
|
||||||
The UUID of the project with the given alias.
|
The UUID of the project with the given alias.
|
||||||
"""
|
"""
|
||||||
stmt = f"SELECT * FROM 'projects' WHERE aliases = '{alias}'"
|
conn = sqlite3.connect(db)
|
||||||
results = thin_sql_wrapper(path, stmt)
|
c = conn.cursor()
|
||||||
|
c.execute(f"SELECT * FROM 'projects' WHERE aliases = '{alias}'")
|
||||||
|
results = c.fetchall()
|
||||||
|
conn.close()
|
||||||
if len(results)>1:
|
if len(results)>1:
|
||||||
print("Error: multiple projects found with alias " + alias)
|
print("Error: multiple projects found with alias " + alias)
|
||||||
elif len(results) == 0:
|
elif len(results) == 0:
|
||||||
|
|
@ -40,7 +42,7 @@ def _project_lookup_by_alias(path: Path, alias: str) -> str:
|
||||||
return str(results[0][0])
|
return str(results[0][0])
|
||||||
|
|
||||||
|
|
||||||
def _project_lookup_by_id(path: Path, uuid: str) -> list[tuple[str, ...]]:
|
def _project_lookup_by_id(db: Path, uuid: str) -> list[tuple[str, ...]]:
|
||||||
"""
|
"""
|
||||||
Return the project information available in the database by UUID.
|
Return the project information available in the database by UUID.
|
||||||
|
|
||||||
|
|
@ -56,8 +58,11 @@ def _project_lookup_by_id(path: Path, uuid: str) -> list[tuple[str, ...]]:
|
||||||
results: list
|
results: list
|
||||||
The row of the project in the database.
|
The row of the project in the database.
|
||||||
"""
|
"""
|
||||||
stmt = f"SELECT * FROM 'projects' WHERE id = '{uuid}'"
|
conn = sqlite3.connect(db)
|
||||||
results = thin_sql_wrapper(path, stmt)
|
c = conn.cursor()
|
||||||
|
c.execute(f"SELECT * FROM 'projects' WHERE id = '{uuid}'")
|
||||||
|
results = c.fetchall()
|
||||||
|
conn.close()
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -355,7 +360,7 @@ def find_project(path: Path, name: str) -> str:
|
||||||
"""
|
"""
|
||||||
db_file = get_db_file(path)
|
db_file = get_db_file(path)
|
||||||
get(path, db_file)
|
get(path, db_file)
|
||||||
return _project_lookup_by_alias(path, name)
|
return _project_lookup_by_alias(path / db_file, name)
|
||||||
|
|
||||||
|
|
||||||
def list_projects(path: Path) -> list[tuple[str, str]]:
|
def list_projects(path: Path) -> list[tuple[str, str]]:
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import sqlite3
|
|
||||||
from .tools import get_db_file
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
|
|
||||||
def thin_sql_wrapper(path: Path, stmt: str) -> list[Any]:
|
|
||||||
db_file = get_db_file(path)
|
|
||||||
db = path / db_file
|
|
||||||
conn = sqlite3.connect(db)
|
|
||||||
c = conn.cursor()
|
|
||||||
|
|
||||||
c.execute(stmt)
|
|
||||||
results = c.fetchall()
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
return results
|
|
||||||
|
|
@ -9,17 +9,12 @@ import datetime as dt
|
||||||
|
|
||||||
|
|
||||||
def make_sql(path: Path) -> Path:
|
def make_sql(path: Path) -> Path:
|
||||||
db = path / "backlogger.db"
|
db = path / "test.db"
|
||||||
cinit._create_db(db)
|
cinit._create_db(db)
|
||||||
return db
|
return db
|
||||||
|
|
||||||
|
|
||||||
def make_config(path: Path) -> None:
|
|
||||||
cinit._write_config(path, cinit._create_config(path, "datalad", False))
|
|
||||||
|
|
||||||
|
|
||||||
def test_find_lookup_by_one_alias(tmp_path: Path) -> None:
|
def test_find_lookup_by_one_alias(tmp_path: Path) -> None:
|
||||||
make_config(tmp_path)
|
|
||||||
db = make_sql(tmp_path)
|
db = make_sql(tmp_path)
|
||||||
conn = sqlite3.connect(db)
|
conn = sqlite3.connect(db)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
@ -31,7 +26,7 @@ def test_find_lookup_by_one_alias(tmp_path: Path) -> None:
|
||||||
c.execute("INSERT INTO projects (id, aliases, customTags, owner, code, created_at, updated_at) VALUES (?, ?, ?, ?, ?, datetime('now'), datetime('now'))",
|
c.execute("INSERT INTO projects (id, aliases, customTags, owner, code, created_at, updated_at) VALUES (?, ?, ?, ?, ?, datetime('now'), datetime('now'))",
|
||||||
(uuid, alias_str, tag_str, owner, code))
|
(uuid, alias_str, tag_str, owner, code))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
assert uuid == find._project_lookup_by_alias(tmp_path, "fun_project")
|
assert uuid == find._project_lookup_by_alias(db, "fun_project")
|
||||||
uuid = "test_uuid2"
|
uuid = "test_uuid2"
|
||||||
alias_str = "fun_project"
|
alias_str = "fun_project"
|
||||||
c.execute("INSERT INTO projects (id, aliases, customTags, owner, code, created_at, updated_at) VALUES (?, ?, ?, ?, ?, datetime('now'), datetime('now'))",
|
c.execute("INSERT INTO projects (id, aliases, customTags, owner, code, created_at, updated_at) VALUES (?, ?, ?, ?, ?, datetime('now'), datetime('now'))",
|
||||||
|
|
@ -41,9 +36,7 @@ def test_find_lookup_by_one_alias(tmp_path: Path) -> None:
|
||||||
assert uuid == find._project_lookup_by_alias(db, "fun_project")
|
assert uuid == find._project_lookup_by_alias(db, "fun_project")
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def test_find_lookup_by_id(tmp_path: Path) -> None:
|
def test_find_lookup_by_id(tmp_path: Path) -> None:
|
||||||
make_config(tmp_path)
|
|
||||||
db = make_sql(tmp_path)
|
db = make_sql(tmp_path)
|
||||||
conn = sqlite3.connect(db)
|
conn = sqlite3.connect(db)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
@ -56,7 +49,7 @@ def test_find_lookup_by_id(tmp_path: Path) -> None:
|
||||||
(uuid, alias_str, tag_str, owner, code))
|
(uuid, alias_str, tag_str, owner, code))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
result = find._project_lookup_by_id(tmp_path, uuid)[0]
|
result = find._project_lookup_by_id(db, uuid)[0]
|
||||||
assert uuid == result[0]
|
assert uuid == result[0]
|
||||||
assert alias_str == result[1]
|
assert alias_str == result[1]
|
||||||
assert tag_str == result[2]
|
assert tag_str == result[2]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue