Skip to content

Commit

Permalink
refactor/move some utilities into _common.py
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Apr 11, 2019
1 parent 55f4b24 commit c0aba35
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 36 deletions.
2 changes: 1 addition & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 13 additions & 0 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 1 addition & 10 deletions psutil/_psaix.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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
Expand Down Expand Up @@ -101,16 +102,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
# =====================================================================
Expand Down
17 changes: 2 additions & 15 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
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
Expand Down Expand Up @@ -207,19 +207,6 @@ class IOPriority(enum.IntEnum):
# =====================================================================


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
Expand Down
11 changes: 1 addition & 10 deletions psutil/_pssunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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
Expand Down Expand Up @@ -113,16 +114,6 @@
'pmmap_ext', 'addr perms ' + ' '.join(pmmap_grouped._fields))


# =====================================================================
# --- utils
# =====================================================================


def get_procfs_path():
"""Return updated psutil.PROCFS_PATH constant."""
return sys.modules['psutil'].PROCFS_PATH


# =====================================================================
# --- memory
# =====================================================================
Expand Down

0 comments on commit c0aba35

Please sign in to comment.