diff options
author | vg <vg@devys.org> | 2018-10-05 09:54:15 +0200 |
---|---|---|
committer | vg <vg@devys.org> | 2018-10-05 09:54:15 +0200 |
commit | 23253ce0b022470a047eb6b512fb85beaf884388 (patch) | |
tree | b0e3f91c6c12a0313e90affdf2d08fc2d54f4646 | |
parent | b6e37c8773167c64baccb6c252cdfd57f2d48f29 (diff) | |
download | scripts-23253ce0b022470a047eb6b512fb85beaf884388.tar.gz scripts-23253ce0b022470a047eb6b512fb85beaf884388.tar.bz2 scripts-23253ce0b022470a047eb6b512fb85beaf884388.zip |
make parsing more robust with explicit split/strip
-rwxr-xr-x | scripts/critical_hibernate.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/scripts/critical_hibernate.py b/scripts/critical_hibernate.py index f7128e2..a51a97c 100755 --- a/scripts/critical_hibernate.py +++ b/scripts/critical_hibernate.py @@ -39,8 +39,9 @@ try: batfd = os.open(sysfs_path, os.O_RDONLY) print('monitoring %s (threshold %d%%)' % (sysfs_path, threshold)) while True: - uevent_dict = dict((e.split(b'=') - for e in os.pread(batfd, 1024, 0).split())) + uevent_dict = dict((tuple(x.strip() for x in e.split(b'=')) + for e in os.pread(batfd, 1024, 0).split(b'\n') + if e)) capacity = int(uevent_dict[b'POWER_SUPPLY_CAPACITY']) status = uevent_dict[b'POWER_SUPPLY_STATUS'] if status == b'Discharging' and capacity <= threshold: |