diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-12 00:54:11 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-12 00:54:11 +0200 |
commit | c0aba35a78649c453f0c89ab163a58a8efb4639e (patch) | |
tree | 589b4f69491ed6aefb38b3069be351c98d69c66a | |
parent | 55f4b24642b53c747540a02b4161753d1ea7e1f9 (diff) | |
download | psutil-c0aba35a78649c453f0c89ab163a58a8efb4639e.tar.gz |
refactor/move some utilities into _common.py
-rw-r--r-- | psutil/__init__.py | 2 | ||||
-rw-r--r-- | psutil/_common.py | 13 | ||||
-rw-r--r-- | psutil/_psaix.py | 11 | ||||
-rw-r--r-- | psutil/_pslinux.py | 17 | ||||
-rw-r--r-- | psutil/_pssunos.py | 11 |
5 files changed, 18 insertions, 36 deletions
diff --git a/psutil/__init__.py b/psutil/__init__.py index 4adb4509..bd968f5d 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -2473,7 +2473,7 @@ def test(): # pragma: no cover else: cputime = '' - user = p.info['username'] + user = p.info['username'] or '' if not user and POSIX: try: user = p.uids()[0] diff --git a/psutil/_common.py b/psutil/_common.py index 0b4f5308..e3b45417 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -619,3 +619,16 @@ def bytes2human(n, format="%(value).1f%(symbol)s"): value = float(n) / prefix[symbol] return format % locals() return format % dict(symbol=symbols[0], value=n) + + +def get_procfs_path(): + """Return updated psutil.PROCFS_PATH constant.""" + return sys.modules['psutil'].PROCFS_PATH + + +if PY3: + def decode(s): + return s.decode(encoding=ENCODING, errors=ENCODING_ERRS) +else: + def decode(s): + return s diff --git a/psutil/_psaix.py b/psutil/_psaix.py index ff086b90..b0aefa99 100644 --- a/psutil/_psaix.py +++ b/psutil/_psaix.py @@ -20,6 +20,7 @@ from . import _psposix from . import _psutil_aix as cext from . import _psutil_posix as cext_posix from ._common import AF_INET6 +from ._common import get_procfs_path from ._common import memoize_when_activated from ._common import NIC_DUPLEX_FULL from ._common import NIC_DUPLEX_HALF @@ -102,16 +103,6 @@ svmem = namedtuple('svmem', ['total', 'available', 'percent', 'used', 'free']) # ===================================================================== -# --- utils -# ===================================================================== - - -def get_procfs_path(): - """Return updated psutil.PROCFS_PATH constant.""" - return sys.modules['psutil'].PROCFS_PATH - - -# ===================================================================== # --- memory # ===================================================================== diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 1f8ddb93..eccfeed2 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -25,8 +25,8 @@ from . import _common from . import _psposix from . import _psutil_linux as cext from . import _psutil_posix as cext_posix -from ._common import ENCODING -from ._common import ENCODING_ERRS +from ._common import decode +from ._common import get_procfs_path from ._common import isfile_strict from ._common import memoize from ._common import memoize_when_activated @@ -207,19 +207,6 @@ pio = namedtuple('pio', ['read_count', 'write_count', # ===================================================================== -if PY3: - def decode(s): - return s.decode(encoding=ENCODING, errors=ENCODING_ERRS) -else: - def decode(s): - return s - - -def get_procfs_path(): - """Return updated psutil.PROCFS_PATH constant.""" - return sys.modules['psutil'].PROCFS_PATH - - def readlink(path): """Wrapper around os.readlink().""" assert isinstance(path, basestring), path diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py index 67166e46..47a18181 100644 --- a/psutil/_pssunos.py +++ b/psutil/_pssunos.py @@ -17,6 +17,7 @@ from . import _psposix from . import _psutil_posix as cext_posix from . import _psutil_sunos as cext from ._common import AF_INET6 +from ._common import get_procfs_path from ._common import isfile_strict from ._common import memoize_when_activated from ._common import sockfam_to_enum @@ -114,16 +115,6 @@ pmmap_ext = namedtuple( # ===================================================================== -# --- utils -# ===================================================================== - - -def get_procfs_path(): - """Return updated psutil.PROCFS_PATH constant.""" - return sys.modules['psutil'].PROCFS_PATH - - -# ===================================================================== # --- memory # ===================================================================== |