statblk 1.21__py3-none-any.whl → 1.22__py3-none-any.whl

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.21
3
+ Version: 1.22
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
@@ -0,0 +1,6 @@
1
+ statblk.py,sha256=C8_7zjjE0b5hKj7GtK73jXcQcaRr96uhtWb-RDenPug,27212
2
+ statblk-1.22.dist-info/METADATA,sha256=rVGQOV-ggZp3EHWxPqm9dp7ZaSWfYUkdhaPmhz0P-Cg,1465
3
+ statblk-1.22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4
+ statblk-1.22.dist-info/entry_points.txt,sha256=JDz-sa6FIdaOckmlz9NbnhZXQaB5Yle-cTKgUQmAV40,41
5
+ statblk-1.22.dist-info/top_level.txt,sha256=dBdU6_PD4tG_7uquWEs6YremqudiePASv3u3G59scf4,8
6
+ statblk-1.22.dist-info/RECORD,,
statblk.py CHANGED
@@ -276,7 +276,7 @@ except :
276
276
  def cache_decorator(func):
277
277
  return func
278
278
 
279
- version = '1.21'
279
+ version = '1.22'
280
280
  VERSION = version
281
281
  __version__ = version
282
282
  COMMIT_DATE = '2025-09-10'
@@ -293,11 +293,11 @@ def read_text(path):
293
293
  def read_int(path):
294
294
  s = read_text(path)
295
295
  if s is None:
296
- return None
296
+ return 0
297
297
  try:
298
298
  return int(s)
299
299
  except Exception:
300
- return None
300
+ return 0
301
301
 
302
302
  def build_symlink_dict(dir_path):
303
303
  """
@@ -337,7 +337,7 @@ def read_discard_support(sysfs_block_path):
337
337
  return 'N/A'
338
338
  dmbytes = read_int(os.path.join(sysfs_block_path, "queue", "discard_max_bytes"))
339
339
  try:
340
- if (dmbytes or 0) > 0:
340
+ if dmbytes > 0:
341
341
  return 'Yes'
342
342
  else:
343
343
  return 'No'
@@ -345,7 +345,7 @@ def read_discard_support(sysfs_block_path):
345
345
  return 'N/A'
346
346
 
347
347
  @cache_decorator
348
- def get_parent_device_sysfs(sysfs_block_path):
348
+ def get_real_sysfs_device_path(sysfs_block_path):
349
349
  """
350
350
  Return the sysfs 'device' directory for this block node (resolves partition
351
351
  to its parent device as well).
@@ -360,7 +360,7 @@ def get_parent_device_sysfs(sysfs_block_path):
360
360
  def read_model_and_serial(sysfs_block_path):
361
361
  if not sysfs_block_path or not os.path.isdir(sysfs_block_path):
362
362
  return '', ''
363
- device_path = get_parent_device_sysfs(sysfs_block_path)
363
+ device_path = get_real_sysfs_device_path(sysfs_block_path)
364
364
  model = read_text(os.path.join(device_path, "model"))
365
365
  serial = read_text(os.path.join(device_path, "serial"))
366
366
  if serial is None:
@@ -375,12 +375,20 @@ def read_model_and_serial(sysfs_block_path):
375
375
  serial = ''
376
376
  return model, serial
377
377
 
378
+ def read_size(sysfs_block_path):# -> tuple[int | None, Any] | Literal['']:
379
+ if not sysfs_block_path or not os.path.isdir(sysfs_block_path):
380
+ return ''
381
+ size = read_int(os.path.join(sysfs_block_path, "size"))
382
+ return size
383
+
378
384
  MountEntry = namedtuple("MountEntry", ["MOUNTPOINT", "FSTYPE", "OPTIONS"])
379
385
  def parseMount():
380
386
  rtn = multiCMD.run_command('mount',timeout=1,quiet=True)
381
387
  mount_table = defaultdict(list)
382
388
  for line in rtn:
383
389
  device_name, _, line = line.partition(' on ')
390
+ if device_name.startswith(os.path.sep):
391
+ device_name = os.path.realpath(device_name)
384
392
  mount_point, _, line = line.partition(' type ')
385
393
  fstype, _ , options = line.partition(' (')
386
394
  options = options.rstrip(')').split(',')
@@ -429,7 +437,7 @@ def get_sector_size(sysfs_block_path):
429
437
  if get_partition_parent_name(sysfs_block_path):
430
438
  sysfs_block_path = os.path.join('/sys/class/block', os.path.basename(get_partition_parent_name(sysfs_block_path)))
431
439
  sector_size = read_int(os.path.join(sysfs_block_path, "queue", "hw_sector_size"))
432
- if sector_size is None:
440
+ if sector_size == 0:
433
441
  sector_size = read_int(os.path.join(sysfs_block_path, "queue", "logical_block_size"))
434
442
  return sector_size if sector_size else 512
435
443
 
@@ -503,7 +511,7 @@ def get_drives_info(print_bytes = False, use_1024 = False, mounted_only=False, b
503
511
  if parent_name not in smart_infos:
504
512
  smart_infos[parent_name] = multiCMD.run_command(f'{SMARTCTL_PATH} -H {parent_name}',timeout=2,quiet=True,wait_for_return=False,return_object=True)
505
513
  if block_device not in tptDict:
506
- sysfs_block_path = os.path.realpath(os.path.join('/sys/class/block', os.path.basename(block_device)))
514
+ sysfs_block_path = os.path.join('/sys/class/block', os.path.basename(block_device))
507
515
  tptDict[block_device] = get_read_write_rate_throughput_iter(sysfs_block_path)
508
516
  mount_table = parseMount()
509
517
  target_devices = set(block_devices)
@@ -568,6 +576,7 @@ def get_drives_info(print_bytes = False, use_1024 = False, mounted_only=False, b
568
576
  elif "denied" in line:
569
577
  smart = 'DENIED'
570
578
  break
579
+ size_bytes = read_size(os.path.join('/sys/class/block', os.path.basename(device_name)))
571
580
  if device_name in tptDict:
572
581
  try:
573
582
  rtpt, wtpt = next(tptDict[device_name])
@@ -603,13 +612,14 @@ def get_drives_info(print_bytes = False, use_1024 = False, mounted_only=False, b
603
612
  else:
604
613
  size = multiCMD.format_bytes(size_bytes, use_1024_bytes=use_1024, to_str=True) + 'B'
605
614
  if not full:
606
- device_name = device_name.lstrip('/dev/')
615
+ device_name = device_name.replace('/dev/', '')
607
616
  output.append([device_name, fstype, size, fsusepct, mountpoint, smart, label, uuid, model, serial, discard, rtpt, wtpt])
608
617
  else:
609
618
  if formated_only and device_name not in fstype_dict:
610
619
  continue
611
620
  fstype = fstype_dict.get(device_name, '')
612
- size_bytes = size_dict.get(device_name, 0)
621
+ if not size_bytes:
622
+ size_bytes = size_dict.get(device_name, 0)
613
623
  if size_bytes == 0 and not show_zero_size_devices:
614
624
  continue
615
625
  if print_bytes:
@@ -617,7 +627,7 @@ def get_drives_info(print_bytes = False, use_1024 = False, mounted_only=False, b
617
627
  else:
618
628
  size = multiCMD.format_bytes(size_bytes, use_1024_bytes=use_1024, to_str=True) + 'B'
619
629
  if not full:
620
- device_name = device_name.lstrip('/dev/')
630
+ device_name = device_name.replace('/dev/', '')
621
631
  output.append([device_name, fstype, size, fsusepct, mountpoint, smart, label, uuid, model, serial, discard, rtpt, wtpt])
622
632
  return output
623
633
 
@@ -1,6 +0,0 @@
1
- statblk.py,sha256=KzueRFpQZTcTJzrLPuC2kIRX0DilrnyyJJcGTfN2pEw,26804
2
- statblk-1.21.dist-info/METADATA,sha256=Zxv0Jkuz1hsATIkOG1cnRhOiFx-VF5SID3rWVEPGWMw,1465
3
- statblk-1.21.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4
- statblk-1.21.dist-info/entry_points.txt,sha256=JDz-sa6FIdaOckmlz9NbnhZXQaB5Yle-cTKgUQmAV40,41
5
- statblk-1.21.dist-info/top_level.txt,sha256=dBdU6_PD4tG_7uquWEs6YremqudiePASv3u3G59scf4,8
6
- statblk-1.21.dist-info/RECORD,,
File without changes