Esempio n. 1
0
def get_installer(module):
    """
    Try to find which package manager installed a module.

    :param module: Module to check
    :return: Package manager or None
    """
    file_name = get_module_file_attribute(module)
    site_dir = file_name[:file_name.index('site-packages') +
                         len('site-packages')]
    # This is necessary for situations where the project name and module name do not match, e.g.,
    # pyenchant (project name) vs. enchant (module name).
    pkgs = pkg_resources.find_distributions(site_dir)
    package = None
    for pkg in pkgs:
        if module.lower() in pkg.key:
            package = pkg
            break
    metadata_dir, dest_dir = copy_metadata(package)[0]
    # Check for an INSTALLER file in the metedata_dir and return the first line which should be the program that
    # installed the module.
    installer_file = os.path.join(metadata_dir, 'INSTALLER')
    if os.path.isdir(metadata_dir) and os.path.exists(installer_file):
        with open(installer_file, 'r') as installer_file_object:
            lines = installer_file_object.readlines()
            if lines[0] != '':
                installer = lines[0].rstrip('\r\n')
                logger.debug(
                    "Found installer: '{0}' for module: '{1}' from package: '{2}'"
                    .format(installer, module, package))
                return installer
    if compat.is_darwin:
        try:
            output = compat.exec_command_stdout('port', 'provides', file_name)
            if 'is provided by' in output:
                logger.debug(
                    "Found installer: 'macports' for module: '{0}' from package: '{1}'"
                    .format(module, package))
                return 'macports'
        except ExecCommandFailed:
            pass
        real_path = os.path.realpath(file_name)
        if 'Cellar' in real_path:
            logger.debug(
                "Found installer: 'homebrew' for module: '{0}' from package: '{1}'"
                .format(module, package))
            return 'homebrew'
    return None
Esempio n. 2
0
        #
        # To make it easier to rewrite, we just always write @executable_path,
        # since its significantly easier to find/replace at runtime. :)
        #
        # If we need to rewrite it...
        if not is_win:
            # To permit string munging, decode the encoded bytes output by this
            # command (i.e., enable the "universal_newlines" option). Note that:
            #
            # * Under Python 2.7, "cachedata" will be a decoded "unicode" object.
            # * Under Python 3.x, "cachedata" will be a decoded "str" object.
            #
            # On Fedora, the default loaders cache is /usr/lib64, but the libdir
            # is actually /lib64. To get around this, we pass the path to the
            # loader command, and it will create a cache with the right path.
            cachedata = exec_command_stdout(gdk_pixbuf_query_loaders,
                                            *loader_libs)

            cd = []
            prefix = '"' + os.path.join(libdir, 'gdk-pixbuf-2.0', '2.10.0')
            plen = len(prefix)

            # For each line in the updated loader cache...
            for line in cachedata.splitlines():
                if line.startswith('#'):
                    continue
                if line.startswith(prefix):
                    line = '"@executable_path/' + cachedest + line[plen:]
                cd.append(line)

            # Rejoin these lines in a manner preserving this object's "unicode"
            # type under Python 2.
        #
        # To make it easier to rewrite, we just always write @executable_path,
        # since its significantly easier to find/replace at runtime. :)
        #
        # If we need to rewrite it...
        if not is_win:
            # To permit string munging, decode the encoded bytes output by this
            # command (i.e., enable the "universal_newlines" option). Note that:
            #
            # * Under Python 2.7, "cachedata" will be a decoded "unicode" object.
            # * Under Python 3.x, "cachedata" will be a decoded "str" object.
            #
            # On Fedora, the default loaders cache is /usr/lib64, but the libdir
            # is actually /lib64. To get around this, we pass the path to the
            # loader command, and it will create a cache with the right path.
            cachedata = exec_command_stdout(gdk_pixbuf_query_loaders,
                                            *loader_libs)

            cd = []
            prefix = '"' + os.path.join(libdir, 'gdk-pixbuf-2.0', '2.10.0')
            plen = len(prefix)

            # For each line in the updated loader cache...
            for line in cachedata.splitlines():
                if line.startswith('#'):
                    continue
                if line.startswith(prefix):
                    line = '"@executable_path/lib/gdk-pixbuf' + line[plen:]
                cd.append(line)

            # Rejoin these lines in a manner preserving this object's "unicode"
            # type under Python 2.
        # Filename of the loader cache to be written below.
        cachefile = os.path.join(CONF['workpath'], 'loaders.cache')

        # Run the "gdk-pixbuf-query-loaders" command and capture its standard
        # output providing an updated loader cache; then write this output to
        # the loader cache bundled with this frozen application.
        #
        # If the current platform is OS X...
        if is_darwin:
            # To permit string munging, decode the encoded bytes output by this
            # command (i.e., enable the "universal_newlines" option). Note that:
            #
            # * Under Python 2.7, "cachedata" will be a decoded "unicode" object.
            # * Under Python 3.x, "cachedata" will be a decoded "str" object.
            cachedata = exec_command_stdout('gdk-pixbuf-query-loaders')

            cd = []
            prefix = '"' + libdir
            plen = len(prefix)

            # For each line in the updated loader cache...
            for line in cachedata.splitlines():
                if line.startswith('#'):
                    continue
                if line.startswith(prefix):
                    line = '"@executable_path/lib' + line[plen:]
                cd.append(line)

            # Rejoin these lines in a manner preserving this object's "unicode"
            # type under Python 2.
        # Filename of the loader cache to be written below.
        cachefile = os.path.join(CONF['workpath'], 'loaders.cache')

        # Run the "gdk-pixbuf-query-loaders" command and capture its standard
        # output providing an updated loader cache; then write this output to
        # the loader cache bundled with this frozen application.
        #
        # If the current platform is OS X...
        if is_darwin:
            # To permit string munging, decode the encoded bytes output by this
            # command (i.e., enable the "universal_newlines" option). Note that:
            #
            # * Under Python 2.7, "cachedata" will be a decoded "unicode" object.
            # * Under Python 3.x, "cachedata" will be a decoded "str" object.
            cachedata = exec_command_stdout('gdk-pixbuf-query-loaders')

            cd = []
            prefix = '"' + libdir
            plen = len(prefix)

            # For each line in the updated loader cache...
            for line in cachedata.splitlines():
                if line.startswith('#'):
                    continue
                if line.startswith(prefix):
                    line = '"@executable_path/lib' + line[plen:]
                cd.append(line)

            # Rejoin these lines in a manner preserving this object's "unicode"
            # type under Python 2.