diff --git a/api/__init__.py b/api/__init__.py index a37ccdd..6e6840e 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -1,4 +1,4 @@ -from .project import have_project, create_project, delete_project +from .project import list_project, have_project, create_project, delete_project from .project import is_project_open, get_project_open_count, open_project, close_project from .project import copy_project diff --git a/api/project.py b/api/project.py index 30743aa..c9cdfb0 100644 --- a/api/project.py +++ b/api/project.py @@ -1,10 +1,19 @@ import psycopg as pg +from psycopg.rows import dict_row from .connection import g_conn_dict as conn # no undo/redo _project_open_count: dict[str, int] = {} +def list_project() -> list[str]: + ps = [] + with pg.connect(conninfo="dbname=postgres host=127.0.0.1", autocommit=True) as conn: + with conn.cursor(row_factory=dict_row) as cur: + for p in cur.execute(f"select datname from pg_database where datname <> 'postgres' and datname <> 'template0' and datname <> 'template1' and datname <> 'project'"): + ps.append(p['datname']) + return ps + def have_project(name: str) -> bool: with pg.connect(conninfo="dbname=postgres host=127.0.0.1", autocommit=True) as conn: with conn.cursor() as cur: diff --git a/tjnetwork.py b/tjnetwork.py index 558e6f4..f927a05 100644 --- a/tjnetwork.py +++ b/tjnetwork.py @@ -116,6 +116,9 @@ def read_inp(name: str, inp: str) -> None: # operation ############################################################ +def list_project() -> list[str]: + return api.list_project() + def get_current_operation(name: str) -> int: return api.get_current_operation(name)