handle systems with no labelled devices

This commit is contained in:
Martinez 2016-10-09 20:19:11 +02:00
parent 4b6a059f1d
commit 51d1cd1926

View file

@ -547,7 +547,11 @@ class StatsPart(Part):
names = [] names = []
first_mountpoint = True first_mountpoint = True
btrfs_encountered_devices = set() btrfs_encountered_devices = set()
device_to_label = {os.path.join("/dev", os.path.basename(os.readlink(os.path.join("/dev/disk/by-label", x)))): x for x in os.listdir("/dev/disk/by-label")}
if os.path.isdir("/dev/disk/by-label"):
device_to_label = {os.path.join("/dev", os.path.basename(os.readlink(os.path.join("/dev/disk/by-label", x)))): x for x in os.listdir("/dev/disk/by-label")}
else:
device_to_label = {}
with open("/proc/self/mounts") as f: with open("/proc/self/mounts") as f:
for line in f: for line in f:
@ -585,7 +589,7 @@ class StatsPart(Part):
continue continue
btrfs_encountered_devices.add(device) btrfs_encountered_devices.add(device)
short_name = " "+device_to_label[device][0] if device in device_to_label: short_name = " "+device_to_label[device][0]
btrfs_raw = command(["/sbin/btrfs", "fi", "usage", "-b", dir]) btrfs_raw = command(["/sbin/btrfs", "fi", "usage", "-b", dir])