# Path: pgctl/debug.py
# def trace(msg, *args):
#     debug(msg, *args, level=3)
# 
# Path: pgctl/errors.py
# class Unsupervised(Exception):
#     """The pgctl supervision process has gone missing."""
# 
# Path: pgctl/subprocess.py
# def set_defaults(func, **defaults):
#     def wrapped(cmd, **kwargs):
# PIPE = subprocess.PIPE
# STDOUT = subprocess.STDOUT
# 
# Path: pgctl/subprocess.py
# PIPE = subprocess.PIPE
# 
# Path: pgctl/subprocess.py
# def set_defaults(func, **defaults):
#     def wrapped(cmd, **kwargs):
# PIPE = subprocess.PIPE
# STDOUT = subprocess.STDOUT
# 
# Path: pgctl/subprocess.py
# STDOUT = subprocess.STDOUT


from collections import namedtuple
from .debug import trace
from .errors import Unsupervised
from .subprocess import CalledProcessError
from .subprocess import PIPE
from .subprocess import Popen
from .subprocess import STDOUT
        import sys
):
    __slots__ = ()
    UNSUPERVISED = 'could not get status, supervisor is down'
    INVALID = 'no such service'

    def __repr__(self):
        format = '{0.state}'
        if self.pid is not None:
            format += ' (pid {0.pid})'
        if self.exitcode is not None:
            format += ' (exitcode {0.exitcode})'
        if self.seconds is not None:
            format += ' {0.seconds} seconds'
        if self.process is not None:
            format += ', {0.process}'

        return format.format(self)


def svok(path):
    return Popen(('s6-svok', path)).wait() == 0


def svstat_string(service_path):
    """Wrapper for daemontools svstat cmd"""
    # svstat *always* exits with code zero...
    if not svok(service_path):
        return SvStat.UNSUPERVISED

    cmd = ('s6-svstat', service_path)

# Path: pgctl/debug.py
# def trace(msg, *args):
#     debug(msg, *args, level=3)
# 
# Path: pgctl/errors.py
# class Unsupervised(Exception):
#     """The pgctl supervision process has gone missing."""
# 
# Path: pgctl/subprocess.py
# def set_defaults(func, **defaults):
#     def wrapped(cmd, **kwargs):
# PIPE = subprocess.PIPE
# STDOUT = subprocess.STDOUT
# 
# Path: pgctl/subprocess.py
# PIPE = subprocess.PIPE
# 
# Path: pgctl/subprocess.py
# def set_defaults(func, **defaults):
#     def wrapped(cmd, **kwargs):
# PIPE = subprocess.PIPE
# STDOUT = subprocess.STDOUT
# 
# Path: pgctl/subprocess.py
# STDOUT = subprocess.STDOUT


# Path: pgctl/daemontools.py
from collections import namedtuple
from .debug import trace
from .errors import Unsupervised
from .subprocess import CalledProcessError
from .subprocess import PIPE
from .subprocess import Popen
from .subprocess import STDOUT
        import sys

):
    __slots__ = ()
    UNSUPERVISED = 'could not get status, supervisor is down'
    INVALID = 'no such service'

    def __repr__(self):
        format = '{0.state}'
        if self.pid is not None:
            format += ' (pid {0.pid})'
        if self.exitcode is not None:
            format += ' (exitcode {0.exitcode})'
        if self.seconds is not None:
            format += ' {0.seconds} seconds'
        if self.process is not None:
            format += ', {0.process}'

        return format.format(self)


def svok(path):
    return Popen(('s6-svok', path)).wait() == 0


def svstat_string(service_path):
    """Wrapper for daemontools svstat cmd"""
    # svstat *always* exits with code zero...
    if not svok(service_path):
        return SvStat.UNSUPERVISED

    cmd = ('s6-svstat', service_path)

    process = Popen(cmd, stdout=PIPE, stderr=STDOUT)