aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvg <vg@devys.org>2018-10-05 09:54:15 +0200
committervg <vg@devys.org>2018-10-05 09:54:15 +0200
commit23253ce0b022470a047eb6b512fb85beaf884388 (patch)
treeb0e3f91c6c12a0313e90affdf2d08fc2d54f4646
parentb6e37c8773167c64baccb6c252cdfd57f2d48f29 (diff)
downloadscripts-23253ce0b022470a047eb6b512fb85beaf884388.tar.gz
scripts-23253ce0b022470a047eb6b512fb85beaf884388.tar.bz2
scripts-23253ce0b022470a047eb6b512fb85beaf884388.zip
make parsing more robust with explicit split/strip
-rwxr-xr-xscripts/critical_hibernate.py5
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: