Convert Disk description to a property
This commit is contained in:
parent
1616379398
commit
e03956f2fe
1 changed files with 8 additions and 17 deletions
|
|
@ -37,7 +37,6 @@ class Disk:
|
|||
"""Object for tracking disk specific data."""
|
||||
attributes: dict[Any, dict] = field(init=False, default_factory=dict)
|
||||
bus: str = field(init=False)
|
||||
description: str = field(init=False)
|
||||
filesystem: str = field(init=False)
|
||||
log_sec: int = field(init=False)
|
||||
model: str = field(init=False)
|
||||
|
|
@ -57,7 +56,6 @@ class Disk:
|
|||
def __post_init__(self) -> None:
|
||||
self.path = pathlib.Path(self.path).resolve()
|
||||
self.get_details()
|
||||
self.set_description()
|
||||
enable_smart(self)
|
||||
update_smart_details(self)
|
||||
if not self.attributes and self.bus == 'USB':
|
||||
|
|
@ -86,6 +84,14 @@ class Disk:
|
|||
present = True
|
||||
return present
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
"""Get disk description from details."""
|
||||
return (
|
||||
f'{bytes_to_string(self.size, use_binary=False)}'
|
||||
f' ({self.bus}) {self.model} {self.serial}'
|
||||
)
|
||||
|
||||
def disable_disk_tests(self) -> None:
|
||||
"""Disable all tests."""
|
||||
LOG.warning('Disabling all tests for: %s', self.path)
|
||||
|
|
@ -156,14 +162,6 @@ class Disk:
|
|||
if attr == 'size':
|
||||
setattr(self, attr, -1)
|
||||
|
||||
# Set description
|
||||
self.description = (
|
||||
f'{bytes_to_string(self.size, use_binary=False)}'
|
||||
f' ({self.bus})'
|
||||
f' {self.model}'
|
||||
f' {self.serial}'
|
||||
)
|
||||
|
||||
def get_labels(self) -> list[str]:
|
||||
"""Build list of labels for this disk, returns list."""
|
||||
labels = []
|
||||
|
|
@ -189,13 +187,6 @@ class Disk:
|
|||
|
||||
return aligned
|
||||
|
||||
def set_description(self) -> None:
|
||||
"""Set disk description from details."""
|
||||
self.description = (
|
||||
f'{bytes_to_string(self.size, use_binary=False)}'
|
||||
f' ({self.bus}) {self.model} {self.serial}'
|
||||
)
|
||||
|
||||
|
||||
# Functions
|
||||
def get_disk_details_linux(path) -> dict[Any, Any]:
|
||||
|
|
|
|||
Loading…
Reference in a new issue