From ecf26dfbc65e0c39001e8283e776c50899f90e1b Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 13 Mar 2014 19:38:05 +0400 Subject: [PATCH 1/3] Update powerline for new psutil Fixes #835 --- powerline/segments/common.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/powerline/segments/common.py b/powerline/segments/common.py index 01c18a20..06f3d563 100644 --- a/powerline/segments/common.py +++ b/powerline/segments/common.py @@ -517,8 +517,14 @@ try: if data: yield interface, data.bytes_recv, data.bytes_sent - def _get_user(segment_info): - return psutil.Process(os.getpid()).username + # Pre psutil-2.0.0: psutil.Process.username has type property + if callable(psutil.Process.username): + def _get_user(segment_info): + return psutil.Process(os.getpid()).username() + # psutil-2.0.0: psutil.Process.username is unbound method + else: + def _get_user(segment_info): + return psutil.Process(os.getpid()).username class CPULoadPercentSegment(ThreadedSegment): interval = 1 From 678d47c61e455666fea0a3d0d2ed8fa60b926feb Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 13 Mar 2014 19:41:59 +0400 Subject: [PATCH 2/3] Switch comments --- powerline/segments/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerline/segments/common.py b/powerline/segments/common.py index 06f3d563..56a51f6c 100644 --- a/powerline/segments/common.py +++ b/powerline/segments/common.py @@ -517,11 +517,11 @@ try: if data: yield interface, data.bytes_recv, data.bytes_sent - # Pre psutil-2.0.0: psutil.Process.username has type property + # psutil-2.0.0: psutil.Process.username is unbound method if callable(psutil.Process.username): def _get_user(segment_info): return psutil.Process(os.getpid()).username() - # psutil-2.0.0: psutil.Process.username is unbound method + # pre psutil-2.0.0: psutil.Process.username has type property else: def _get_user(segment_info): return psutil.Process(os.getpid()).username From 55858e1a9d651018369453de6f72b658e2cffbe4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 13 Mar 2014 20:05:52 +0400 Subject: [PATCH 3/3] Fix tests for new psutil --- tests/test_segments.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/test_segments.py b/tests/test_segments.py index 48fde0c2..bfea4f6a 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -169,7 +169,18 @@ class TestCommon(TestCase): def test_user(self): new_os = new_module('os', getpid=lambda: 1) - new_psutil = new_module('psutil', Process=lambda pid: Args(username='def')) + + class Process(object): + def __init__(self, pid): + pass + + def username(self): + return 'def' + + if hasattr(common, 'psutil') and not callable(common.psutil.Process.username): + username = property(username) + + new_psutil = new_module('psutil', Process=Process) pl = Pl() with replace_env('USER', 'def') as segment_info: common.username = False