diff --git a/mapchete/cli/mpath.py b/mapchete/cli/mpath.py index c7f92df4..a32cfa46 100644 --- a/mapchete/cli/mpath.py +++ b/mapchete/cli/mpath.py @@ -6,7 +6,6 @@ from mapchete.cli import options from mapchete.io import copy from mapchete.path import MPath -from mapchete.pretty import pretty_bytes opt_recursive = click.option("--recursive", "-r", is_flag=True) @@ -79,9 +78,11 @@ def _print_rows( columns=[ "", "", - f"{str(subpath)}/" - if absolute_paths - else f"{subpath.relative_to(path)}/", + ( + f"{str(subpath)}/" + if absolute_paths + else f"{subpath.relative_to(path)}/" + ), ], widths=[last_modified_column_width, size_column_width, None], spacing=spacing, @@ -92,7 +93,7 @@ def _print_rows( _row( columns=[ subpath.last_modified().strftime(date_format), - pretty_bytes(subpath.size()), + subpath.pretty_size(), str(subpath) if absolute_paths else subpath.relative_to(path), ], widths=[last_modified_column_width, size_column_width, None], diff --git a/mapchete/path.py b/mapchete/path.py index f31d1d35..1d705684 100644 --- a/mapchete/path.py +++ b/mapchete/path.py @@ -22,6 +22,7 @@ from retry import retry from mapchete.executor import Executor +from mapchete.pretty import pretty_bytes from mapchete.settings import GDALHTTPOptions, IORetrySettings, mapchete_options from mapchete.tile import BufferedTile from mapchete.types import MPathLike @@ -442,6 +443,9 @@ def rm(self, recursive: bool = False, ignore_errors: bool = False) -> None: def size(self) -> int: return self.info().get("size", self.info().get("Size")) + def pretty_size(self) -> str: + return pretty_bytes(self.size()) + def last_modified(self) -> datetime: # for S3 objects last_modified = self.info().get("LastModified") diff --git a/test/test_path.py b/test/test_path.py index 2121b63b..2a0b769d 100644 --- a/test/test_path.py +++ b/test/test_path.py @@ -287,6 +287,16 @@ def test_size_remote(path): test_size(path) +@pytest.mark.parametrize( + "path", + [ + lazy_fixture("metadata_json"), + ], +) +def test_pretty_size(path): + assert path.pretty_size() + + @pytest.mark.parametrize( "path", [