statblk 1.44__tar.gz → 1.45__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: statblk
3
- Version: 1.44
3
+ Version: 1.45
4
4
  Summary: Gather essential disk and partition info for block devices and print it in a nice table
5
5
  Home-page: https://github.com/yufei-pan/statblk
6
6
  Author: Yufei Pan
@@ -68,7 +68,7 @@ statblk 2 # refresh every 2 seconds (watch mode)
68
68
 
69
69
  ## Output columns
70
70
 
71
- By default all columns are shown:
71
+ By default every column that has data is shown (a column that is empty for every row, such as `LABEL` when nothing is labelled, is hidden from the table):
72
72
 
73
73
  | Column | Description |
74
74
  |--------|-------------|
@@ -86,7 +86,7 @@ By default all columns are shown:
86
86
  | `READ` | Current read throughput |
87
87
  | `WRITE` | Current write throughput |
88
88
 
89
- Use `-o` / `--output` to select columns (comma-separated) or `-x` / `--exclude` to omit columns.
89
+ Use `-o` / `--output` to select columns (comma-separated) or `-x` / `--exclude` to omit columns. Columns named with `-o` are always shown, even when empty; `--show_empty_columns` keeps empty columns in the default view. JSON output (`-j` / `-J`) always includes every selected column.
90
90
 
91
91
  ## Options
92
92
 
@@ -99,8 +99,9 @@ Use `-o` / `--output` to select columns (comma-separated) or `-x` / `--exclude`
99
99
  | `-b`, `--bytes` | Print sizes and throughput as raw byte counts |
100
100
  | `-H`, `--si` | Use powers of 1000 (SI) instead of 1024 for sizes |
101
101
  | `-R`, `--full` | Do not truncate long values to terminal width |
102
- | `-o`, `--output` | Columns to include (default: all) |
102
+ | `-o`, `--output` | Columns to include (default: all with data) |
103
103
  | `-x`, `--exclude` | Columns to omit |
104
+ | `--show_empty_columns` | Keep columns that are empty for every row in the table |
104
105
 
105
106
  ### Filtering
106
107
 
@@ -152,7 +153,7 @@ statblk -w 0 nvme0 # same via flag
152
153
 
153
154
  Uses sysfs, `/proc/self/mountinfo`, `lsblk`, and optionally `smartctl`.
154
155
 
155
- - **SMART** requires `smartctl` (smartmontools). Use `--sudo` if permission is denied. It only runs against hardware-backed disks (not loop, dm, md, zram, nbd). Use `--debug` to see why the column is empty.
156
+ - **SMART** requires `smartctl` (smartmontools). Use `--sudo` if permission is denied. It only runs against hardware-backed disks (not loop, dm, md, zram, nbd). The column is hidden when no disk reports SMART; use `-o` or `--show_empty_columns` to show it and `--debug` to see why it is empty.
156
157
  - **autofs** trigger mounts are ignored (stat-ing them would trigger the automount); the real filesystem appears once mounted.
157
158
  - **READ / WRITE** throughput comes from `/sys/class/block/*/stat` (always 512-byte sector units).
158
159
  - On a single-shot run (and the first row of watch mode), READ/WRITE are a lifetime busy-time average (bytes / time spent in I/O since boot). In watch mode, later refreshes are interval rates over the sleep period (Δbytes / wall clock).
@@ -39,7 +39,7 @@ statblk 2 # refresh every 2 seconds (watch mode)
39
39
 
40
40
  ## Output columns
41
41
 
42
- By default all columns are shown:
42
+ By default every column that has data is shown (a column that is empty for every row, such as `LABEL` when nothing is labelled, is hidden from the table):
43
43
 
44
44
  | Column | Description |
45
45
  |--------|-------------|
@@ -57,7 +57,7 @@ By default all columns are shown:
57
57
  | `READ` | Current read throughput |
58
58
  | `WRITE` | Current write throughput |
59
59
 
60
- Use `-o` / `--output` to select columns (comma-separated) or `-x` / `--exclude` to omit columns.
60
+ Use `-o` / `--output` to select columns (comma-separated) or `-x` / `--exclude` to omit columns. Columns named with `-o` are always shown, even when empty; `--show_empty_columns` keeps empty columns in the default view. JSON output (`-j` / `-J`) always includes every selected column.
61
61
 
62
62
  ## Options
63
63
 
@@ -70,8 +70,9 @@ Use `-o` / `--output` to select columns (comma-separated) or `-x` / `--exclude`
70
70
  | `-b`, `--bytes` | Print sizes and throughput as raw byte counts |
71
71
  | `-H`, `--si` | Use powers of 1000 (SI) instead of 1024 for sizes |
72
72
  | `-R`, `--full` | Do not truncate long values to terminal width |
73
- | `-o`, `--output` | Columns to include (default: all) |
73
+ | `-o`, `--output` | Columns to include (default: all with data) |
74
74
  | `-x`, `--exclude` | Columns to omit |
75
+ | `--show_empty_columns` | Keep columns that are empty for every row in the table |
75
76
 
76
77
  ### Filtering
77
78
 
@@ -123,7 +124,7 @@ statblk -w 0 nvme0 # same via flag
123
124
 
124
125
  Uses sysfs, `/proc/self/mountinfo`, `lsblk`, and optionally `smartctl`.
125
126
 
126
- - **SMART** requires `smartctl` (smartmontools). Use `--sudo` if permission is denied. It only runs against hardware-backed disks (not loop, dm, md, zram, nbd). Use `--debug` to see why the column is empty.
127
+ - **SMART** requires `smartctl` (smartmontools). Use `--sudo` if permission is denied. It only runs against hardware-backed disks (not loop, dm, md, zram, nbd). The column is hidden when no disk reports SMART; use `-o` or `--show_empty_columns` to show it and `--debug` to see why it is empty.
127
128
  - **autofs** trigger mounts are ignored (stat-ing them would trigger the automount); the real filesystem appears once mounted.
128
129
  - **READ / WRITE** throughput comes from `/sys/class/block/*/stat` (always 512-byte sector units).
129
130
  - On a single-shot run (and the first row of watch mode), READ/WRITE are a lifetime busy-time average (bytes / time spent in I/O since boot). In watch mode, later refreshes are interval rates over the sleep period (Δbytes / wall clock).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: statblk
3
- Version: 1.44
3
+ Version: 1.45
4
4
  Summary: Gather essential disk and partition info for block devices and print it in a nice table
5
5
  Home-page: https://github.com/yufei-pan/statblk
6
6
  Author: Yufei Pan
@@ -68,7 +68,7 @@ statblk 2 # refresh every 2 seconds (watch mode)
68
68
 
69
69
  ## Output columns
70
70
 
71
- By default all columns are shown:
71
+ By default every column that has data is shown (a column that is empty for every row, such as `LABEL` when nothing is labelled, is hidden from the table):
72
72
 
73
73
  | Column | Description |
74
74
  |--------|-------------|
@@ -86,7 +86,7 @@ By default all columns are shown:
86
86
  | `READ` | Current read throughput |
87
87
  | `WRITE` | Current write throughput |
88
88
 
89
- Use `-o` / `--output` to select columns (comma-separated) or `-x` / `--exclude` to omit columns.
89
+ Use `-o` / `--output` to select columns (comma-separated) or `-x` / `--exclude` to omit columns. Columns named with `-o` are always shown, even when empty; `--show_empty_columns` keeps empty columns in the default view. JSON output (`-j` / `-J`) always includes every selected column.
90
90
 
91
91
  ## Options
92
92
 
@@ -99,8 +99,9 @@ Use `-o` / `--output` to select columns (comma-separated) or `-x` / `--exclude`
99
99
  | `-b`, `--bytes` | Print sizes and throughput as raw byte counts |
100
100
  | `-H`, `--si` | Use powers of 1000 (SI) instead of 1024 for sizes |
101
101
  | `-R`, `--full` | Do not truncate long values to terminal width |
102
- | `-o`, `--output` | Columns to include (default: all) |
102
+ | `-o`, `--output` | Columns to include (default: all with data) |
103
103
  | `-x`, `--exclude` | Columns to omit |
104
+ | `--show_empty_columns` | Keep columns that are empty for every row in the table |
104
105
 
105
106
  ### Filtering
106
107
 
@@ -152,7 +153,7 @@ statblk -w 0 nvme0 # same via flag
152
153
 
153
154
  Uses sysfs, `/proc/self/mountinfo`, `lsblk`, and optionally `smartctl`.
154
155
 
155
- - **SMART** requires `smartctl` (smartmontools). Use `--sudo` if permission is denied. It only runs against hardware-backed disks (not loop, dm, md, zram, nbd). Use `--debug` to see why the column is empty.
156
+ - **SMART** requires `smartctl` (smartmontools). Use `--sudo` if permission is denied. It only runs against hardware-backed disks (not loop, dm, md, zram, nbd). The column is hidden when no disk reports SMART; use `-o` or `--show_empty_columns` to show it and `--debug` to see why it is empty.
156
157
  - **autofs** trigger mounts are ignored (stat-ing them would trigger the automount); the real filesystem appears once mounted.
157
158
  - **READ / WRITE** throughput comes from `/sys/class/block/*/stat` (always 512-byte sector units).
158
159
  - On a single-shot run (and the first row of watch mode), READ/WRITE are a lifetime busy-time average (bytes / time spent in I/O since boot). In watch mode, later refreshes are interval rates over the sleep period (Δbytes / wall clock).
@@ -154,7 +154,7 @@ def clear_caches():
154
154
  for fn in _CACHED_FUNCTIONS:
155
155
  fn.cache_clear()
156
156
 
157
- version = '1.44'
157
+ version = '1.45'
158
158
  VERSION = version
159
159
  __version__ = version
160
160
  COMMIT_DATE = '2026-10-10'
@@ -1014,6 +1014,21 @@ def printable(text):
1014
1014
  escaped.append('\\U%08x' % code)
1015
1015
  return ''.join(escaped)
1016
1016
 
1017
+ def drop_empty_columns(rows):
1018
+ """Remove columns whose value is empty in every data row (e.g. LABEL when
1019
+ no filesystem is labelled, SMART without smartctl). A header-only table is
1020
+ returned unchanged.
1021
+
1022
+ >>> drop_empty_columns([['NAME', 'LABEL', 'SMART'], ['sda1', '', 'OK'], ['sda2', '', '']])
1023
+ [['NAME', 'SMART'], ['sda1', 'OK'], ['sda2', '']]
1024
+ >>> drop_empty_columns([['NAME', 'LABEL']])
1025
+ [['NAME', 'LABEL']]
1026
+ """
1027
+ if len(rows) < 2:
1028
+ return rows
1029
+ keep = [i for i in range(len(rows[0])) if any(str(row[i]).strip() for row in rows[1:])]
1030
+ return [[row[i] for i in keep] for row in rows]
1031
+
1017
1032
  def rows_to_objects(rows):
1018
1033
  """Turn get_drives_info(print_bytes=True) rows into one dict per row, with
1019
1034
  SIZE/READ/WRITE as integer bytes and FSUSE% as an integer percent (None
@@ -1056,6 +1071,7 @@ def main():
1056
1071
  help="Repeat output every SECONDS (watch mode). Equivalent to a trailing integer positional.")
1057
1072
  parser.add_argument('--sudo', help="Run commands as root with sudo. Needed for querying SMART info.", action="store_true")
1058
1073
  parser.add_argument('--show_zero_size_devices', help="Show devices with zero size", action="store_true")
1074
+ parser.add_argument('--show_empty_columns', help="Keep table columns that are empty for every row (hidden by default unless named in -o)", action="store_true")
1059
1075
  parser.add_argument('-D','--match_devname_only', help="Change filter pattern to match just the device names instead of the full line", action="store_true")
1060
1076
  parser.add_argument('-v','--invert_match', help="Invert the filter match", action="store_true")
1061
1077
  parser.add_argument('--debug', help="Print suppressed exceptions to stderr for troubleshooting", action="store_true")
@@ -1100,6 +1116,10 @@ def main():
1100
1116
  import json
1101
1117
  print(json.dumps(results, indent=1),flush=True)
1102
1118
  else:
1119
+ # Hide all-empty columns only for the default column set: an explicit
1120
+ # -o asked for them, and JSON keeps a stable schema for scripts.
1121
+ if args.output == "all" and not args.show_empty_columns:
1122
+ results = drop_empty_columns(results)
1103
1123
  # JSON output is already escaped by json.dumps; the table is not.
1104
1124
  safe_rows = [[printable(str(value)) for value in row] for row in results]
1105
1125
  print(multiCMD.pretty_format_table(safe_rows,full=args.full),flush=True)
@@ -206,3 +206,52 @@ def test_json_output_keeps_values_but_no_raw_control_characters(monkeypatch, cap
206
206
  out = capsys.readouterr().out
207
207
  assert "\x1b" not in out
208
208
  assert json.loads(out)[1] == HOSTILE_ROWS[1]
209
+
210
+
211
+ SPARSE_ROWS = [
212
+ ["NAME", "SMART", "LABEL", "MOUNTPOINT"],
213
+ ["sda1", "OK", "", "/data"],
214
+ ["sda2", "OK", "", ""],
215
+ ]
216
+
217
+
218
+ def _captured_table(monkeypatch, argv, rows=SPARSE_ROWS):
219
+ tables = []
220
+ _patch_main_basics(monkeypatch, lambda **k: [list(r) for r in rows])
221
+ monkeypatch.setattr(statblk.multiCMD, "pretty_format_table", lambda r, **k: tables.append(r) or "T")
222
+ monkeypatch.setattr(statblk.sys, "argv", argv)
223
+ statblk.main()
224
+ return tables[0]
225
+
226
+
227
+ def test_table_hides_empty_columns_by_default(monkeypatch):
228
+ assert _captured_table(monkeypatch, ["statblk"]) == [
229
+ ["NAME", "SMART", "MOUNTPOINT"],
230
+ ["sda1", "OK", "/data"],
231
+ ["sda2", "OK", ""],
232
+ ]
233
+
234
+
235
+ def test_table_hides_empty_columns_with_exclude(monkeypatch):
236
+ assert _captured_table(monkeypatch, ["statblk", "-x", "SMART"])[0] == ["NAME", "SMART", "MOUNTPOINT"]
237
+
238
+
239
+ @pytest.mark.parametrize("argv", [
240
+ ["statblk", "--show_empty_columns"],
241
+ ["statblk", "-o", "NAME,SMART,LABEL,MOUNTPOINT"], # explicitly asked for LABEL
242
+ ])
243
+ def test_table_keeps_empty_columns_when_asked(monkeypatch, argv):
244
+ assert _captured_table(monkeypatch, argv) == SPARSE_ROWS
245
+
246
+
247
+ def test_table_keeps_header_when_no_rows(monkeypatch):
248
+ assert _captured_table(monkeypatch, ["statblk"], rows=[SPARSE_ROWS[0]]) == [SPARSE_ROWS[0]]
249
+
250
+
251
+ @pytest.mark.parametrize("flag", ["-j", "-J"])
252
+ def test_json_keeps_empty_columns(monkeypatch, capsys, flag):
253
+ _patch_main_basics(monkeypatch, lambda **k: [list(r) for r in SPARSE_ROWS])
254
+ monkeypatch.setattr(statblk.sys, "argv", ["statblk", flag])
255
+ statblk.main()
256
+ data = json.loads(capsys.readouterr().out)
257
+ assert "LABEL" in data[0] # header row for -j, first object's keys for -J
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes