Hello community, here is the log from the commit of package python-psutil for openSUSE:Factory checked in at 2015-10-28 17:30:41 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-psutil (Old) and /work/SRC/openSUSE:Factory/.python-psutil.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-psutil" Changes: -------- --- /work/SRC/openSUSE:Factory/python-psutil/python-psutil.changes 2015-10-01 09:29:20.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.python-psutil.new/python-psutil.changes 2015-10-28 17:30:47.000000000 +0100 @@ -1,0 +2,11 @@ +Mon Oct 26 21:09:10 UTC 2015 - mich...@stroeder.com + +- update to version 3.2.2 + +**Bug fixes** + +- #623: [Linux] process or system connections raises ValueError if IPv6 is not + supported by the system. +- #678: [Linux] can't install psutil due to bug in setup.py. + +------------------------------------------------------------------- Old: ---- psutil-3.2.1.tar.gz New: ---- psutil-3.2.2.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-psutil.spec ++++++ --- /var/tmp/diff_new_pack.ytBS4W/_old 2015-10-28 17:30:48.000000000 +0100 +++ /var/tmp/diff_new_pack.ytBS4W/_new 2015-10-28 17:30:48.000000000 +0100 @@ -17,7 +17,7 @@ Name: python-psutil -Version: 3.2.1 +Version: 3.2.2 Release: 0 Summary: A process utilities module for Python License: BSD-3-Clause ++++++ psutil-3.2.1.tar.gz -> psutil-3.2.2.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/.git-pre-commit new/psutil-3.2.2/.git-pre-commit --- old/psutil-3.2.1/.git-pre-commit 2015-08-07 14:05:06.000000000 +0200 +++ new/psutil-3.2.2/.git-pre-commit 2015-09-06 18:15:02.000000000 +0200 @@ -38,7 +38,7 @@ # flake8 failed = False for path in files: - ret = subprocess.call("flake8 %s" % path, shell=True) + ret = subprocess.call("python -m flake8 %s" % path, shell=True) if ret != 0: failed = True if failed: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/.travis.yml new/psutil-3.2.2/.travis.yml --- old/psutil-3.2.1/.travis.yml 2015-08-03 23:38:14.000000000 +0200 +++ new/psutil-3.2.2/.travis.yml 2015-09-22 13:34:14.000000000 +0200 @@ -4,7 +4,6 @@ include: - python: 2.6 - python: 2.7 - - python: 3.2 - python: 3.3 - python: 3.4 - language: generic @@ -15,9 +14,6 @@ env: PYVER=py27 - language: generic os: osx - env: PYVER=py32 - - language: generic - os: osx env: PYVER=py33 - language: generic os: osx diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/CREDITS new/psutil-3.2.2/CREDITS --- old/psutil-3.2.1/CREDITS 2015-08-30 18:06:42.000000000 +0200 +++ new/psutil-3.2.2/CREDITS 2015-10-04 18:32:38.000000000 +0200 @@ -325,3 +325,15 @@ N: maozguttman W: https://github.com/maozguttman I: 659 + +N: wiggin15 +W: https://github.com/wiggin15 +I: 517, 607, 610 + +N: dasumin +W: https://github.com/dasumin +I: 541 + +N: Mike Sarahan +W: https://github.com/msarahan +I: 688 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/HISTORY.rst new/psutil-3.2.2/HISTORY.rst --- old/psutil-3.2.1/HISTORY.rst 2015-09-03 17:16:38.000000000 +0200 +++ new/psutil-3.2.2/HISTORY.rst 2015-10-04 18:32:54.000000000 +0200 @@ -1,5 +1,22 @@ Bug tracker at https://github.com/giampaolo/psutil/issues +3.2.2 - 2015-10-04 +================== + +**Bug fixes** + +- #517: [SunOS] net_io_counters failed to detect network interfaces + correctly on Solaris 10 +- #541: [FreeBSD] disk_io_counters r/w times were expressed in seconds instead + of milliseconds. (patch by dasumin) +- #610: [SunOS] fix build and tests on Solaris 10 +- #623: [Linux] process or system connections raises ValueError if IPv6 is not + supported by the system. +- #678: [Linux] can't install psutil due to bug in setup.py. +- #688: [Windows] compilation fails with MSVC 2015, Python 3.5. (patch by + Mike Sarahan) + + 3.2.1 - 2015-09-03 ================== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/PKG-INFO new/psutil-3.2.2/PKG-INFO --- old/psutil-3.2.1/PKG-INFO 2015-09-03 17:30:30.000000000 +0200 +++ new/psutil-3.2.2/PKG-INFO 2015-10-04 18:39:09.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: psutil -Version: 3.2.1 +Version: 3.2.2 Summary: psutil is a cross-platform library for retrieving information onrunning processes and system utilization (CPU, memory, disks, network)in Python. Home-page: https://github.com/giampaolo/psutil Author: Giampaolo Rodola @@ -358,6 +358,7 @@ Timeline ======== + - 2015-10-04: `psutil-3.2.2.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.2.2.tar.gz>`_ - 2015-09-03: `psutil-3.2.1.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.2.1.tar.gz>`_ - 2015-09-02: `psutil-3.2.0.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.2.0.tar.gz>`_ - 2015-07-15: `psutil-3.1.1.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.1.1.tar.gz>`_ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/README.rst new/psutil-3.2.2/README.rst --- old/psutil-3.2.1/README.rst 2015-09-03 17:18:54.000000000 +0200 +++ new/psutil-3.2.2/README.rst 2015-10-04 18:33:12.000000000 +0200 @@ -350,6 +350,7 @@ Timeline ======== +- 2015-10-04: `psutil-3.2.2.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.2.2.tar.gz>`_ - 2015-09-03: `psutil-3.2.1.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.2.1.tar.gz>`_ - 2015-09-02: `psutil-3.2.0.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.2.0.tar.gz>`_ - 2015-07-15: `psutil-3.1.1.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.1.1.tar.gz>`_ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/TODO new/psutil-3.2.2/TODO --- old/psutil-3.2.1/TODO 2015-08-06 11:18:45.000000000 +0200 +++ new/psutil-3.2.2/TODO 2015-09-06 16:19:55.000000000 +0200 @@ -6,11 +6,25 @@ https://github.com/giampaolo/psutil/issues +PLATFORMS +========= + + * #615 (PR): OpenBSD + + * #355 (patch): Android + + * #429 (patch): NetBSD + + * #605 (branch): AIX + + * #276: GNU/Hurd + + * DragonFlyBSD + + HIGHER PRIORITY =============== - * OpenBSD support. - * #371: CPU temperature (apparently OSX and Linux only; on Linux it requires lm-sensors lib). @@ -36,16 +50,6 @@ LOWER PRIORITY ============== - * #355: Android support. - - * #276: GNU/Hurd support. - - * #429: NetBSD support. - - * DragonFlyBSD support? - - * AIX support? - * examples/taskmgr-gui.py (using tk). * system-wide number of open file descriptors: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/docs/xxx new/psutil-3.2.2/docs/xxx --- old/psutil-3.2.1/docs/xxx 2015-07-15 02:47:19.000000000 +0200 +++ new/psutil-3.2.2/docs/xxx 1970-01-01 01:00:00.000000000 +0100 @@ -1,11 +0,0 @@ -cpu 1974613 1749 485728 6305758 80280 15 5924 0 0 0 - -cpu0 519156 374 132999 5977865 72925 10 1458 0 0 0 - -cpu1 524667 401 125931 108960 2110 4 2214 0 0 0 - -cpu2 462286 520 117046 109514 2666 0 828 0 0 0 - -cpu3 468502 453 109750 109418 2578 0 1424 0 0 0 - - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/__init__.py new/psutil-3.2.2/psutil/__init__.py --- old/psutil-3.2.1/psutil/__init__.py 2015-09-03 17:16:54.000000000 +0200 +++ new/psutil-3.2.2/psutil/__init__.py 2015-09-06 16:06:22.000000000 +0200 @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. @@ -158,7 +157,7 @@ ] __all__.extend(_psplatform.__extra__all__) __author__ = "Giampaolo Rodola'" -__version__ = "3.2.1" +__version__ = "3.2.2" version_info = tuple([int(num) for num in __version__.split('.')]) AF_LINK = _psplatform.AF_LINK _TOTAL_PHYMEM = None diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_common.py new/psutil-3.2.2/psutil/_common.py --- old/psutil-3.2.1/psutil/_common.py 2015-08-05 04:02:49.000000000 +0200 +++ new/psutil-3.2.2/psutil/_common.py 2015-09-19 13:39:03.000000000 +0200 @@ -7,6 +7,7 @@ """Common objects shared by all _ps* modules.""" from __future__ import division +import contextlib import errno import functools import os @@ -140,6 +141,19 @@ return stat.S_ISREG(st.st_mode) +def supports_ipv6(): + """Return True if IPv6 is supported on this platform.""" + if not socket.has_ipv6 or not hasattr(socket, "AF_INET6"): + return False + try: + sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + with contextlib.closing(sock): + sock.bind(("::1", 0)) + return True + except socket.error: + return False + + def sockfam_to_enum(num): """Convert a numeric socket family value to an IntEnum member. If it's not a known member, return the numeric value itself. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_compat.py new/psutil-3.2.2/psutil/_compat.py --- old/psutil-3.2.1/psutil/_compat.py 2015-07-12 16:48:30.000000000 +0200 +++ new/psutil-3.2.2/psutil/_compat.py 2015-09-03 18:46:00.000000000 +0200 @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_psbsd.py new/psutil-3.2.2/psutil/_psbsd.py --- old/psutil-3.2.1/psutil/_psbsd.py 2015-07-09 11:43:49.000000000 +0200 +++ new/psutil-3.2.2/psutil/_psbsd.py 2015-09-03 18:46:00.000000000 +0200 @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_pslinux.py new/psutil-3.2.2/psutil/_pslinux.py --- old/psutil-3.2.1/psutil/_pslinux.py 2015-09-03 10:38:48.000000000 +0200 +++ new/psutil-3.2.2/psutil/_pslinux.py 2015-09-19 13:44:44.000000000 +0200 @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -23,7 +21,7 @@ from . import _psposix from . import _psutil_linux as cext from . import _psutil_posix as cext_posix -from ._common import isfile_strict, usage_percent +from ._common import isfile_strict, usage_percent, supports_ipv6 from ._common import NIC_DUPLEX_FULL, NIC_DUPLEX_HALF, NIC_DUPLEX_UNKNOWN from ._compat import PY3, long @@ -357,6 +355,10 @@ # --- network +class _Ipv6UnsupportedError(Exception): + pass + + class Connections: """A wrapper on top of /proc/net/* files, retrieving per-process and system-wide open connections (TCP, UDP, UNIX) similarly to @@ -466,15 +468,22 @@ # return socket.inet_ntop(socket.AF_INET6, # ''.join(ip[i:i+4][::-1] for i in xrange(0, 16, 4))) ip = base64.b16decode(ip) - # see: https://github.com/giampaolo/psutil/issues/201 - if sys.byteorder == 'little': - ip = socket.inet_ntop( - socket.AF_INET6, - struct.pack('>4I', *struct.unpack('<4I', ip))) - else: - ip = socket.inet_ntop( - socket.AF_INET6, - struct.pack('<4I', *struct.unpack('<4I', ip))) + try: + # see: https://github.com/giampaolo/psutil/issues/201 + if sys.byteorder == 'little': + ip = socket.inet_ntop( + socket.AF_INET6, + struct.pack('>4I', *struct.unpack('<4I', ip))) + else: + ip = socket.inet_ntop( + socket.AF_INET6, + struct.pack('<4I', *struct.unpack('<4I', ip))) + except ValueError: + # see: https://github.com/giampaolo/psutil/issues/623 + if not supports_ipv6(): + raise _Ipv6UnsupportedError + else: + raise return (ip, port) def process_inet(self, file, family, type_, inodes, filter_pid=None): @@ -509,8 +518,11 @@ status = TCP_STATUSES[status] else: status = _common.CONN_NONE - laddr = self.decode_address(laddr, family) - raddr = self.decode_address(raddr, family) + try: + laddr = self.decode_address(laddr, family) + raddr = self.decode_address(raddr, family) + except _Ipv6UnsupportedError: + continue yield (fd, family, type_, laddr, raddr, status, pid) def process_unix(self, file, family, inodes, filter_pid=None): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_psosx.py new/psutil-3.2.2/psutil/_psosx.py --- old/psutil-3.2.1/psutil/_psosx.py 2015-06-04 03:59:23.000000000 +0200 +++ new/psutil-3.2.2/psutil/_psosx.py 2015-09-03 18:46:00.000000000 +0200 @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_psposix.py new/psutil-3.2.2/psutil/_psposix.py --- old/psutil-3.2.1/psutil/_psposix.py 2015-06-04 03:59:23.000000000 +0200 +++ new/psutil-3.2.2/psutil/_psposix.py 2015-09-03 18:46:00.000000000 +0200 @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_pssunos.py new/psutil-3.2.2/psutil/_pssunos.py --- old/psutil-3.2.1/psutil/_pssunos.py 2015-07-09 11:43:49.000000000 +0200 +++ new/psutil-3.2.2/psutil/_pssunos.py 2015-09-06 16:04:00.000000000 +0200 @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -97,13 +95,13 @@ # ...nevertheless I can't manage to obtain the same numbers as 'swap' # cmdline utility, so let's parse its output (sigh!) p = subprocess.Popen(['/usr/bin/env', 'PATH=/usr/sbin:/sbin:%s' % - os.environ['PATH'], 'swap', '-l', '-k'], + os.environ['PATH'], 'swap', '-l'], stdout=subprocess.PIPE) stdout, stderr = p.communicate() if PY3: stdout = stdout.decode(sys.stdout.encoding) if p.returncode != 0: - raise RuntimeError("'swap -l -k' failed (retcode=%s)" % p.returncode) + raise RuntimeError("'swap -l' failed (retcode=%s)" % p.returncode) lines = stdout.strip().split('\n')[1:] if not lines: @@ -112,10 +110,8 @@ for line in lines: line = line.split() t, f = line[-2:] - t = t.replace('K', '') - f = f.replace('K', '') - total += int(int(t) * 1024) - free += int(int(f) * 1024) + total += int(int(t) * 512) + free += int(int(f) * 512) used = total - free percent = usage_percent(used, total, _round=1) return _common.sswap(total, used, free, percent, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_psutil_bsd.c new/psutil-3.2.2/psutil/_psutil_bsd.c --- old/psutil-3.2.1/psutil/_psutil_bsd.c 2015-09-03 17:06:01.000000000 +0200 +++ new/psutil-3.2.2/psutil/_psutil_bsd.c 2015-09-22 13:28:43.000000000 +0200 @@ -63,7 +63,8 @@ // convert a timeval struct to a double #define TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0) - +// convert a bintime struct to milliseconds +#define BT2MSEC(bt) (bt.sec * 1000 + ( ( (uint64_t) 1000000000 * (uint32_t) (bt.frac >> 32) ) >> 32 ) / 1000000) /* * Utility function which fills a kinfo_proc struct based on process pid @@ -1555,10 +1556,9 @@ current.operations[DEVSTAT_WRITE], // no writes current.bytes[DEVSTAT_READ], // bytes read current.bytes[DEVSTAT_WRITE], // bytes written - (long long)devstat_compute_etime( - ¤t.duration[DEVSTAT_READ], NULL), // r time - (long long)devstat_compute_etime( - ¤t.duration[DEVSTAT_WRITE], NULL)); // w time + (long long) BT2MSEC(current.duration[DEVSTAT_READ]), // r time + (long long) BT2MSEC(current.duration[DEVSTAT_WRITE]) // w time + ); // finished transactions if (!py_disk_info) goto error; if (PyDict_SetItemString(py_retdict, disk_name, py_disk_info)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_psutil_linux.c new/psutil-3.2.2/psutil/_psutil_linux.c --- old/psutil-3.2.1/psutil/_psutil_linux.c 2015-09-03 11:09:16.000000000 +0200 +++ new/psutil-3.2.2/psutil/_psutil_linux.c 2015-09-05 18:22:50.000000000 +0200 @@ -55,17 +55,18 @@ #endif -#if PSUTIL_HAVE_IOPRIO -enum { - IOPRIO_WHO_PROCESS = 1, -}; - // May happen on old RedHat versions, see: // https://github.com/giampaolo/psutil/issues/607 #ifndef DUPLEX_UNKNOWN #define DUPLEX_UNKNOWN 0xff #endif + +#if PSUTIL_HAVE_IOPRIO +enum { + IOPRIO_WHO_PROCESS = 1, +}; + static inline int ioprio_get(int which, int who) { return syscall(__NR_ioprio_get, which, who); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_psutil_posix.c new/psutil-3.2.2/psutil/_psutil_posix.c --- old/psutil-3.2.1/psutil/_psutil_posix.c 2015-08-07 12:00:36.000000000 +0200 +++ new/psutil-3.2.2/psutil/_psutil_posix.c 2015-09-06 16:04:00.000000000 +0200 @@ -13,9 +13,14 @@ #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> -#include <ifaddrs.h> #include <net/if.h> +#ifdef PSUTIL_SUNOS10 +#include "arch/solaris10/ifaddrs.h" +#else +#include <ifaddrs.h> +#endif + #ifdef __linux #include <netdb.h> #include <linux/if_packet.h> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_psutil_sunos.c new/psutil-3.2.2/psutil/_psutil_sunos.c --- old/psutil-3.2.1/psutil/_psutil_sunos.c 2015-09-03 17:10:31.000000000 +0200 +++ new/psutil-3.2.2/psutil/_psutil_sunos.c 2015-09-06 16:04:00.000000000 +0200 @@ -675,6 +675,9 @@ kstat_ctl_t *kc = NULL; kstat_t *ksp; kstat_named_t *rbytes, *wbytes, *rpkts, *wpkts, *ierrs, *oerrs; + int ret; + int sock = -1; + struct lifreq ifr; PyObject *py_retdict = PyDict_New(); PyObject *py_ifc_info = NULL; @@ -685,25 +688,32 @@ if (kc == NULL) goto error; + sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock == -1) { + PyErr_SetFromErrno(PyExc_OSError); + goto error; + } + ksp = kc->kc_chain; while (ksp != NULL) { if (ksp->ks_type != KSTAT_TYPE_NAMED) goto next; if (strcmp(ksp->ks_class, "net") != 0) goto next; - /* - // XXX "lo" (localhost) interface makes kstat_data_lookup() fail - // (maybe because "ifconfig -a" says it's a virtual interface?). - if ((strcmp(ksp->ks_module, "link") != 0) && - (strcmp(ksp->ks_module, "lo") != 0)) { - goto skip; - */ - if ((strcmp(ksp->ks_module, "link") != 0)) + // skip 'lo' (localhost) because it doesn't have the statistics we need + // and it makes kstat_data_lookup() fail + if (strcmp(ksp->ks_module, "lo") == 0) + goto next; + + // check if this is a network interface by sending a ioctl + strncpy(ifr.lifr_name, ksp->ks_name, sizeof(ifr.lifr_name)); + ret = ioctl(sock, SIOCGLIFFLAGS, &ifr); + if (ret == -1) goto next; if (kstat_read(kc, ksp, NULL) == -1) { errno = 0; - continue; + goto next; } rbytes = (kstat_named_t *)kstat_data_lookup(ksp, "rbytes"); @@ -720,26 +730,32 @@ goto error; } -#if defined(_INT64_TYPE) - py_ifc_info = Py_BuildValue("(KKKKkkii)", - wbytes->value.ui64, - rbytes->value.ui64, - wpkts->value.ui64, - rpkts->value.ui64, - ierrs->value.ui32, - oerrs->value.ui32, -#else - py_ifc_info = Py_BuildValue("(kkkkkkii)", - wbytes->value.ui32, - rbytes->value.ui32, - wpkts->value.ui32, - rpkts->value.ui32, - ierrs->value.ui32, - oerrs->value.ui32, -#endif - 0, // dropin not supported - 0 // dropout not supported - ); + if (rbytes->data_type == KSTAT_DATA_UINT64) + { + py_ifc_info = Py_BuildValue("(KKKKIIii)", + wbytes->value.ui64, + rbytes->value.ui64, + wpkts->value.ui64, + rpkts->value.ui64, + ierrs->value.ui32, + oerrs->value.ui32, + 0, // dropin not supported + 0 // dropout not supported + ); + } + else + { + py_ifc_info = Py_BuildValue("(IIIIIIii)", + wbytes->value.ui32, + rbytes->value.ui32, + wpkts->value.ui32, + rpkts->value.ui32, + ierrs->value.ui32, + oerrs->value.ui32, + 0, // dropin not supported + 0 // dropout not supported + ); + } if (!py_ifc_info) goto error; if (PyDict_SetItemString(py_retdict, ksp->ks_name, py_ifc_info)) @@ -752,6 +768,7 @@ } kstat_close(kc); + close(sock); return py_retdict; error: @@ -759,6 +776,9 @@ Py_DECREF(py_retdict); if (kc != NULL) kstat_close(kc); + if (sock != -1) { + close(sock); + } return NULL; } @@ -1138,7 +1158,7 @@ kstat_t *ksp; kstat_named_t *knp; int ret; - int sock = 0; + int sock = -1; int duplex; int speed; @@ -1152,12 +1172,14 @@ if (kc == NULL) goto error; sock = socket(AF_INET, SOCK_DGRAM, 0); - if (sock == -1) + if (sock == -1) { + PyErr_SetFromErrno(PyExc_OSError); goto error; + } for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) { if (strcmp(ksp->ks_class, "net") == 0) { - struct ifreq ifr; + struct lifreq ifr; kstat_read(kc, ksp, NULL); if (ksp->ks_type != KSTAT_TYPE_NAMED) @@ -1165,13 +1187,13 @@ if (strcmp(ksp->ks_class, "net") != 0) continue; - strncpy(ifr.ifr_name, ksp->ks_name, sizeof(ifr.ifr_name)); - ret = ioctl(sock, SIOCGIFFLAGS, &ifr); + strncpy(ifr.lifr_name, ksp->ks_name, sizeof(ifr.lifr_name)); + ret = ioctl(sock, SIOCGLIFFLAGS, &ifr); if (ret == -1) continue; // not a network interface // is up? - if ((ifr.ifr_flags & IFF_UP) != 0) { + if ((ifr.lifr_flags & IFF_UP) != 0) { if ((knp = kstat_data_lookup(ksp, "link_up")) != NULL) { if (knp->value.ui32 != 0u) py_is_up = Py_True; @@ -1204,12 +1226,12 @@ speed = 0; // mtu - ret = ioctl(sock, SIOCGIFMTU, &ifr); + ret = ioctl(sock, SIOCGLIFMTU, &ifr); if (ret == -1) goto error; py_ifc_info = Py_BuildValue("(Oiii)", py_is_up, duplex, speed, - ifr.ifr_mtu); + ifr.lifr_mtu); if (!py_ifc_info) goto error; if (PyDict_SetItemString(py_retdict, ksp->ks_name, py_ifc_info)) @@ -1226,7 +1248,7 @@ Py_XDECREF(py_is_up); Py_XDECREF(py_ifc_info); Py_DECREF(py_retdict); - if (sock != 0) + if (sock != -1) close(sock); if (kc != NULL) kstat_close(kc); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/_pswindows.py new/psutil-3.2.2/psutil/_pswindows.py --- old/psutil-3.2.1/psutil/_pswindows.py 2015-08-30 16:31:44.000000000 +0200 +++ new/psutil-3.2.2/psutil/_pswindows.py 2015-09-03 18:46:00.000000000 +0200 @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/arch/solaris/v10/ifaddrs.c new/psutil-3.2.2/psutil/arch/solaris/v10/ifaddrs.c --- old/psutil-3.2.1/psutil/arch/solaris/v10/ifaddrs.c 1970-01-01 01:00:00.000000000 +0100 +++ new/psutil-3.2.2/psutil/arch/solaris/v10/ifaddrs.c 2015-09-06 16:04:00.000000000 +0200 @@ -0,0 +1,124 @@ +/* Refrences: + * https://lists.samba.org/archive/samba-technical/2009-February/063079.html + * http://stackoverflow.com/questions/4139405/#4139811 + * https://code.google.com/p/openpgm/source/browse/trunk/openpgm/pgm/getifaddrs.c + */ + +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <net/if.h> +#include <netinet/in.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/sockio.h> + +#include "ifaddrs.h" + +#define MAX(x,y) ((x)>(y)?(x):(y)) +#define SIZE(p) MAX((p).ss_len,sizeof(p)) + + +static struct sockaddr * +sa_dup (struct sockaddr *sa1) +{ + struct sockaddr *sa2; + size_t sz = sizeof(sa1); + sa2 = (struct sockaddr *) calloc(1,sz); + memcpy(sa2,sa1,sz); + return(sa2); +} + + +void freeifaddrs (struct ifaddrs *ifp) +{ + if (NULL == ifp) return; + free(ifp->ifa_name); + free(ifp->ifa_addr); + free(ifp->ifa_netmask); + free(ifp->ifa_dstaddr); + freeifaddrs(ifp->ifa_next); + free(ifp); +} + + +int getifaddrs (struct ifaddrs **ifap) +{ + int sd = -1; + char *ccp, *ecp; + struct lifconf ifc; + struct lifreq *ifr; + struct lifnum lifn; + struct ifaddrs *cifa = NULL; /* current */ + struct ifaddrs *pifa = NULL; /* previous */ + const size_t IFREQSZ = sizeof(struct lifreq); + + sd = socket(AF_INET, SOCK_STREAM, 0); + if (sd < 0) + goto error; + + ifc.lifc_buf = NULL; + *ifap = NULL; + /* find how much memory to allocate for the SIOCGLIFCONF call */ + lifn.lifn_family = AF_UNSPEC; + lifn.lifn_flags = 0; + if (ioctl(sd, SIOCGLIFNUM, &lifn) < 0) + goto error; + + /* Sun and Apple code likes to pad the interface count here in case interfaces + * are coming up between calls */ + lifn.lifn_count += 4; + + ifc.lifc_family = AF_UNSPEC; + ifc.lifc_len = lifn.lifn_count * sizeof(struct lifreq); + ifc.lifc_buf = calloc(1, ifc.lifc_len); + if (ioctl(sd, SIOCGLIFCONF, &ifc) < 0) + goto error; + + ccp = (char *)ifc.lifc_req; + ecp = ccp + ifc.lifc_len; + + while (ccp < ecp) { + + ifr = (struct lifreq *) ccp; + cifa = (struct ifaddrs *) calloc(1, sizeof(struct ifaddrs)); + cifa->ifa_next = NULL; + cifa->ifa_name = strdup(ifr->lifr_name); + + if (pifa == NULL) *ifap = cifa; /* first one */ + else pifa->ifa_next = cifa; + + if (ioctl(sd, SIOCGLIFADDR, ifr, IFREQSZ) < 0) + goto error; + cifa->ifa_addr = sa_dup((struct sockaddr*)&ifr->lifr_addr); + + if (ioctl(sd, SIOCGLIFNETMASK, ifr, IFREQSZ) < 0) + goto error; + cifa->ifa_netmask = sa_dup((struct sockaddr*)&ifr->lifr_addr); + + cifa->ifa_flags = 0; + cifa->ifa_dstaddr = NULL; + + if (0 == ioctl(sd, SIOCGLIFFLAGS, ifr)) /* optional */ + cifa->ifa_flags = ifr->lifr_flags; + + if (ioctl(sd, SIOCGLIFDSTADDR, ifr, IFREQSZ) < 0) { + if (0 == ioctl(sd, SIOCGLIFBRDADDR, ifr, IFREQSZ)) + cifa->ifa_dstaddr = sa_dup((struct sockaddr*)&ifr->lifr_addr); + } + else cifa->ifa_dstaddr = sa_dup((struct sockaddr*)&ifr->lifr_addr); + + pifa = cifa; + ccp += IFREQSZ; + } + free(ifc.lifc_buf); + close(sd); + return 0; +error: + if (ifc.lifc_buf != NULL) + free(ifc.lifc_buf); + if (sd != -1) + close(sd); + return (-1); +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/arch/solaris/v10/ifaddrs.h new/psutil-3.2.2/psutil/arch/solaris/v10/ifaddrs.h --- old/psutil-3.2.1/psutil/arch/solaris/v10/ifaddrs.h 1970-01-01 01:00:00.000000000 +0100 +++ new/psutil-3.2.2/psutil/arch/solaris/v10/ifaddrs.h 2015-09-06 16:04:00.000000000 +0200 @@ -0,0 +1,26 @@ +/* Reference: https://lists.samba.org/archive/samba-technical/2009-February/063079.html */ + + +#ifndef __IFADDRS_H___ +#define __IFADDRS_H___ + +#include <sys/socket.h> +#include <net/if.h> + +#undef ifa_dstaddr +#undef ifa_broadaddr +#define ifa_broadaddr ifa_dstaddr + +struct ifaddrs { + struct ifaddrs *ifa_next; + char *ifa_name; + unsigned int ifa_flags; + struct sockaddr *ifa_addr; + struct sockaddr *ifa_netmask; + struct sockaddr *ifa_dstaddr; +}; + +extern int getifaddrs(struct ifaddrs **); +extern void freeifaddrs(struct ifaddrs *); + +#endif \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil/arch/windows/ntextapi.h new/psutil-3.2.2/psutil/arch/windows/ntextapi.h --- old/psutil-3.2.1/psutil/arch/windows/ntextapi.h 2015-08-26 10:48:21.000000000 +0200 +++ new/psutil-3.2.2/psutil/arch/windows/ntextapi.h 2015-10-04 18:30:59.000000000 +0200 @@ -177,7 +177,6 @@ DWORD ProcessInformationLength ); - typedef enum _PROCESSINFOCLASS2 { _ProcessBasicInformation, ProcessQuotaLimits, @@ -209,8 +208,12 @@ /* added after XP+ */ _ProcessImageFileName, ProcessLUIDDeviceMapsEnabled, +// MSVC 2015 starts forcing C++11 standard, which does not allow duplicate +// unscoped enumerations. It doesn't matter that this is C code, MSVC is a C++ compiler. +#if _MSC_VER < 1900 ProcessBreakOnTermination, - ProcessDebugObjectHandle, +#endif + ProcessDebugObjectHandle=ProcessLUIDDeviceMapsEnabled+2, ProcessDebugFlags, ProcessHandleTracing, ProcessIoPriority, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil.egg-info/PKG-INFO new/psutil-3.2.2/psutil.egg-info/PKG-INFO --- old/psutil-3.2.1/psutil.egg-info/PKG-INFO 2015-09-03 17:30:30.000000000 +0200 +++ new/psutil-3.2.2/psutil.egg-info/PKG-INFO 2015-10-04 18:39:09.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: psutil -Version: 3.2.1 +Version: 3.2.2 Summary: psutil is a cross-platform library for retrieving information onrunning processes and system utilization (CPU, memory, disks, network)in Python. Home-page: https://github.com/giampaolo/psutil Author: Giampaolo Rodola @@ -358,6 +358,7 @@ Timeline ======== + - 2015-10-04: `psutil-3.2.2.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.2.2.tar.gz>`_ - 2015-09-03: `psutil-3.2.1.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.2.1.tar.gz>`_ - 2015-09-02: `psutil-3.2.0.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.2.0.tar.gz>`_ - 2015-07-15: `psutil-3.1.1.tar.gz <https://pypi.python.org/packages/source/p/psutil/psutil-3.1.1.tar.gz>`_ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/psutil.egg-info/SOURCES.txt new/psutil-3.2.2/psutil.egg-info/SOURCES.txt --- old/psutil-3.2.1/psutil.egg-info/SOURCES.txt 2015-09-03 17:30:30.000000000 +0200 +++ new/psutil-3.2.2/psutil.egg-info/SOURCES.txt 2015-10-04 18:39:09.000000000 +0200 @@ -19,7 +19,6 @@ docs/conf.py docs/index.rst docs/make.bat -docs/xxx docs/_static/copybutton.js docs/_static/favicon.ico docs/_static/logo.png @@ -76,6 +75,8 @@ psutil/arch/bsd/process_info.h psutil/arch/osx/process_info.c psutil/arch/osx/process_info.h +psutil/arch/solaris/v10/ifaddrs.c +psutil/arch/solaris/v10/ifaddrs.h psutil/arch/windows/glpi.h psutil/arch/windows/inet_ntop.c psutil/arch/windows/inet_ntop.h diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/setup.py new/psutil-3.2.2/setup.py --- old/psutil-3.2.1/setup.py 2015-09-03 16:49:42.000000000 +0200 +++ new/psutil-3.2.2/setup.py 2015-09-06 16:07:06.000000000 +0200 @@ -15,6 +15,7 @@ import os import sys import tempfile +import platform try: from setuptools import setup, Extension except ImportError: @@ -47,6 +48,9 @@ @contextlib.contextmanager def silenced_output(stream_name): class DummyFile(io.BytesIO): + # see: https://github.com/giampaolo/psutil/issues/678 + errors = "ignore" + def write(self, s): pass @@ -64,13 +68,15 @@ # POSIX if os.name == 'posix': - libraries = [] - if sys.platform.startswith("sunos"): - libraries.append('socket') posix_extension = Extension( 'psutil._psutil_posix', - sources=['psutil/_psutil_posix.c'], - libraries=libraries) + sources=['psutil/_psutil_posix.c']) + if sys.platform.startswith("sunos"): + posix_extension.libraries.append('socket') + if platform.release() == '5.10': + posix_extension.sources.append('psutil/arch/solaris/v10/ifaddrs.c') + posix_extension.define_macros.append(('PSUTIL_SUNOS10', 1)) + # Windows if sys.platform.startswith("win32"): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/test/_linux.py new/psutil-3.2.2/test/_linux.py --- old/psutil-3.2.1/test/_linux.py 2015-08-31 12:22:58.000000000 +0200 +++ new/psutil-3.2.2/test/_linux.py 2015-09-19 13:44:16.000000000 +0200 @@ -426,6 +426,18 @@ assert ret self.assertEqual(ret[0].fstype, 'zfs') + @mock.patch('psutil._pslinux.socket.inet_ntop', side_effect=ValueError) + @mock.patch('psutil._pslinux.supports_ipv6', return_value=False) + def test_connections_ipv6_not_supported(self, supports_ipv6, inet_ntop): + # see: https://github.com/giampaolo/psutil/issues/623 + try: + s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + self.addCleanup(s.close) + s.bind(("::1", 0)) + except socket.error: + pass + psutil.net_connections(kind='inet6') + # --- tests for specific kernel versions @unittest.skipUnless( diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/test/_posix.py new/psutil-3.2.2/test/_posix.py --- old/psutil-3.2.1/test/_posix.py 2015-07-11 13:52:57.000000000 +0200 +++ new/psutil-3.2.2/test/_posix.py 2015-09-06 16:04:00.000000000 +0200 @@ -150,11 +150,12 @@ # Note: this test might fail if the OS is starting/killing # other processes in the meantime if SUNOS: - cmd = ["ps", "ax"] + cmd = ["ps", "-A", "-o", "pid"] else: cmd = ["ps", "ax", "-o", "pid"] p = get_test_subprocess(cmd, stdout=subprocess.PIPE) output = p.communicate()[0].strip() + assert p.poll() == 0 if PY3: output = str(output, sys.stdout.encoding) pids_ps = [] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/test/_sunos.py new/psutil-3.2.2/test/_sunos.py --- old/psutil-3.2.1/test/_sunos.py 2015-07-09 11:43:49.000000000 +0200 +++ new/psutil-3.2.2/test/_sunos.py 2015-09-06 16:04:00.000000000 +0200 @@ -17,7 +17,7 @@ class SunOSSpecificTestCase(unittest.TestCase): def test_swap_memory(self): - out = sh('env PATH=/usr/sbin:/sbin:%s swap -l -k' % os.environ['PATH']) + out = sh('env PATH=/usr/sbin:/sbin:%s swap -l' % os.environ['PATH']) lines = out.strip().split('\n')[1:] if not lines: raise ValueError('no swap device(s) configured') @@ -25,10 +25,8 @@ for line in lines: line = line.split() t, f = line[-2:] - t = t.replace('K', '') - f = f.replace('K', '') - total += int(int(t) * 1024) - free += int(int(f) * 1024) + total += int(int(t) * 512) + free += int(int(f) * 512) used = total - free psutil_swap = psutil.swap_memory() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/test/_windows.py new/psutil-3.2.2/test/_windows.py --- old/psutil-3.2.1/test/_windows.py 2015-08-31 13:49:20.000000000 +0200 +++ new/psutil-3.2.2/test/_windows.py 2015-09-07 09:56:56.000000000 +0200 @@ -18,6 +18,7 @@ from test_psutil import APPVEYOR, WINDOWS from test_psutil import get_test_subprocess, reap_children, unittest +from test_psutil import retry_before_failing import mock try: @@ -207,6 +208,7 @@ self.assertEqual(wmi_pids, psutil_pids) @unittest.skipIf(wmi is None, "wmi module is not installed") + @retry_before_failing() def test_disks(self): ps_parts = psutil.disk_partitions(all=True) wmi_parts = wmi.WMI().Win32_LogicalDisk() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/test/test_memory_leaks.py new/psutil-3.2.2/test/test_memory_leaks.py --- old/psutil-3.2.1/test/test_memory_leaks.py 2015-08-07 12:01:00.000000000 +0200 +++ new/psutil-3.2.2/test/test_memory_leaks.py 2015-09-06 16:04:00.000000000 +0200 @@ -360,13 +360,11 @@ @skip_if_linux() def test_cpu_count_logical(self): - psutil.cpu_count = psutil._psplatform.cpu_count_logical - self.execute('cpu_count') + self.execute('cpu_count', logical=True) @skip_if_linux() def test_cpu_count_physical(self): - psutil.cpu_count = psutil._psplatform.cpu_count_physical - self.execute('cpu_count') + self.execute('cpu_count', logical=False) @skip_if_linux() def test_boot_time(self): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/psutil-3.2.1/test/test_psutil.py new/psutil-3.2.2/test/test_psutil.py --- old/psutil-3.2.1/test/test_psutil.py 2015-09-03 17:04:32.000000000 +0200 +++ new/psutil-3.2.2/test/test_psutil.py 2015-10-04 18:30:50.000000000 +0200 @@ -53,6 +53,7 @@ import mock # requires "pip install mock" import psutil +from psutil._common import supports_ipv6 from psutil._compat import PY3, callable, long, unicode if sys.version_info < (2, 7): @@ -499,21 +500,29 @@ return decorator -def supports_ipv6(): - """Return True if IPv6 is supported on this platform.""" - if not socket.has_ipv6 or not hasattr(socket, "AF_INET6"): - return False - sock = None - try: - sock = socket.socket(AF_INET6, SOCK_STREAM) - sock.bind(("::1", 0)) - except (socket.error, socket.gaierror): - return False +def create_temp_executable_file(suffix): + tmpdir = None + if TRAVIS and OSX: + tmpdir = "/private/tmp" + fd, path = tempfile.mkstemp( + prefix='psu', suffix=suffix, dir=tmpdir) + os.close(fd) + + if which("gcc"): + fd, c_file = tempfile.mkstemp( + prefix='psu', suffix='.c', dir=tmpdir) + os.close(fd) + with open(c_file, "w") as f: + f.write("void main() { pause(); }") + subprocess.check_call(["gcc", c_file, "-o", path]) + safe_remove(c_file) else: - return True - finally: - if sock is not None: - sock.close() + # fallback - use python's executable + shutil.copyfile(sys.executable, path) + if POSIX: + st = os.stat(path) + os.chmod(path, st.st_mode | stat.S_IEXEC) + return path if WINDOWS: @@ -755,7 +764,7 @@ self.assertEqual(logical, len(psutil.cpu_times(percpu=True))) self.assertGreaterEqual(logical, 1) # - if LINUX: + if os.path.exists("/proc/cpuinfo"): with open("/proc/cpuinfo") as fd: cpuinfo_data = fd.read() if "physical id" not in cpuinfo_data: @@ -1385,7 +1394,8 @@ def test_terminal(self): terminal = psutil.Process().terminal() if sys.stdin.isatty(): - self.assertEqual(terminal, sh('tty')) + tty = os.path.realpath(sh('tty')) + self.assertEqual(terminal, tty) else: assert terminal, repr(terminal) @@ -1645,7 +1655,8 @@ if not nt.path.startswith('['): assert os.path.isabs(nt.path), nt.path if POSIX: - assert os.path.exists(nt.path), nt.path + assert os.path.exists(nt.path) or \ + os.path.islink(nt.path), nt.path else: # XXX - On Windows we have this strange behavior with # 64 bit dlls: they are visible via explorer but cannot @@ -1685,7 +1696,8 @@ except AssertionError: if WINDOWS and len(exe) == len(PYTHON): # on Windows we don't care about case sensitivity - self.assertEqual(exe.lower(), PYTHON.lower()) + normcase = os.path.normcase + self.assertEqual(normcase(exe), normcase(PYTHON)) else: # certain platforms such as BSD are more accurate returning: # "/usr/local/bin/python2.7" @@ -1708,36 +1720,20 @@ pyexe = os.path.basename(os.path.realpath(sys.executable)).lower() assert pyexe.startswith(name), (pyexe, name) - @unittest.skipUnless(POSIX, "posix only") - # TODO: add support for other compilers - @unittest.skipUnless(which("gcc"), "gcc not available") def test_prog_w_funky_name(self): # Test that name(), exe() and cmdline() correctly handle programs # with funky chars such as spaces and ")", see: # https://github.com/giampaolo/psutil/issues/628 - # funky_path = os.path.join(tempfile.gettempdir(), "foo bar )") - if OSX: - tmpdir = "/private/tmp" - else: - tmpdir = "/tmp" - fd, funky_path = tempfile.mkstemp( - prefix='psutil-', suffix='foo bar )', dir=tmpdir) - os.close(fd) - fd, c_file = tempfile.mkstemp( - prefix='psutil-', suffix='.c', dir=tmpdir) - os.close(fd) - self.addCleanup(safe_remove, c_file) + funky_path = create_temp_executable_file('foo bar )') self.addCleanup(safe_remove, funky_path) - with open(c_file, "w") as f: - f.write("void main() { pause(); }") - subprocess.check_call(["gcc", c_file, "-o", funky_path]) sproc = get_test_subprocess( [funky_path, "arg1", "arg2", "", "arg3", ""]) p = psutil.Process(sproc.pid) # ...in order to try to prevent occasional failures on travis wait_for_pid(p.pid) + normcase = os.path.normcase self.assertEqual(p.name(), os.path.basename(funky_path)) - self.assertEqual(p.exe(), funky_path) + self.assertEqual(normcase(p.exe()), normcase(funky_path)) self.assertEqual( p.cmdline(), [funky_path, "arg1", "arg2", "", "arg3", ""]) @@ -2920,6 +2916,29 @@ # docstring self.assertEqual(foo.__doc__, "foo docstring") + def test_supports_ipv6(self): + if supports_ipv6(): + with mock.patch('psutil._common.socket') as s: + s.has_ipv6 = False + assert not supports_ipv6() + with mock.patch('psutil._common.socket.socket', + side_effect=socket.error) as s: + assert not supports_ipv6() + assert s.called + with mock.patch('psutil._common.socket.socket', + side_effect=socket.gaierror) as s: + assert not supports_ipv6() + assert s.called + with mock.patch('psutil._common.socket.socket.bind', + side_effect=socket.gaierror) as s: + assert not supports_ipv6() + assert s.called + else: + if hasattr(socket, 'AF_INET6'): + with self.assertRaises(Exception): + sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + sock.bind(("::1", 0)) + def test_isfile_strict(self): from psutil._common import isfile_strict this_file = os.path.abspath(__file__) @@ -3092,13 +3111,9 @@ @classmethod def setUpClass(cls): - with tempfile.NamedTemporaryFile() as f: - tdir = os.path.dirname(f.name) - cls.uexe = os.path.realpath(os.path.join(tdir, "psutil-è.exe")) - shutil.copyfile(sys.executable, cls.uexe) - if POSIX: - st = os.stat(cls.uexe) - os.chmod(cls.uexe, st.st_mode | stat.S_IEXEC) + cls.uexe = create_temp_executable_file('è') + cls.ubasename = os.path.basename(cls.uexe) + assert 'è' in cls.ubasename @classmethod def tearDownClass(cls): @@ -3114,7 +3129,7 @@ subp = get_test_subprocess(cmd=[self.uexe]) p = psutil.Process(subp.pid) self.assertIsInstance(p.name(), str) - self.assertEqual(os.path.basename(p.name()), "psutil-è.exe") + self.assertEqual(os.path.basename(p.name()), self.ubasename) def test_proc_name(self): subp = get_test_subprocess(cmd=[self.uexe]) @@ -3123,7 +3138,7 @@ name = py2_strencode(psutil._psplatform.cext.proc_name(subp.pid)) else: name = psutil.Process(subp.pid).name() - self.assertEqual(name, "psutil-è.exe") + self.assertEqual(name, self.ubasename) def test_proc_cmdline(self): subp = get_test_subprocess(cmd=[self.uexe]) @@ -3147,10 +3162,7 @@ new = set(p.open_files()) path = (new - start).pop().path self.assertIsInstance(path, str) - if WINDOWS: - self.assertEqual(path.lower(), self.uexe.lower()) - else: - self.assertEqual(path, self.uexe) + self.assertEqual(os.path.normcase(path), os.path.normcase(self.uexe)) def main():