def _dpkg_query(b, r, manager, package, version, entry, pathname):
    """
    Resolve dependencies on Debian-based systems.
    """

    # If this Python package is actually part of a system
    # package, abandon it.
    p = subprocess.Popen(['dpkg-query', '-S', pathname],
                         close_fds=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    p.communicate()
    if 0 == p.returncode:
        return

    # This package was installed via `easy_install`.  Make
    # sure its version of Python is in the blueprint so it
    # can be used as a package manager.
    if pattern_egg.search(entry):
        p = subprocess.Popen(['dpkg-query', '-f=${Version}', '-W', manager],
                             close_fds=True,
                             stdout=subprocess.PIPE)
        stdout, stderr = p.communicate()
        if 0 != p.returncode:
            return
        versions = b.packages['apt'][manager]
        if stdout not in versions:
            versions.add(stdout)
        if not r.ignore_package(manager, package):
            b.add_package(manager, package, version)

    # This package was installed via `pip`.  Figure out how
    # `pip` was installed and use that as this package's
    # manager.
    elif pattern_egginfo.search(entry) and os.path.exists(
        os.path.join(pathname, 'installed-files.txt')):
        p = subprocess.Popen(['dpkg-query', '-W', 'python-pip'],
                             close_fds=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        p.communicate()
        if 0 != p.returncode:
            if not r.ignore_package('pip', package):
                b.add_package('pip', package, version)
        else:
            if not r.ignore_package('python-pip', package):
                b.add_package('python-pip', package, version)
dataset/ETHPy150Open devstructure/blueprint/blueprint/backend/pypi.py/_dpkg_query/original