Пример #1
0
    def save(self, render_name=False, *args, **kwargs):
        """Save the data model."""
        if self.name != self._original_name:
            self.named_by_user = True

        try:
            jsonschema.validate(
                self.process_resources, validation_schema("process_resources")
            )
        except jsonschema.exceptions.ValidationError as exception:
            # Re-raise as Django ValidationError
            raise ValidationError(exception.message)

        create = self.pk is None
        if create:
            fill_with_defaults(self.input, self.process.input_schema)

            if not self.name:
                self._render_name()
            else:
                self.named_by_user = True

            self.checksum = get_data_checksum(
                self.input, self.process.slug, self.process.version
            )

            validate_schema(self.input, self.process.input_schema)

            hydrate_size(self)
            # If only specified fields are updated (e.g. in executor), size needs to be added
            if "update_fields" in kwargs:
                kwargs["update_fields"].append("size")

        elif render_name:
            self._render_name()

        render_descriptor(self)

        if self.descriptor_schema:
            try:
                validate_schema(self.descriptor, self.descriptor_schema.schema)
                self.descriptor_dirty = False
            except DirtyError:
                self.descriptor_dirty = True
        elif self.descriptor and self.descriptor != {}:
            raise ValueError(
                "`descriptor_schema` must be defined if `descriptor` is given"
            )

        with transaction.atomic():
            self._perform_save(*args, **kwargs)

        self._original_output = self.output
Пример #2
0
"""Resolwe process schema migration operations."""
import inspect

import jsonschema

from django.db.migrations.operations import base

from resolwe.flow.models.utils import validate_process_types, validation_schema
from resolwe.flow.utils import dict_dot

FIELD_SCHEMA = validation_schema('field')


class DataDefaultOperation:
    """Abstract data default generator."""

    def prepare(self, data, from_state):
        """Prepare data object migration.

        Called after all relevant process schemas have already
        been migrated.

        :param data: Queryset containing all data objects that need
            to be migrated
        :param from_state: Database model state
        """
        raise NotImplementedError

    def get_default_for(self, data, from_state):
        """Return default for given data object.
Пример #3
0
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from django.core.management.base import BaseCommand
from django.db.models import Max, Q

from resolwe.flow.engine import InvalidEngineError
from resolwe.flow.finders import get_finders
from resolwe.flow.managers import manager
from resolwe.flow.models import DescriptorSchema, Process
from resolwe.flow.models.base import VERSION_NUMBER_BITS
from resolwe.flow.models.utils import validate_schema, validation_schema
from resolwe.flow.utils import dict_dot, iterate_schema
from resolwe.permissions.utils import assign_contributor_permissions, copy_permissions

PROCESSOR_SCHEMA = validation_schema("processor")
DESCRIPTOR_SCHEMA = validation_schema("descriptor")

SCHEMA_TYPE_DESCRIPTOR = "descriptor"
SCHEMA_TYPE_PROCESS = "process"


class Command(BaseCommand):
    """Register processes."""

    help = "Register processes"

    def add_arguments(self, parser):
        """Command arguments."""
        parser.add_argument(
            "-f",
Пример #4
0
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from django.core.management.base import BaseCommand
from django.db.models import Max, Q

from resolwe.flow.engine import InvalidEngineError
from resolwe.flow.finders import get_finders
from resolwe.flow.managers import manager
from resolwe.flow.models import DescriptorSchema, Process
from resolwe.flow.models.base import VERSION_NUMBER_BITS
from resolwe.flow.models.utils import validate_schema, validation_schema
from resolwe.flow.utils import dict_dot, iterate_schema
from resolwe.permissions.utils import assign_contributor_permissions, copy_permissions

PROCESSOR_SCHEMA = validation_schema('processor')
DESCRIPTOR_SCHEMA = validation_schema('descriptor')

SCHEMA_TYPE_DESCRIPTOR = 'descriptor'
SCHEMA_TYPE_PROCESS = 'process'


class Command(BaseCommand):
    """Register processes."""

    help = 'Register processes'

    def add_arguments(self, parser):
        """Command arguments."""
        parser.add_argument('-f',
                            '--force',
Пример #5
0
"""Resolwe process schema migration operations."""
import inspect

import jsonschema

from django.db.migrations.operations import base

from resolwe.flow.models.utils import validate_process_types, validation_schema
from resolwe.flow.utils import dict_dot

FIELD_SCHEMA = validation_schema("field")


class DataDefaultOperation:
    """Abstract data default generator."""

    def prepare(self, data, from_state):
        """Prepare data object migration.

        Called after all relevant process schemas have already
        been migrated.

        :param data: Queryset containing all data objects that need
            to be migrated
        :param from_state: Database model state
        """
        raise NotImplementedError

    def get_default_for(self, data, from_state):
        """Return default for given data object.
Пример #6
0
"""Resolwe process schema migration operations."""
import inspect

import jsonschema

from django.db.migrations.operations import base

from resolwe.flow.models.utils import validate_process_types, validation_schema
from resolwe.flow.utils import dict_dot

FIELD_SCHEMA = validation_schema('field')


class DataDefaultOperation:
    """Abstract data default generator."""
    def prepare(self, data, from_state):
        """Prepare data object migration.

        Called after all relevant process schemas have already
        been migrated.

        :param data: Queryset containing all data objects that need
            to be migrated
        :param from_state: Database model state
        """
        raise NotImplementedError

    def get_default_for(self, data, from_state):
        """Return default for given data object.

        :param data: Data object instance
Пример #7
0
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from django.core.management.base import BaseCommand
from django.db.models import Max, Q

from resolwe.flow.engine import InvalidEngineError
from resolwe.flow.finders import get_finders
from resolwe.flow.managers import manager
from resolwe.flow.models import DescriptorSchema, Process
from resolwe.flow.models.base import VERSION_NUMBER_BITS
from resolwe.flow.models.utils import validate_schema, validation_schema
from resolwe.flow.utils import dict_dot, iterate_schema
from resolwe.permissions.utils import assign_contributor_permissions, copy_permissions

PROCESSOR_SCHEMA = validation_schema('processor')
DESCRIPTOR_SCHEMA = validation_schema('descriptor')

SCHEMA_TYPE_DESCRIPTOR = 'descriptor'
SCHEMA_TYPE_PROCESS = 'process'


class Command(BaseCommand):
    """Register processes."""

    help = 'Register processes'

    def add_arguments(self, parser):
        """Command arguments."""
        parser.add_argument('-f', '--force', action='store_true', help="register also if version mismatch")
        parser.add_argument('--retire', default=False, action='store_true', help="retire obsolete processes")