Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies = [
"ClusterShell",
"pycairo",
"PyGObject",
"RFL.log",
"RFL.log >= 1.6.0",
]
readme = "README.md"
classifiers = [
Expand Down
32 changes: 22 additions & 10 deletions racksdb/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}"
Expand Down
27 changes: 27 additions & 0 deletions racksdb/tests/test_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()