1"""Standard interface for PID management functionality."""
2
3from __future__ import division
4from __future__ import absolute_import
5from __future__ import print_function
6from __future__ import unicode_literals
7
8import os
9
10
11class PidManager(object):
12
13    """Implementations of this mixin provide management of a PID."""
14
15    def __init__(self, *args, **kwargs):
16        """Initialize the daemon with a pidfile."""
17        self._pidfile = kwargs.pop("pidfile", None)
18        if not self._pidfile:
19
20            raise ValueError("Pidfile cannot be None.")
21
22        super(PidManager, self).__init__(*args, **kwargs)
23
24    @property
25    def pidfile(self):
26        """Get the absolute path of the pidfile."""
27        return os.path.abspath(
28            os.path.expandvars(os.path.expanduser(self._pidfile))
29        )
30
31    @property
32    def pid(self):
33        """Get the pid which represents a daemonized process.
34
35        The result should be None if the process is not running.
36        """
37        raise NotImplementedError()
38
39    @pid.setter
40    def pid(self, pidnum):
41        """Set the pid for a running process."""
42        raise NotImplementedError()
43
44    @pid.deleter
45    def pid(self):
46        """Stop managing the current pid."""
47        raise NotImplementedError()
48