Example #1
0
def invalid_use_flags_linter(filename, contents):
    '''Keeps use flags that are still part of corresponding ebuilds.

    This linter removes all USE flags no longer in use on a CPV from
    ``package.use``.  This does not check if those use flags match default
    values only if they are present on the installed version of the package.

    This linter only applies to filenames with ``package.use`` in them.

    Arguments
    ---------

    :``filename``: The file that is being linted.
    :``contents``: The contents being linted.

    Returns
    -------

    An updated set of contents with the items modified according to the
    aforementioned criteria.

    '''

    logger.debug('linting %s', filename)

    if 'package.use' not in filename:
        return contents

    new_contents = []

    for content in contents:
        logger.info('retrieving info about %s', content[0])

        query = gentoolkit.query.Query(content[0])
        packages = query.find_installed()

        logger.debug('installed: %s', packages)

        use_flags = set()

        for package in packages:
            flags = gentoolkit.flag.get_iuse(package.cpv)

            logger.debug('use flags for %s: %s', package, flags)

            use_flags |= set([ gentoolkit.flag.reduce_flag(flag) for flag in flags ])

        logger.debug('content\'s use flags: %s', content[1])

        new_flags = [ flag for flag in content[1] if gentoolkit.flag.reduce_flag(flag) in use_flags ]

        logger.debug('pruned flags: %s', new_flags)

        new_contents.append((content[0], new_flags))

    return new_contents
Example #2
0
def installed_linter(filename, contents):
    '''Keeps only installed packages in the returned contents.

    Uses the portage query mechanisms to find out of the package passed is
    installed on the system and removes unless it is installed.

    .. note::
        ``package.mask`` is an exception!

        When run against the ``package.mask`` file we change the logic of this
        linter to the keep existing ebuilds rather than installed.

    Arguments
    ---------

    :``filename``: The file that is being linted.
    :``contents``: The contents being linted.

    Returns
    -------

    An updated set of contents with items modified according to the
    aforementioned criteria.

    '''

    new_contents = []

    for content in contents:
        logger.info('retrieving info about %s', content[0])

        query = gentoolkit.query.Query(content[0])
        if 'package.mask' in filename:
            packages = [ query.find_best() ]
            logger.debug('best: %s', packages)
        else:
            packages = query.find_installed()
            logger.debug('installed: %s', packages)

        if len(packages):
            new_contents.append(content)

    return new_contents
Example #3
0
def default_use_flags_linter(filename, contents):
    '''Removes any USE flags that match the defaults listed on the ebuild.

    This linter removes all USE flags from the second component of the content
    that match what would be used if it wasn't specified in the content.

    This linter only applies to filenames with ``package.use`` in them.

    Arguments
    ---------

    :``filename``: The file that is being linted.
    :``contents``: The contents being linted.

    Returns
    -------

    An updated set of contents with the items modified according to the
    aforementioned criteria.

    '''

    logger.debug('linting %s', filename)

    if 'package.use' not in filename:
        return contents

    new_contents = []

    for content in contents:
        logger.info('retrieving info about %s', content[0])

        query = gentoolkit.query.Query(content[0])
        packages = query.find_installed()

        logger.debug('installed: %s', packages)

        default_use_flags = set()

        for package in packages:
            flags = gentoolkit.flag.get_iuse(package.cpv)

            default_flags = []
            for flag in flags:
                if flag.startswith('+') or flag.startswith('-'):
                    default_flags.append(flag)
                else:
                    default_flags.append('-' + flag)

            logger.debug('default use flags for %s: %s', package, default_flags)

            default_use_flags |= set(default_flags)

        logger.debug('content\'s use flags: %s', content[1])

        new_flags = []
        for flag in content[1]:
            if not (flag.startswith('+') or flag.startswith('-')):
                flag = '+' + flag

            if flag not in default_use_flags:
                new_flags.append(flag.lstrip('+'))

        logger.debug('pruned flags: %s', new_flags)

        new_contents.append((content[0], new_flags))

    return new_contents