From 4d78874da83e409e38825a81d1cd1c5cc19d4e3b Mon Sep 17 00:00:00 2001 From: saket0187 Date: Wed, 17 Jun 2026 17:02:35 +0530 Subject: [PATCH 1/4] Draft code --- temporal/t.list/t.list.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/temporal/t.list/t.list.py b/temporal/t.list/t.list.py index 4a38e22fecf..64c7447f07a 100755 --- a/temporal/t.list/t.list.py +++ b/temporal/t.list/t.list.py @@ -99,6 +99,7 @@ from contextlib import nullcontext import grass.script as gs +from grass.tools import Tools ############################################################################ @@ -149,6 +150,29 @@ def main(): elif not separator: # output_format == "plain" separator = "|" + tools = Tools() + + conn = tools.t_connect(flags="pg").keyval + + driver = conn["driver"] + database = conn["database"] + + db_exists = True + + if not driver or not database: + db_exists = False + + # if no connection is found + if not db_exists: + gs.message( + _( + "No temporal database connection exists in this mapset. No datasets to list." + ) + ) + if outpath and outpath != "-": + open(outpath, "w").close() + return + # Lazy import import grass.temporal as tgis From 2daba32ae2281c50c64fe676b7e28de6335c2ddd Mon Sep 17 00:00:00 2001 From: saket0187 Date: Thu, 18 Jun 2026 12:27:57 +0530 Subject: [PATCH 2/4] Add suggestions --- temporal/t.list/t.list.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/temporal/t.list/t.list.py b/temporal/t.list/t.list.py index 64c7447f07a..209587ab53f 100755 --- a/temporal/t.list/t.list.py +++ b/temporal/t.list/t.list.py @@ -152,15 +152,9 @@ def main(): tools = Tools() - conn = tools.t_connect(flags="pg").keyval + conn = tools.t_connect(flags="p", format="json") - driver = conn["driver"] - database = conn["database"] - - db_exists = True - - if not driver or not database: - db_exists = False + db_exists = conn["driver"] and conn["database"] # if no connection is found if not db_exists: @@ -169,8 +163,13 @@ def main(): "No temporal database connection exists in this mapset. No datasets to list." ) ) - if outpath and outpath != "-": - open(outpath, "w").close() + with ( + open(outpath, "w") + if (outpath and outpath != "-") + else nullcontext(sys.stdout) + ) as out_file: + if output_format == "json": + out_file.write(json.dumps([], indent=4) + "\n") return # Lazy import From bd35443d522decd89a738ecfa556238cade1e224 Mon Sep 17 00:00:00 2001 From: saket0187 Date: Thu, 18 Jun 2026 19:17:43 +0530 Subject: [PATCH 3/4] Show message only for plain --- temporal/t.list/t.list.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/temporal/t.list/t.list.py b/temporal/t.list/t.list.py index 209587ab53f..858942fa74e 100755 --- a/temporal/t.list/t.list.py +++ b/temporal/t.list/t.list.py @@ -158,11 +158,10 @@ def main(): # if no connection is found if not db_exists: - gs.message( - _( - "No temporal database connection exists in this mapset. No datasets to list." + if output_format == "plain": + gs.message( + _("No temporal database exists in this mapset. No datasets to list.") ) - ) with ( open(outpath, "w") if (outpath and outpath != "-") From f5cc2e06e46ed971bbb4ce7327bc85d3a94e2664 Mon Sep 17 00:00:00 2001 From: saket0187 Date: Fri, 19 Jun 2026 13:21:53 +0530 Subject: [PATCH 4/4] Add tests --- temporal/t.list/tests/conftest.py | 11 +++++++++++ temporal/t.list/tests/test_t_list.py | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/temporal/t.list/tests/conftest.py b/temporal/t.list/tests/conftest.py index bc1493fee6f..3ba6be95ed4 100644 --- a/temporal/t.list/tests/conftest.py +++ b/temporal/t.list/tests/conftest.py @@ -56,3 +56,14 @@ def space_time_dataset(tmp_path_factory): name=dataset_name, map_names=names, ) + + +@pytest.fixture(scope="module") +def empty_session(tmp_path_factory): + """Start an isolated session with no temporal database.""" + tmp_path = tmp_path_factory.mktemp("empty_time_series") + project = tmp_path / "empty_project" + gs.create_project(project) + + with gs.setup.init(project, env=os.environ.copy()) as session: + yield SimpleNamespace(session=session) diff --git a/temporal/t.list/tests/test_t_list.py b/temporal/t.list/tests/test_t_list.py index 68887c2c643..ae8d31486cd 100644 --- a/temporal/t.list/tests/test_t_list.py +++ b/temporal/t.list/tests/test_t_list.py @@ -131,3 +131,23 @@ def test_colhead_validation(space_time_dataset, output_format): assert status == 0 else: assert status != 0 + + +def test_t_list_empty_database(empty_session): + """Verify that t.list handles a missing TGIS database without creating one.""" + tools = Tools(session=empty_session.session) + + json_result = tools.t_list(type="strds", format="json") + assert json_result.returncode == 0 + assert json_result.stdout.strip() == "[]" + + csv_result = tools.t_list(type="strds", format="csv") + assert csv_result is None + + plain_result = tools.t_list(type="strds", format="plain") + assert plain_result is None + + # Ensure no connection is established + result = tools.t_connect(flags="p", format="json") + db_exist = result["driver"] and result["database"] + assert not db_exist