Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DISK] Fixes df output parsing when FS column contains whitespaces #102

Merged
merged 3 commits into from
Oct 16, 2021
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: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os:
- 'macOS-latest'
- 'macOS-10.15'
- 'ubuntu-latest'
python-version:
- '3.6'
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project (partially) adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- (`Disk`) Fix `df` output parsing when file-systems column containing whitespaces

## [v4.13.1] - 2021-09-04
### Changed
Expand Down
24 changes: 16 additions & 8 deletions archey/entries/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,24 @@ def _get_df_output_dict() -> Dict[str, dict]:
return {}

df_output_dict = {}
for df_entry in df_output.splitlines()[1:]: # Discard the header row here.
# Don't crash against BSDs's autofs mount points.
if df_entry.startswith('map '):
for df_entry_match in re.findall(
# device_path
# total_blocks
# used_blocks
# mount point
r"^(.+?)\s+(\d+)\s+(\d+)\s+\d+\s+\d+%\s+(.*)$",
df_output,
flags=re.MULTILINE
):
total_blocks = int(df_entry_match[1])
# Skip entries missing the number of blocks.
if total_blocks == 0:
continue

columns = df_entry.split(maxsplit=5)
df_output_dict[columns[5]] = { # 6th column === mount point.
'device_path': columns[0],
'used_blocks': int(columns[2]),
'total_blocks': int(columns[1])
df_output_dict[df_entry_match[3]] = {
'device_path': df_entry_match[0],
'used_blocks': int(df_entry_match[2]),
'total_blocks': total_blocks
}

return df_output_dict
Expand Down
1 change: 1 addition & 0 deletions archey/test/entries/test_archey_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_disk_df_output_dict(self, run_mock):
"/dev/nvme0n1p1 523248 35908 487340 7% /boot",
"/dev/sda1 1624 42 1582 1% /what is this", # pylint: disable=line-too-long
"map auto_home 0 0 0 100% /System/Volumes/Data/home", # pylint: disable=line-too-long
"/Applications/Among Us.app/Wrapper 0 0 0 100% /System/Volumes/Data/game", # pylint: disable=line-too-long
HorlogeSkynet marked this conversation as resolved.
Show resolved Hide resolved
""
])
self.assertDictEqual(
Expand Down
8 changes: 3 additions & 5 deletions archey/test/entries/test_archey_uptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,9 @@ def test_parse_uptime_cmd(self, check_output_mock):
self.assertEqual(
uptime_instance_mock._parse_uptime_cmd(), # pylint: disable=protected-access
expected_delta,
msg='`uptime` output: "{}"'.format(
uptime_output.format(
time=variations[0],
user_loadavg=variations[1]
)
msg=(
"`uptime` output: "
+ uptime_output.format(time=variations[0], user_loadavg=variations[1])
)
)

Expand Down
10 changes: 6 additions & 4 deletions archey/test/test_archey_logos.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def test_distribution_logos_consistency(self):
self.assertEqual(
line_width,
logo_width,
msg='[{}] line index {}, got an unexpected width {} (expected {})'.format(
logo_module_info.name, j, line_width, logo_width
msg=(
f"[{logo_module_info.name}] line index {j}, "
f"got an unexpected width {line_width} (expected {logo_width})"
)
)

Expand All @@ -75,8 +76,9 @@ def test_distribution_logos_consistency(self):
self.assertEqual(
i,
len(distributions_identifiers),
msg='[{}] Expected {} logo modules, got {}'.format(
logo_module_info.name, len(distributions_identifiers), i
msg=(
f"[{logo_module_info.name}] Expected {len(distributions_identifiers)} "
f"logo modules, got {i}"
)
)

Expand Down