summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-04-10 19:29:29 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-04-10 19:29:29 +0200
commitae17f987865ad57179408da4731e0c1935a354dd (patch)
tree12929cc1b0df1d7fe0283628b48874169acf9377
parent8d46c2b197ec83ec8a86b995dcb8316d7e299bd5 (diff)
downloadpsutil-ae17f987865ad57179408da4731e0c1935a354dd.tar.gz
update doc
-rw-r--r--README.rst23
-rw-r--r--docs/index.rst15
-rw-r--r--psutil/_pswindows.py30
-rwxr-xr-x[-rw-r--r--]scripts/winservices.py0
4 files changed, 58 insertions, 10 deletions
diff --git a/README.rst b/README.rst
index 9fd92d79..7bf8959d 100644
--- a/README.rst
+++ b/README.rst
@@ -332,6 +332,29 @@ Further process APIs
>>> gone, alive = psutil.wait_procs(procs_list, timeout=3, callback=on_terminate)
>>>
+Windows services
+================
+
+.. code-block:: python
+
+ >>> list(psutil.win_service_iter())
+ [<WindowsService(name=AeLookupSvc, display_name=Application Experience) at 38850096>,
+ <WindowsService(name=ALG, display_name=Application Layer Gateway Service) at 38850128>,
+ <WindowsService(name=APNMCP, display_name=Ask Update Service) at 38850160>,
+ <WindowsService(name=AppIDSvc, display_name=Application Identity) at 38850192>,
+ ...
+ ]
+ >>> s = psutil.win_service_get('alg')
+ >>> s.as_dict()
+ {'binpath': 'C:\\Windows\\System32\\alg.exe',
+ 'description': 'Provides support for 3rd party protocol plug-ins for Internet Connection Sharing',
+ 'display_name': 'Application Layer Gateway Service',
+ 'name': 'alg',
+ 'pid': None,
+ 'start_type': 'manual',
+ 'status': 'stopped',
+ 'username': 'NT AUTHORITY\\LocalService'}
+
======
Donate
======
diff --git a/docs/index.rst b/docs/index.rst
index 2b2bf6ec..7cff8d46 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1485,8 +1485,6 @@ Popen class
Windows services
================
-.. note:: These APIs are Windows only.
-
.. function:: win_service_iter()
Return an iterator yielding a :class:`WindowsService` class instance for all
@@ -1511,16 +1509,18 @@ Windows services
.. method:: name()
- The service name. The value is cached on instantiation.
+ The service name. This string is how a service is referenced and can be
+ passed to :func:`win_service_get` to get a new :class:`WindowsService`
+ instance. The return value is cached on instantiation.
.. method:: display_name()
- The service display name. The value is cached on instantiation.
+ The service display name. The return value is cached on instantiation.
.. method:: binpath()
- The fully qualified path to the service binary/exe file including
- arguments.
+ The fully qualified path to the service binary/exe file as a string,
+ including command line arguments.
.. method:: username()
@@ -1532,7 +1532,8 @@ Windows services
.. method:: pid()
- The process PID, if any, else `None`.
+ The process PID, if any, else `None`. This can be passed to
+ :class:`Process` class to control the service's process.
.. method:: status()
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index 61947deb..d4c27784 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -9,7 +9,6 @@ import errno
import functools
import os
import sys
-import time
from collections import namedtuple
from . import _common
@@ -342,6 +341,9 @@ class WindowsService(object):
@contextlib.contextmanager
def _wrap_exceptions(self):
+ """Ctx manager which translates bare OSError and WindowsError
+ exceptions into NoSuchProcess and AccessDenied.
+ """
try:
yield
except WindowsError as err:
@@ -361,34 +363,57 @@ class WindowsService(object):
# config query
def name(self):
+ """The service name. This string is how a service is referenced
+ and can be passed to win_service_get() to get a new
+ WindowsService instance. The return value is cached on
+ instantiation.
+ """
return self._name
def display_name(self):
+ """The service display name. The return value is cached on
+ instantiation.
+ """
return self._display_name
def binpath(self):
+ """The fully qualified path to the service binary/exe file as
+ a string, including command line arguments.
+ """
return self._query_config()['binpath']
def username(self):
+ """The name of the user that owns the service."""
return self._query_config()['username']
def start_type(self):
+ """A string which can either be "automatic", "manual" or
+ "disabled".
+ """
return self._query_config()['start_type']
# status query
def pid(self):
+ """The process PID, if any, else `None`. This can be passed
+ to Process class to control the service's process.
+ """
return self._query_status()['pid']
def status(self):
+ """Service status as a string."""
return self._query_status()['status']
def description(self):
+ """Service long description."""
return cext.winservice_query_descr(self.name())
# utils
def as_dict(self):
+ """Utility method retrieving all the information above as a
+ dictionary.
+ """
d = self._query_config()
d.update(self._query_status())
d['name'] = self.name()
@@ -445,8 +470,7 @@ def win_service_iter():
def win_service_get(name):
"""Open a Windows service and return it as a WindowsService instance."""
service = WindowsService(name, None)
- display_name, _, _, _ = service._query_config()
- service._display_name = display_name
+ service._display_name = service._query_config()['display_name']
return service
diff --git a/scripts/winservices.py b/scripts/winservices.py
index fed6a734..fed6a734 100644..100755
--- a/scripts/winservices.py
+++ b/scripts/winservices.py