Skip to content

Commit

Permalink
[DISK] Fixes df output parsing when FS column contains whitespaces (#…
Browse files Browse the repository at this point in the history
…102)

* [STYLE] Silences new Pylint recommendation C0209
* [CI] Forces macOS-10.15 as pypy 3.6 is unavailable afterwards (see actions/runner-images#4060)

Co-authored-by: Samuel FORESTIER <dev@samuel.domains>
  • Loading branch information
lourinaldi and Samuel FORESTIER committed Oct 16, 2021
1 parent 7752e4b commit 0e21951
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
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
""
])
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

0 comments on commit 0e21951

Please sign in to comment.