From 7b95a0f151a4f954471655c69e852954c6621b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Palancher?= Date: Tue, 14 Oct 2025 11:54:02 +0200 Subject: [PATCH 1/2] feat(cli): auto-paging feature Add auto-paging to dump, schema and all view commands. This feature requires RFL.log >= 1.6.0. fix #138 --- CHANGELOG.md | 2 ++ pyproject.toml | 2 +- racksdb/exec.py | 32 ++++++++++++++++++++++---------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 789e5579..6454e6c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,13 @@ and this project adheres to ## [unreleased] ### Added +- cli: Add auto-paging to `dump`, `schema` and all view commands (#138). - docs: - Mention support of Fedora 42. - Mention support of Debian 14 _« forky »_ ### Changed +- pkgs: Bump minimal requirement on `RFL.log` >= 1.6.0. - docs: Reword s/modelize/modeling/. ### Removed diff --git a/pyproject.toml b/pyproject.toml index 1311d90e..d5f17650 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ dependencies = [ "ClusterShell", "pycairo", "PyGObject", - "RFL.log", + "RFL.log >= 1.6.0", ] readme = "README.md" classifiers = [ diff --git a/racksdb/exec.py b/racksdb/exec.py index 0f43bcf9..8b931943 100644 --- a/racksdb/exec.py +++ b/racksdb/exec.py @@ -11,7 +11,7 @@ import typing as t from pathlib import Path -from rfl.log import setup_logger +from rfl.log import setup_logger, AutoPager from .version import get_version from .generic.errors import DBFormatError, DBSchemaError @@ -167,10 +167,18 @@ def _setup_logger(self): ) def _run_schema(self): - print(SchemaDumperFactory.get("yaml")().dump(self.db._schema)) + with AutoPager(): + try: + print(SchemaDumperFactory.get("yaml")().dump(self.db._schema)) + except BrokenPipeError: + pass def _run_dump(self): - print(DBDumperFactory.get("yaml")().dump(self.db._loader.content)) + with AutoPager(): + try: + print(DBDumperFactory.get("yaml")().dump(self.db._loader.content)) + except BrokenPipeError: + pass def _run_racks(self): self._dump_view() @@ -233,13 +241,17 @@ def _dump_view(self): if self.args.format is None: self.args.format = self.DEFAULT_FORMAT - print( - DBDumperFactory.get(self.args.format)( - show_types=self.args.with_objects_types, - objects_map=view.objects_map, - fold=self.args.fold, - ).dump(data) - ) + with AutoPager(): + try: + print( + DBDumperFactory.get(self.args.format)( + show_types=self.args.with_objects_types, + objects_map=view.objects_map, + fold=self.args.fold, + ).dump(data) + ) + except BrokenPipeError: + pass def _run_draw(self): file = f"{self.args.name}.{self.args.format}" From 697d62709edc16cec465b9ca8f829cb918000406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Palancher?= Date: Tue, 14 Oct 2025 11:56:19 +0200 Subject: [PATCH 2/2] tests(cli): cover auto-paging feature --- racksdb/tests/test_exec.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/racksdb/tests/test_exec.py b/racksdb/tests/test_exec.py index 015420cc..8f5948d4 100644 --- a/racksdb/tests/test_exec.py +++ b/racksdb/tests/test_exec.py @@ -668,3 +668,30 @@ def test_draw_infrastructure_axonometric(self): self.assertTrue(drawing.exists()) finally: os.chdir(cwd) + + # + # autopaging + # + + def test_autopager_used_in_schema(self): + with mock.patch("racksdb.exec.AutoPager") as autopager: + with mock.patch("sys.stdout", new=io.StringIO()): + RacksDBExec(CMD_BASE_ARGS + ["schema"]) + autopager.assert_called_once() + # Ensure context manager was entered + autopager.return_value.__enter__.assert_called_once() + + def test_autopager_used_in_dump(self): + with mock.patch("racksdb.exec.AutoPager") as autopager: + with mock.patch("sys.stdout", new=io.StringIO()): + RacksDBExec(CMD_BASE_ARGS + ["dump"]) + autopager.assert_called_once() + autopager.return_value.__enter__.assert_called_once() + + def test_autopager_used_in_views(self): + # Use a representative view command that goes through _dump_view + with mock.patch("racksdb.exec.AutoPager") as autopager: + with mock.patch("sys.stdout", new=io.StringIO()): + RacksDBExec(CMD_BASE_ARGS + ["datacenters"]) + autopager.assert_called_once() + autopager.return_value.__enter__.assert_called_once()