Skip to content

Commit

Permalink
Split out detail and table listing of filesystems
Browse files Browse the repository at this point in the history
Differentiate them so that table listing no longer includes the Created
field and so that the Detail view has more explanatory text.

Signed-off-by: mulhern <amulhern@redhat.com>
  • Loading branch information
mulkieran committed Jan 17, 2024
1 parent 537c79f commit cb989aa
Showing 1 changed file with 58 additions and 11 deletions.
69 changes: 58 additions & 11 deletions src/stratis_cli/_actions/_list_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
Filesystem listing.
"""

# isort: STDLIB
from abc import ABC, abstractmethod

# isort: THIRDPARTY
from dateutil import parser as date_parser
from justbytes import Range
Expand Down Expand Up @@ -66,22 +69,22 @@ def list_filesystems(
]

if fs_id is None:
klass = List(
klass = Table(
uuid_formatter,
filesystems_with_props,
path_to_name,
)
else:
klass = List(
klass = Detail(
uuid_formatter,
filesystems_with_props,
path_to_name,
)

klass.list_filesystems()
klass.display()


class List: # pylint: disable=too-few-public-methods
class List(ABC): # pylint: disable=too-few-public-methods
"""
Handle listing a filesystem or filesystems.
"""
Expand All @@ -97,9 +100,21 @@ def __init__(self, uuid_formatter, filesystems_with_props, path_to_name):
self.filesystems_with_props = filesystems_with_props
self.path_to_name = path_to_name

def list_filesystems(self):
@abstractmethod
def display(self):
"""
List filesystems.
"""


class Table(List): # pylint: disable=too-few-public-methods
"""
List filesystems using table format.
"""

def display(self):
"""
List the pools.
List the filesystems.
"""

def filesystem_size_quartet(dbus_props):
Expand All @@ -122,9 +137,6 @@ def filesystem_size_quartet(dbus_props):
self.path_to_name[mofilesystem.Pool()],
mofilesystem.Name(),
filesystem_size_quartet(mofilesystem),
date_parser.parse(mofilesystem.Created())
.astimezone()
.strftime("%b %d %Y %H:%M"),
mofilesystem.Devnode(),
self.uuid_formatter(mofilesystem.Uuid()),
)
Expand All @@ -136,10 +148,45 @@ def filesystem_size_quartet(dbus_props):
"Pool",
"Filesystem",
f"{TOTAL_USED_FREE} / Limit",
"Created",
"Device",
"UUID",
],
sorted(tables, key=lambda entry: (entry[0], entry[1])),
["<", "<", "<", "<", "<", "<"],
["<", "<", "<", "<", "<"],
)


class Detail(List): # pylint: disable=too-few-public-methods
"""
Do a detailed listing of filesystems.
"""

def display(self):
"""
List the filesystems.
"""
assert len(self.filesystems_with_props) == 1

fs = self.filesystems_with_props[0]

total = Range(fs.Size())
used = get_property(fs.Used(), Range, None)
limit = get_property(fs.SizeLimit(), Range, None)
created = (
date_parser.parse(fs.Created()).astimezone().strftime("%b %d %Y %H:%M")
)

print(f"UUID: {self.uuid_formatter(fs.Uuid())}")
print(f"Name: {fs.Name()}")
print(f"Pool: {self.path_to_name[fs.Pool()]}")
print()
print(f"Device: {fs.Devnode()}")
print()
print(f"Created: {created}")
print()
print("Sizes:")
print(f" Logical size of devicemapper device: {total}")
print(f" Total used (including for XFS metadata): {used}")
print(f" Free: {total - used}")
print()
print(f" Size Limit: {'None' if limit is None else limit}")

0 comments on commit cb989aa

Please sign in to comment.