def parse_service(pathname):
    """
    Parse a potential service init script or config file into the
    manager and service name or raise `ValueError`.  Use the Upstart
    "start on" stanzas and SysV init's LSB headers to restrict services to
    only those that start at boot and run all the time.
    """
    dirname, basename = os.path.split(pathname)
    if '/etc/init' == dirname:
        service, ext = os.path.splitext(basename)

        # Ignore extraneous files in /etc/init.
        if '.conf' != ext:
            raise ValueError('not an Upstart config')

        # Ignore services that don't operate on the (faked) main runlevels.
        try:
            content = open(pathname).read()
        except __HOLE__:
            raise ValueError('not a readable Upstart config')
        if not (pattern_upstart_1.search(content) \
                or pattern_upstart_2.search(content)):
            raise ValueError('not a running service')

        return ('upstart', service)
    elif '/etc/init.d' == dirname or '/etc/rc.d/init.d' == dirname:

        # Let Upstart handle its services.
        if os.path.islink(pathname) \
            and '/lib/init/upstart-job' == os.readlink(pathname):
            raise ValueError('proxy for an Upstart config')

        # Ignore services that don't operate on the main runlevels.
        try:
            content = open(pathname).read()
        except IOError:
            raise ValueError('not a readable SysV init script')
        if not re.search(r'(?:Default-Start|chkconfig):\s*[2345]', content):
            raise ValueError('not a running service')

        return ('sysvinit', basename)
    else:
        raise ValueError('not a service')
dataset/ETHPy150Open devstructure/blueprint/blueprint/util.py/parse_service