diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-01-24 16:39:24 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-01-24 16:39:24 +0100 |
commit | c69f2591f07341681cc56dbf93cf08cbb3cba48a (patch) | |
tree | 9704c9f4c2973dde49f19020d197f89c99b8b124 | |
parent | ff1547b98bbda585e65654bed7c938d8060478ef (diff) | |
download | psutil-c69f2591f07341681cc56dbf93cf08cbb3cba48a.tar.gz |
rename function
-rw-r--r-- | psutil/__init__.py | 57 | ||||
-rw-r--r-- | psutil/_common.py | 2 | ||||
-rw-r--r-- | psutil/_pslinux.py | 2 | ||||
-rwxr-xr-x | psutil/tests/test_system.py | 12 |
4 files changed, 45 insertions, 28 deletions
diff --git a/psutil/__init__.py b/psutil/__init__.py index b4a60d32..afd30e90 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -185,7 +185,7 @@ __all__ = [ "net_io_counters", "net_connections", "net_if_addrs", # network "net_if_stats", "disk_io_counters", "disk_partitions", "disk_usage", # disk - "users", "boot_time", # "temperatures" # others + "users", "boot_time", # "sensors_temperatures" # others ] __all__.extend(_psplatform.__extra__all__) __author__ = "Giampaolo Rodola'" @@ -2161,33 +2161,13 @@ def net_if_stats(): # ===================================================================== -# --- other system related functions +# --- sensors # ===================================================================== -def boot_time(): - """Return the system boot time expressed in seconds since the epoch.""" - # Note: we are not caching this because it is subject to - # system clock updates. - return _psplatform.boot_time() - - -def users(): - """Return users currently connected on the system as a list of - namedtuples including the following fields. +if hasattr(_psplatform, "sensors_temperatures"): - - user: the name of the user - - terminal: the tty or pseudo-tty associated with the user, if any. - - host: the host name associated with the entry, if any. - - started: the creation time as a floating point number expressed in - seconds since the epoch. - """ - return _psplatform.users() - - -if hasattr(_psplatform, "temperatures"): - - def temperatures(fahrenheit=False): + def sensors_temperatures(fahrenheit=False): """Return hardware temperatures as a list of named tuples. Each entry represents a "sensor" monitoring a certain hardware resource. @@ -2202,7 +2182,7 @@ if hasattr(_psplatform, "temperatures"): return (n * 9 / 5) + 32 ret = [] - for rawtuple in _psplatform.temperatures(): + for rawtuple in _psplatform.sensors_temperatures(): name, label, current, high, critical = rawtuple if fahrenheit: current = to_fahrenheit(current) @@ -2217,7 +2197,32 @@ if hasattr(_psplatform, "temperatures"): ret.append(_common.shwtemp(name, label, current, high, critical)) return ret - __all__.append("temperatures") + __all__.append("sensors_temperatures") + + +# ===================================================================== +# --- other system related functions +# ===================================================================== + + +def boot_time(): + """Return the system boot time expressed in seconds since the epoch.""" + # Note: we are not caching this because it is subject to + # system clock updates. + return _psplatform.boot_time() + + +def users(): + """Return users currently connected on the system as a list of + namedtuples including the following fields. + + - user: the name of the user + - terminal: the tty or pseudo-tty associated with the user, if any. + - host: the host name associated with the entry, if any. + - started: the creation time as a floating point number expressed in + seconds since the epoch. + """ + return _psplatform.users() # ===================================================================== diff --git a/psutil/_common.py b/psutil/_common.py index fd8bc186..8866ef19 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -158,7 +158,7 @@ scpustats = namedtuple( 'scpustats', ['ctx_switches', 'interrupts', 'soft_interrupts', 'syscalls']) # psutil.cpu_freq() scpufreq = namedtuple('scpufreq', ['current', 'min', 'max']) -# psutil.temperatures() +# psutil.sensors_temperatures() shwtemp = namedtuple( 'shwtemp', ['name', 'label', 'current', 'high', 'critical']) diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 0206d893..28e4a77c 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1096,7 +1096,7 @@ def boot_time(): if os.path.exists('/sys/class/hwmon'): - def temperatures(): + def sensors_temps(): """Return hardware (CPU and others) temperatures as a list of named tuples including name, label, current, max and critical temperatures. diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py index 4cbdb056..0ee4b6b6 100755 --- a/psutil/tests/test_system.py +++ b/psutil/tests/test_system.py @@ -753,6 +753,18 @@ class TestSystemAPIs(unittest.TestCase): for name in names: self.assertIs(getattr(psutil, name), False, msg=name) + @unittest.skipUnless(hasattr(psutil, "sensors_temperatures"), + "platform not suported") + def test_sensors_temperatures(self): + ls = psutil.sensors_temperatures() + for entry in ls: + if entry.current is not None: + self.assertGreaterEqual(entry.current, 0) + if entry.high is not None: + self.assertGreaterEqual(entry.high, 0) + if entry.critical is not None: + self.assertGreaterEqual(entry.critical, 0) + if __name__ == '__main__': run_test_module_by_name(__file__) |