From 3ba5f4d961808e49e34f0d1c78349c11ace6d8a8 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Sun, 13 Mar 2011 15:59:38 +0100 Subject: [PATCH] getloadavg: try harder to get loadavg on alt platforms Patch from Michael Haubenwallner to read loadavg from `uptime` on AIX and HP-UX. --- pym/_emerge/getloadavg.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pym/_emerge/getloadavg.py b/pym/_emerge/getloadavg.py index e9babf13e..8e62ebf90 100644 --- a/pym/_emerge/getloadavg.py +++ b/pym/_emerge/getloadavg.py @@ -2,6 +2,7 @@ # Distributed under the terms of the GNU General Public License v2 from portage import os +import platform getloadavg = getattr(os, "getloadavg", None) if getloadavg is None: @@ -11,8 +12,16 @@ if getloadavg is None: Raises OSError if the load average was unobtainable. """ try: - loadavg_str = open('/proc/loadavg').readline() - except IOError: + if platform.system() in ["AIX", "HP-UX"]: + loadavg_str = os.popen('LANG=C /usr/bin/uptime 2>/dev/null').readline().split() + while loadavg_str[0] != 'load' and loadavg_str[1] != 'average:': + loadavg_str = loadavg_str[1:] + loadavg_str = loadavg_str[2:5] + loadavg_str = [x.rstrip(',') for x in loadavg_str] + loadavg_str = ' '.join(loadavg_str) + else: + loadavg_str = open('/proc/loadavg').readline() + except (IOError, IndexError): # getloadavg() is only supposed to raise OSError, so convert raise OSError('unknown') loadavg_split = loadavg_str.split() -- 2.26.2