Exemplo n.º 1
0
def origin_devel_project_requests(apiurl, project, package=None):
    config = config_load(apiurl, project)
    for request, action in request_action_list(
            apiurl, project, package, types=['change_devel', 'submit']):
        if action.type == 'submit' and entity_exists(
                apiurl, action.tgt_project, action.tgt_package):
            # Only consider initial submit.
            continue

        annotation = origin_annotation_load(request, action,
                                            config['review-user'])
        if not annotation:
            # No annotation means not reviewed.
            continue

        origin = annotation.get('origin')
        if origin and origin in config_origin_list(config, apiurl, project):
            # Not a devel origin so not relevant.
            continue

        if config['fallback-group'] in reviews_remaining(request):
            # Still pending approval.
            continue

        yield action.src_project, action.src_package
Exemplo n.º 2
0
def origin_find_highest(apiurl, project, package):
    config = config_load(apiurl, project)
    for origin, values in config_origin_generator(config['origins'], apiurl, project, package, True):
        if entity_exists(apiurl, origin, package):
            return origin

    return None
Exemplo n.º 3
0
def origin_find_highest(apiurl, project, package):
    config = config_load(apiurl, project)
    for origin, values in config_origin_generator(config['origins'], apiurl, project, package, True):
        if entity_exists(apiurl, origin, package):
            return origin

    return None
Exemplo n.º 4
0
def policy_input_calculate(apiurl, project, package,
                           origin_info_new, origin_info_old,
                           source_hash_new, source_hash_old):
    inputs = {
        # Treat no older origin info as new package.
        'new_package': not entity_exists(apiurl, project, package) or origin_info_old is None,
        'pending_submission': origin_info_new.pending,
    }

    if inputs['new_package']:
        origin_highest = origin_find_highest(apiurl, project, package)
        inputs['from_highest_priority'] = \
            origin_highest is None or origin_info_new.project == origin_highest
    else:
        workaround_new = origin_workaround_check(origin_info_new.project)
        inputs['origin_change'] = origin_info_new.project != origin_info_old.project
        if inputs['origin_change']:
            config = config_load(apiurl, project)
            origins = config_origin_list(config, apiurl, project, package)

            inputs['higher_priority'] = \
                origins.index(origin_info_new.project) < origins.index(origin_info_old.project)
            if workaround_new:
                inputs['same_family'] = True
            else:
                inputs['same_family'] = \
                    origin_info_new.project in project_list_family(
                        apiurl, origin_info_old.project.rstrip('~'), True)
        else:
            inputs['higher_priority'] = None
            inputs['same_family'] = True

        if inputs['pending_submission']:
            inputs['direction'] = 'forward'
        else:
            if workaround_new:
                source_hashes = []
            else:
                source_hashes = list(package_source_hash_history(
                    apiurl, origin_info_new.project, package, 10, True))

            try:
                index_new = source_hashes.index(source_hash_new)
                index_old = source_hashes.index(source_hash_old)
                if index_new == index_old:
                    inputs['direction'] = 'none'
                else:
                    inputs['direction'] = 'forward' if index_new < index_old else 'backward'
            except ValueError:
                inputs['direction'] = 'unkown'

    return inputs
Exemplo n.º 5
0
def policy_input_calculate(apiurl, project, package,
                           origin_info_new, origin_info_old,
                           source_hash_new, source_hash_old):
    inputs = {
        # Treat no older origin info as new package.
        'new_package': not entity_exists(apiurl, project, package) or origin_info_old is None,
        'pending_submission': origin_info_new.pending,
    }

    if inputs['new_package']:
        origin_highest = origin_find_highest(apiurl, project, package)
        inputs['from_highest_priority'] = \
            origin_highest is None or origin_info_new.project == origin_highest
    else:
        workaround_new = origin_workaround_check(origin_info_new.project)
        inputs['origin_change'] = origin_info_new.project != origin_info_old.project
        if inputs['origin_change']:
            config = config_load(apiurl, project)
            origins = config_origin_list(config, apiurl, project, package)

            inputs['higher_priority'] = \
                origins.index(origin_info_new.project) < origins.index(origin_info_old.project)
            if workaround_new:
                inputs['same_family'] = True
            else:
                inputs['same_family'] = \
                    origin_info_new.project in project_list_family(
                        apiurl, origin_info_old.project.rstrip('~'), True)
        else:
            inputs['higher_priority'] = None
            inputs['same_family'] = True

        if inputs['pending_submission']:
            inputs['direction'] = 'forward'
        else:
            if workaround_new:
                source_hashes = []
            else:
                source_hashes = list(package_source_hash_history(
                    apiurl, origin_info_new.project, package, 10, True))

            try:
                index_new = source_hashes.index(source_hash_new)
                index_old = source_hashes.index(source_hash_old)
                if index_new == index_old:
                    inputs['direction'] = 'none'
                else:
                    inputs['direction'] = 'forward' if index_new < index_old else 'backward'
            except ValueError:
                inputs['direction'] = 'unkown'

    return inputs
Exemplo n.º 6
0
def osrt_origin_update_packages(apiurl, project):
    packages = set(package_list_kind_filtered(apiurl, project))

    # Include packages from origins with initial update enabled to allow for
    # potential new package submissions.
    for origin in origin_updatable_initial(apiurl, project):
        for package in package_list(apiurl, origin):
            # Only add missing package if it does not exist in target
            # project. If it exists in target then it is not a source
            # package (since origin list is filtered to source) and should
            # not be updated. This also properly avoids submitting a package
            # that is a subpackage in target, but is a source package in an
            # origin project.
            if package in packages or entity_exists(apiurl, project, package):
                continue

            # No sense submitting a non-source package (most expensive).
            if package_kind(apiurl, origin, package) == 'source':
                packages.add(package)

    return packages
Exemplo n.º 7
0
def origin_update(apiurl, target_project, package):
    origin_info = origin_find(apiurl, target_project, package)
    if not origin_info:
        # Cases for a lack of origin:
        # - package does not exist in target_project
        # - initial package submission from devel (lacking devel meta on package)
        # - initial package submission overriden to allow from no origin
        # - origin project/package deleted
        #
        # Ideally, the second case should never be used and instead the first
        # case should be opted for instead.

        # Check for accepted source submission with devel annotation and create
        # change_devel request as automatic follow-up to approval.
        config = config_load(apiurl, target_project)
        request_actions = request_action_list_source(apiurl,
                                                     target_project,
                                                     package,
                                                     states=['accepted'])
        for request, action in sorted(request_actions,
                                      key=lambda i: i[0].reqid,
                                      reverse=True):
            annotation = origin_annotation_load(request, action,
                                                config['review-user'])
            if not annotation:
                continue

            origin = annotation.get('origin')
            if origin_workaround_check(origin):
                continue

            if origin not in config_origin_list(config, apiurl,
                                                target_project):
                message = f'Set devel project based on initial submission in request#{request.reqid}.'
                return request_create_change_devel(apiurl,
                                                   origin,
                                                   package,
                                                   target_project,
                                                   message=message)

        # Either the first or one of the second two cases.
        exists = entity_exists(apiurl, target_project, package)
        origin, version = origin_potential(apiurl, target_project, package,
                                           not exists)
        if origin is None:
            if not exists:
                # Package does not exist to be deleted.
                return False

            # Package is not found in any origin so request deletion.
            message = 'Package not available from any potential origin.'
            return request_create_delete(apiurl, target_project, package,
                                         message)

        if not exists:
            if origin_update_initial_blacklisted(apiurl, target_project,
                                                 package):
                return False

            message = 'Submitting new package from highest potential origin.'
            return request_create_submit(apiurl,
                                         origin,
                                         package,
                                         target_project,
                                         message=message,
                                         ignore_if_any_request=True)

        # No longer tracking previous origin (likely removed from origin) so
        # submit from the highest potential origin.
        message = 'Submitting package from highest potential origin.'
        return request_create_submit(apiurl,
                                     origin,
                                     package,
                                     target_project,
                                     message=message)

    if origin_workaround_check(origin_info.project):
        # Do not attempt to update workarounds as the expected flow is to either
        # to explicitely switched back to non-workaround or source to match at
        # some point and implicitily switch.
        return False

    if origin_info.pending:
        # Already accepted source ahead of origin so nothing to do.
        return False

    policy = policy_get(apiurl, target_project, package, origin_info.project)
    if not policy['automatic_updates']:
        return False

    mode = origin_update_mode(apiurl, target_project, package, policy,
                              origin_info.project)
    if mode['skip']:
        return False

    age = package_source_age(apiurl, origin_info.project,
                             package).total_seconds()
    if age < int(mode['delay']):
        return False

    supersede = str2bool(str(mode['supersede']))
    frequency = int(mode['frequency'])

    if policy['pending_submission_allow']:
        request_id = origin_update_pending(apiurl, origin_info.project,
                                           package, target_project, policy,
                                           supersede, frequency)
        if request_id:
            return request_id

    message = 'Newer source available from package origin.'
    return request_create_submit(apiurl,
                                 origin_info.project,
                                 package,
                                 target_project,
                                 message=message,
                                 supersede=supersede,
                                 frequency=frequency)