mirror of
https://github.com/munki/munki.git
synced 2026-04-23 04:59:17 -05:00
Fix but in getIdleSeconds() where ioreg output is split, but there are inconsistent number of whitespaces.
I ran into a machine where "parts" was: ['|', '|', '"HIDIdleTime"', '=', '1458195167613966'], and since parts[3] is "=" getIdleSeconds() was crashing trying to convert it to int(). So return int(int(parts[3])/1000000000) should really be parts[4] on this machine, but this may be inconsistent on different machines? # /usr/sbin/ioreg -c IOHIDSystem -d 4 | grep Idle | | "HIDIdleTime" = 1458351496253133 So let's just use regex to parse the integer out of the line more safely. git-svn-id: http://munki.googlecode.com/svn/trunk@1103 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
@@ -21,6 +21,7 @@ managedsoftwareupdate
|
||||
import grp
|
||||
import optparse
|
||||
import os
|
||||
import re
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -64,8 +65,11 @@ def getIdleSeconds():
|
||||
ioreglines = str(output).splitlines()
|
||||
for line in ioreglines:
|
||||
if 'Idle' in line:
|
||||
parts = line.split()
|
||||
return int(int(parts[3])/1000000000)
|
||||
idle_re = re.search(' (\d+)', line)
|
||||
idle_time = 0
|
||||
if idle_re:
|
||||
idle_time = idle_re.group(0)
|
||||
return int(int(idle_time)/1000000000)
|
||||
|
||||
|
||||
def networkUp():
|
||||
|
||||
Reference in New Issue
Block a user