Module: check_mk
Branch: master
Commit: 355219f1637e2b0c093f8356a666b431bcc086e4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=355219f1637e2b…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Tue Aug 22 11:53:42 2017 +0200
Refactoring: Replace strange while-true-except-StopIteration construct in df
Change-Id: If59b80d6242f958e615c36f666e0cabebe80003f
---
checks/df | 78 +++++++++++++++++++++++++++++----------------------------------
1 file changed, 36 insertions(+), 42 deletions(-)
diff --git a/checks/df b/checks/df
index 2db54bf..d3e4435 100644
--- a/checks/df
+++ b/checks/df
@@ -94,49 +94,43 @@ def parse_df(info):
df_blocks = []
df_inodes = []
btrfs_devices = set() # We might generalize that later
- lines = iter(info)
-
- try:
- is_inode = False
- while True:
- line = lines.next()
- if line[-1] == '[df_inodes_start]':
- is_inode = True
- continue
- elif line[-1] == '[df_inodes_end]':
- is_inode = False
- continue
-
- try:
- int(line[1])
- except ValueError:
- pass
- else:
- line = [ line[0], None ] + line[1:]
-
- if not is_inode:
- # Handle known cases, where the file system contains spaces
- for index, entry in enumerate(line):
- if entry == "NTFS":
- line = [ " ".join(line[:index]) ] + [line[index]] +
line[index+1:index+5] + [ " ".join(line[index+5:]) ]
- break
-
- if line[2] == "File" and line[3] == "System":
- line = [ line[0], " ".join(line[1:4]) ] + line[4:]
-
- if line[1] == "btrfs":
- device = line[0]
- if device not in btrfs_devices:
- btrfs_devices.add(device)
- df_blocks.append(line[:6] + [ "btrfs " + line[0] ]) #
replace mount point with device
-
- else:
- df_blocks.append(line)
- else:
- df_inodes.append(line)
- except StopIteration:
- pass
+ is_inode = False
+ for line in info:
+ if line[-1] == '[df_inodes_start]':
+ is_inode = True
+ continue
+ elif line[-1] == '[df_inodes_end]':
+ is_inode = False
+ continue
+
+ try:
+ int(line[1])
+ except ValueError:
+ pass
+ else:
+ line = [ line[0], None ] + line[1:]
+
+ if not is_inode:
+ # Handle known cases, where the file system contains spaces
+ for index, entry in enumerate(line):
+ if entry == "NTFS":
+ line = [ " ".join(line[:index]) ] + [line[index]] +
line[index+1:index+5] + [ " ".join(line[index+5:]) ]
+ break
+
+ if line[2] == "File" and line[3] == "System":
+ line = [ line[0], " ".join(line[1:4]) ] + line[4:]
+
+ if line[1] == "btrfs":
+ device = line[0]
+ if device not in btrfs_devices:
+ btrfs_devices.add(device)
+ df_blocks.append(line[:6] + [ "btrfs " + line[0] ]) #
replace mount point with device
+
+ else:
+ df_blocks.append(line)
+ else:
+ df_inodes.append(line)
return df_blocks, df_inodes