Skip to content

Commit

Permalink
#811: raise a meaningful error message if on Windows XP
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Nov 8, 2016
1 parent 8d51580 commit 1f84be8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
**Enhancements**

- 939_: tar.gz distribution went from 1.8M to 258K.
- 811_: [Windows] provide a more meaningful error message if trying to use
psutil on unsupported Windows XP.


5.0.0
Expand Down
4 changes: 4 additions & 0 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
pass

elif WINDOWS:
from ._common import assert_supported_winver
assert_supported_winver()
del assert_supported_winver

from . import _pswindows as _psplatform
from ._psutil_windows import ABOVE_NORMAL_PRIORITY_CLASS # NOQA
from ._psutil_windows import BELOW_NORMAL_PRIORITY_CLASS # NOQA
Expand Down
9 changes: 9 additions & 0 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,12 @@ def inner(self, *args, **kwargs):
return getattr(self, replacement)(*args, **kwargs)
return inner
return outer


def assert_supported_winver():
"""Raise an error if this Windows version is not supported."""
if WINDOWS and sys.getwindowsversion()[0] < 6:
msg = "this Windows version is too old (< Windows Vista); "
msg += "psutil 3.4.2 is the latest version which supports Windows "
msg += "2000, XP and 2003 server"
raise RuntimeError(msg)
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

HERE = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(HERE, "psutil"))

from _common import assert_supported_winver # NOQA
from _common import BSD # NOQA
from _common import FREEBSD # NOQA
from _common import LINUX # NOQA
Expand Down Expand Up @@ -97,6 +99,8 @@ def write(self, s):

# Windows
if WINDOWS:
assert_supported_winver()

def get_winver():
maj, min = sys.getwindowsversion()[0:2]
return '0x0%s' % ((maj * 100) + min)
Expand Down

0 comments on commit 1f84be8

Please sign in to comment.