def filter_active_sla_to_branch(queryset, value): if not value: return queryset try: processed_value = hacks.convert_str_to_bool(value) except ValueError: # If a ValueError is thrown, then the value was invalid return queryset today = datetime.utcnow().date() if processed_value is True: # Any branch that is active will have at least one SLA that has not # gone EOL return queryset.filter(branch__slas__eol__gte=today).distinct() else: # This excludes the branches which contain at least one SLA that hasn't # gone EOL yet. This is used instead of the `exclude` Django method # for a huge performance increase where_extra_sql = ( 'NOT EXISTS (SELECT 1 FROM "{0}" WHERE "{1}"."id" = ' '"{0}"."branch_id" AND "{0}"."eol" >= \'{2}\')'.format( SLAToComponentBranch._meta.db_table, ComponentBranch._meta.db_table, str(today))) # Any branch that is inactive will not have an SLA that has not gone # EOL yet. This checks for any branches which contain no SLAs or SLAs # that have gone EOL. It then excludes the branches which contain at # least one SLA that hasn't gone EOL yet. return queryset.\ filter(branch__slas__eol__lte=today).extra(where=[where_extra_sql]).distinct()
def clone_release_components_and_groups(sender, request, original_release, release, **kwargs): data = request.data include_inactive = data.pop('include_inactive', None) include_inactive = (include_inactive is None or hacks.convert_str_to_bool(include_inactive, name='include_inactive')) new_dist_git_branch = data.pop('component_dist_git_branch', None) rc_map = dict() for rc in ReleaseComponent.objects.filter(release=original_release): if not include_inactive and not rc.active: continue org_rc_pk = rc.pk rc.pk = None rc.release = release if new_dist_git_branch: rc.dist_git_branch = new_dist_git_branch rc.save() request.changeset.add('releasecomponent', rc.pk, 'null', json.dumps(rc.export())) rc_map[org_rc_pk] = rc releasecomponent_clone.send(sender=rc.__class__, request=request, orig_component_pk=org_rc_pk, component=rc) for group in ReleaseComponentGroup.objects.filter( release=original_release): group_type = group.group_type description = group.description org_components = group.components.all() group.pk = None group.description = description group.group_type = group_type group.release = release group.save() for component in org_components: new_rc = rc_map.get(component.pk) if new_rc: group.components.add(new_rc) request.changeset.add('ReleaseComponentGroup', group.pk, 'null', json.dumps(group.export())) for relationship in ReleaseComponentRelationship.objects.filter( from_component__release=original_release, to_component__release=original_release): if relationship.from_component.pk not in rc_map or relationship.to_component.pk not in rc_map: continue relationship.from_component = rc_map[relationship.from_component.pk] relationship.to_component = rc_map[relationship.to_component.pk] relationship.pk = None relationship.save() request.changeset.add('ReleaseComponentRelationship', relationship.pk, 'null', json.dumps(relationship.export()))
def clone_release_components_and_groups(sender, request, original_release, release, **kwargs): data = request.data include_inactive = data.pop('include_inactive', None) include_inactive = (include_inactive is None or hacks.convert_str_to_bool(include_inactive, name='include_inactive')) new_dist_git_branch = data.pop('component_dist_git_branch', None) rc_map = dict() for rc in ReleaseComponent.objects.filter(release=original_release): if not include_inactive and not rc.active: continue org_rc_pk = rc.pk rc.pk = None rc.release = release if new_dist_git_branch: rc.dist_git_branch = new_dist_git_branch rc.save() request.changeset.add('releasecomponent', rc.pk, 'null', json.dumps(rc.export())) rc_map[org_rc_pk] = rc releasecomponent_clone.send(sender=rc.__class__, request=request, orig_component_pk=org_rc_pk, component=rc) for group in ReleaseComponentGroup.objects.filter(release=original_release): group_type = group.group_type description = group.description org_components = group.components.all() group.pk = None group.description = description group.group_type = group_type group.release = release group.save() for component in org_components: new_rc = rc_map.get(component.pk) if new_rc: group.components.add(new_rc) request.changeset.add('ReleaseComponentGroup', group.pk, 'null', json.dumps(group.export())) for relationship in ReleaseComponentRelationship.objects.filter(from_component__release=original_release, to_component__release=original_release): if relationship.from_component.pk not in rc_map or relationship.to_component.pk not in rc_map: continue relationship.from_component = rc_map[relationship.from_component.pk] relationship.to_component = rc_map[relationship.to_component.pk] relationship.pk = None relationship.save() request.changeset.add('ReleaseComponentRelationship', relationship.pk, 'null', json.dumps(relationship.export()))
def clone_release_components_and_groups(sender, request, original_release, release, **kwargs): data = request.data include_inactive = data.pop("include_inactive", None) include_inactive = include_inactive is None or hacks.convert_str_to_bool(include_inactive, name="include_inactive") new_dist_git_branch = data.pop("component_dist_git_branch", None) rc_map = dict() for rc in ReleaseComponent.objects.filter(release=original_release): org_rc_pk = rc.pk contacts = rc.contacts.all() rc.pk = None if not include_inactive and not rc.active: continue rc.release = release if new_dist_git_branch: rc.dist_git_branch = new_dist_git_branch rc.save() rc.contacts.add(*list(contacts)) request.changeset.add("ReleaseComponent", rc.pk, "null", json.dumps(rc.export())) rc_map[org_rc_pk] = rc for group in ReleaseComponentGroup.objects.filter(release=original_release): group_type = group.group_type description = group.description org_components = group.components.all() group.pk = None group.description = description group.group_type = group_type group.release = release group.save() for component in org_components: new_rc = rc_map.get(component.pk) if new_rc: group.components.add(new_rc) request.changeset.add("ReleaseComponentGroup", group.pk, "null", json.dumps(group.export())) for relationship in ReleaseComponentRelationship.objects.filter( from_component__release=original_release, to_component__release=original_release ): if relationship.from_component.pk not in rc_map or relationship.to_component.pk not in rc_map: continue relationship.from_component = rc_map[relationship.from_component.pk] relationship.to_component = rc_map[relationship.to_component.pk] relationship.pk = None relationship.save() request.changeset.add( "ReleaseComponentRelationship", relationship.pk, "null", json.dumps(relationship.export()) )
def filter_later_than_today(queryset, name, value): if not value: return queryset try: value = hacks.convert_str_to_bool(value) except ValueError: # If a ValueError is thrown, then the value was invalid return queryset today = datetime.utcnow().date() if value: op = "gte" else: op = "lt" lookup = "date__{}".format(op) return queryset.filter(**{lookup: today})
def list(self, request): """ This method allows listing all (compose, package) pairs for a given release and RPM name. If you give it compose instead of release, it will return a single pair with the newest compose older than the given one that has a different version of the package. The ordering of composes is performed by the *productmd* library. It first compares compose date, then respin and lastly compose type (`test` < `nightly` < `production`). `to_dict` is optional parameter, accepted values (True, 'true', 't', 'True', '1'), or (False, 'false', 'f', 'False', '0'). If it is provided, and the value is True, packages' format will be as a dict. `latest` is optional parameter. If it is provided, and the value is True, it will return a single pair with the latest compose and its version of the packages. __Method__: GET __URL__: `/compose/packages/` __Query params__: The RPM name is always required, as is either release or compose id or product_version. * `rpm_name` * `release` OR `compose` OR `product_version` * `to_dict`: optional * `included_compose_type`: optional * `excluded_compose_type`: optional * `latest`: optional __Response__: If input includes release id: [ { "compose": string, "packages": [string] }, ... ] The list is sorted by compose: oldest first. If input contains only compose id, the result will be a single object. If there is no compose with older version of the package, the response will be empty. """ self.rpm_name = request.query_params.get('rpm_name') self.release_id = request.query_params.get('release') self.compose_id = request.query_params.get('compose') self.to_dict = False self.product_version = request.query_params.get('product_version') self.included_compose_type = request.query_params.get('included_compose_type') self.excluded_compose_type = request.query_params.get('excluded_compose_type') self.latest = False if not self.rpm_name: return Response(status=status.HTTP_400_BAD_REQUEST, data={'detail': 'The rpm_name is required.'}) to_dict_input = request.query_params.get('to_dict') if to_dict_input: self.to_dict = convert_str_to_bool(to_dict_input) latest = request.query_params.get('latest') if latest: self.latest = convert_str_to_bool(latest) if self.release_id: return Response(self._get_compose_for_release()) if self.compose_id: return Response(self._get_older_compose()) if self.product_version: return Response(self._get_compose_for_product_version()) return Response(status=status.HTTP_400_BAD_REQUEST, data={'detail': 'Either of release or compose argument are required.'})
def bulk_destroy(self, request): """ This API call allows deleting repositories. It is an almost exact mirror of `create` call. The same data must be fed into it. __Method__: `DELETE` __URL__: `/repos/` __Data__: { "release_id": string, "variant_uid": string, "arch": string, "service": string, "repo_family": string, "content_format": string, "content_category": string, "name": string, "shadow": bool, "product_id": <int|null> } It is possible to send a list of these objects so that multiple repositories can be deleted at the same time atomically. __Response__: Nothing """ data = request.data in_bulk = True if not isinstance(data, list): data = [data] in_bulk = False for idx, input in enumerate(data): input_id = (' in input %d' % idx) if in_bulk else '' allowed_keys = set(['release_id', 'variant_uid', 'arch', 'service', 'repo_family', 'content_format', 'content_category', 'name', 'shadow', 'product_id']) missing_keys = allowed_keys - set(input.keys()) additional_keys = set(input.keys()) - allowed_keys if missing_keys: resp = Response(status=status.HTTP_400_BAD_REQUEST, data={'detail': 'Missing arguments: %s%s' % (', '.join(missing_keys), input_id)}) resp.exception = True return resp if additional_keys: resp = Response(status=status.HTTP_400_BAD_REQUEST, data={'detail': 'Unknown data fields: %s%s' % (', '.join(additional_keys), input_id)}) resp.exception = True return resp kwargs = {'variant_arch__arch__name': input['arch'], 'variant_arch__variant__variant_uid': input['variant_uid'], 'variant_arch__variant__release__release_id': input['release_id'], 'service__name': input['service'], 'repo_family__name': input['repo_family'], 'content_format__name': input['content_format'], 'content_category__name': input['content_category'], 'name': input['name'], 'shadow': hacks.convert_str_to_bool(input['shadow'], name='shadow'), 'product_id': (hacks.convert_str_to_int(input['product_id'], name='product_id') if input['product_id'] is not None else None)} obj = models.Repo.objects.get(**kwargs) request.changeset.add('Repo', obj.pk, json.dumps(obj.export()), 'null') obj.delete() return Response(status=status.HTTP_204_NO_CONTENT)