<commit_before>#!/usr/bin/env python
#
# $Id$
#

"""psutil is a module providing convenience functions for managing
processes in a portable way by using Python.
"""

__all__ = [
    "NoSuchProcess",
    "AccessDenied",
    "NUM_CPUS",
    "Process",
    "test",
    "CPUTimes",
    "pid_exists",
    "get_pid_list",
    "process_iter",
    "get_process_list",
    "TOTAL_PHYMEM",
    "avail_phymem",
    "used_phymem",
    "total_virtmem",
    "avail_virtmem",
    "used_virtmem",
    "cpu_times",
    "cpu_percent",
    ]

__version__ = '0.2.0'


import sys
import os
import time
import signal
import warnings
try:
    import pwd, grp
except ImportError:
    pwd = grp = None

from psutil.error import *

# import the appropriate module for our platform only
if sys.platform.lower().startswith("linux"):
    from psutil._pslinux import *
    __all__.extend(["cached_phymem", "phymem_buffers"])

elif sys.platform.lower().startswith("win32"):
    from psutil._psmswindows import *

elif sys.platform.lower().startswith("darwin"):
    from psutil._psosx import *

elif sys.platform.lower().startswith("freebsd"):
    from psutil._psbsd import *

else:
    raise NotImplementedError('platform %s is not supported' % sys.platform)


class CPUTimes:
    """This class contains information about CPU times.
    It is not used directly but it's returned as an instance by
    psutil.cpu_times() function.

    Every CPU time is accessible in form of an attribute and represents
    the time CPU has spent in the given mode.

    The attributes availability varies depending on the platform.
    Here follows a list of all available attributes:

     - user
     - system
     - idle
     - nice (UNIX)
     - iowait (Linux)
     - irq (Linux, FreeBSD)
     - softirq (Linux)
    """

    def __init__(self, **kwargs):
        self.__attrs = []
        for name in kwargs:
            setattr(self, name, kwargs[name])
            self.__attrs.append(name)

    def __str__(self):
        string = []
        for attr in self.__attrs:
            value = getattr(self, attr)
            string.append("%s=%s" %(attr, value))
        return '; '.join(string)

    def __iter__(self):
        for attr in self.__attrs:
            yield getattr(self, attr)


class _ProcessInfo(object):
    """Class that allows the process information to be passed between
    external code and psutil.  Used directly by the Process class.
    """

    def __init__(self, pid, ppid=None, name=None, exe=None, cmdline=None,
                       uid=None, gid=None):
        self.pid = pid
        self.ppid = ppid
        self.name = name
        self.exe = exe
        self.cmdline = cmdline
        # if we have the cmdline but not the exe, figure it out from argv[0]
        if cmdline and not exe:
            if hasattr(os, 'access') and hasattr(os, 'X_OK'):
                _exe = os.path.realpath(cmdline[0])
                if os.path.isfile(_exe) and os.access(_exe, os.X_OK):
                    self.exe = _exe
        self.uid = uid
        self.gid = gid
        self.create = None
        self.username = None


class Process(object):
    """Represents an OS process."""

    def __init__(self, pid):
        """Create a new Process object, raises NoSuchProcess if the PID
        does not exist, and ValueError if the parameter is not an
        integer PID."""
        if not isinstance(pid, int):
            raise ValueError("An integer is required")
        if not pid_exists(pid):
            raise NoSuchProcess(pid, None, "no process found with PID %s" % pid)
        # platform-specific modules define an Impl implementation class
        self._platform_impl = Impl()
        self._procinfo = _ProcessInfo(pid)
        self.is_proxy = True
        # try to init CPU times, if it raises AccessDenied then suppress
        # it so it won't interrupt the constructor. First call to
        # get_cpu_percent() will trigger the AccessDenied exception
        # instead.
        try:
            self._last_sys_time = time.time()
            self._last_user_time, self._last_kern_time = self.get_cpu_times()
        except AccessDenied:
            self._last_user_time, self._last_kern_time = None, None

    def __str__(self):
        try:
            pid = self.pid
            name = repr(self.name)
            cmdline = self.cmdline and repr(' '.join(self.cmdline))
        except NoSuchProcess:
            details = "<pid=%s (terminated)>" % self.pid
        except AccessDenied:
            details = "<pid=%s>" % (self.pid)
        else:
            if cmdline:
                details = "<pid=%s, name=%s, cmdline=%s>" % (pid, name, cmdline)
            else:
                details = "<pid=%s, name=%s>" % (pid, name)
        return "%s.%s %s" % (self.__class__.__module__, 
                             self.__class__.__name__, details)

    def __eq__(self, other):
        """Test for equality with another Process object based on PID<commit_msg>provide a useful output string also on repr()<commit_after>#!/usr/bin/env python
#
# $Id$
#

"""psutil is a module providing convenience functions for managing
processes in a portable way by using Python.
"""

__all__ = [
    "NoSuchProcess",
    "AccessDenied",
    "NUM_CPUS",
    "Process",
    "test",
    "CPUTimes",
    "pid_exists",
    "get_pid_list",
    "process_iter",
    "get_process_list",
    "TOTAL_PHYMEM",
    "avail_phymem",
    "used_phymem",
    "total_virtmem",
    "avail_virtmem",
    "used_virtmem",
    "cpu_times",
    "cpu_percent",
    ]

__version__ = '0.2.0'


import sys
import os
import time
import signal
import warnings
try:
    import pwd, grp
except ImportError:
    pwd = grp = None

from psutil.error import *

# import the appropriate module for our platform only
if sys.platform.lower().startswith("linux"):
    from psutil._pslinux import *
    __all__.extend(["cached_phymem", "phymem_buffers"])

elif sys.platform.lower().startswith("win32"):
    from psutil._psmswindows import *

elif sys.platform.lower().startswith("darwin"):
    from psutil._psosx import *

elif sys.platform.lower().startswith("freebsd"):
    from psutil._psbsd import *

else:
    raise NotImplementedError('platform %s is not supported' % sys.platform)


class CPUTimes:
    """This class contains information about CPU times.
    It is not used directly but it's returned as an instance by
    psutil.cpu_times() function.

    Every CPU time is accessible in form of an attribute and represents
    the time CPU has spent in the given mode.

    The attributes availability varies depending on the platform.
    Here follows a list of all available attributes:

     - user
     - system
     - idle
     - nice (UNIX)
     - iowait (Linux)
     - irq (Linux, FreeBSD)
     - softirq (Linux)
    """

    def __init__(self, **kwargs):
        self.__attrs = []
        for name in kwargs:
            setattr(self, name, kwargs[name])
            self.__attrs.append(name)

    def __str__(self):
        string = []
        for attr in self.__attrs:
            value = getattr(self, attr)
            string.append("%s=%s" %(attr, value))
        return '; '.join(string)

    def __iter__(self):
        for attr in self.__attrs:
            yield getattr(self, attr)


class _ProcessInfo(object):
    """Class that allows the process information to be passed between
    external code and psutil.  Used directly by the Process class.
    """

    def __init__(self, pid, ppid=None, name=None, exe=None, cmdline=None,
                       uid=None, gid=None):
        self.pid = pid
        self.ppid = ppid
        self.name = name
        self.exe = exe
        self.cmdline = cmdline
        # if we have the cmdline but not the exe, figure it out from argv[0]
        if cmdline and not exe:
            if hasattr(os, 'access') and hasattr(os, 'X_OK'):
                _exe = os.path.realpath(cmdline[0])
                if os.path.isfile(_exe) and os.access(_exe, os.X_OK):
                    self.exe = _exe
        self.uid = uid
        self.gid = gid
        self.create = None
        self.username = None


class Process(object):
    """Represents an OS process."""

    def __init__(self, pid):
        """Create a new Process object, raises NoSuchProcess if the PID
        does not exist, and ValueError if the parameter is not an
        integer PID."""
        if not isinstance(pid, int):
            raise ValueError("An integer is required")
        if not pid_exists(pid):
            raise NoSuchProcess(pid, None, "no process found with PID %s" % pid)
        # platform-specific modules define an Impl implementation class
        self._platform_impl = Impl()
        self._procinfo = _ProcessInfo(pid)
        self.is_proxy = True
        # try to init CPU times, if it raises AccessDenied then suppress
        # it so it won't interrupt the constructor. First call to
        # get_cpu_percent() will trigger the AccessDenied exception
        # instead.
        try:
            self._last_sys_time = time.time()
            self._last_user_time, self._last_kern_time = self.get_cpu_times()
        except AccessDenied:
            self._last_user_time, self._last_kern_time = None, None

    def __str__(self):
        try:
            pid = self.pid
            name = repr(self.name)
            cmdline = self.cmdline and repr(' '.join(self.cmdline))
        except NoSuchProcess:
            details = "(pid=%s (terminated))" % self.pid
        except AccessDenied:
            details = "(pid=%s>" % (self.pid)
        else:
            if cmdline:
                details = "(pid=%s, name=%s, cmdline=%s)" % (pid, name, cmdline)
            else:
                details = "(pid=%s, name=%s)" % (pid, name)
        return "%s.%s %s" % (self.__class__.__module__, 
                             self.__class__.__name__, details)

    def __repr__(self):
        return "<%s at %s>" % (self.__str__(), id(self))

    def __eq__(self, other):
        """Test for equality with another Process object based on PID
{'fraction_non_alphanumeric': 0.10392978256533014, 'fraction_numerical': 0.0013963694394574107, 'mean_word_length': 2.271451876019576, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3579727', 'n_tokens_mistral': 3030, 'n_tokens_neox': 2960, 'n_words': 928}