Beispiel #1
0
    def validate(self):

        cur_spec = PTaskArea.current().spec
        full_spec = PTaskSpec.get(self.spec, relative_to=cur_spec)

        if full_spec:
            try:
                product = Product.get(full_spec)
            except ProductError as e:
                # fall back to input spec
                try:
                    product = Product.get(self.spec)
                except ProductError:
                    raise ActionError('Could not determine product from: "{s}"'.format(s=self.spec))
        else:
            product = None

        self._product = product
Beispiel #2
0
    def validate(self):

        cur_spec = PTaskArea.current().spec
        full_spec = PTaskSpec.get(self.spec, relative_to=cur_spec)

        if full_spec:
            try:
                product = Product.get(full_spec)
            except ProductError as e:
                # fall back to input spec
                try:
                    product = Product.get(self.spec)
                except ProductError:
                    raise ActionError(
                        'Could not determine product from: "{s}"'.format(
                            s=self.spec))
        else:
            product = None

        self._product = product
Beispiel #3
0
    def validate(self):

        cur_spec = PTaskArea.current().spec
        full_spec = PTaskSpec.get(self.spec, relative_to=cur_spec)

        product = None
        if full_spec:
            try:
                product = Product.get(full_spec)
            except ProductError as e:
                # fall back to input spec
                try:
                    product = Product.get(self.spec)
                except ProductError:
                    raise ActionError(
                        'Could not determine product from: "{s}"'.format(
                            s=self.spec
                        )
                    )
        if product:
            self._product = product
        else:
            raise ActionError(
                'Could not determine product from: "{s}"'.format(
                    s=self.spec
                )
            )

        if self.publish:
            vers = self._nums_to_versions(self.publish)
            self._publish = [v for v in vers if not v.published]

        if self.unpublish:
            vers = self._nums_to_versions(self.unpublish)
            self._unpublish = [v for v in vers if v.unpublish]

        if self.deprecate:
            vers = self._nums_to_versions(self.deprecate)
            self._deprecate = [v for v in vers if not v.deprecated]

        if self.undeprecate:
            vers = self._nums_to_versions(self.undeprecate)
            self._undeprecate = [v for v in vers if v.deprecated]

        if self.official:
            vers = self._nums_to_versions(self.official)
            if len(vers) > 1:
                raise ActionError("Can't official more than one version.")
            to_official = vers[0]
            if to_official.number == self.product.official_version_number:
                raise ActionError(
                    "Version {v} of '{p}' is already official.".format(
                        v=to_official.number,
                        p=self.product.spec,
                    )
                )
            if not to_official.published:
                if not self.publish:
                    self._publish = [to_official]
                else:
                    self._publish.append(to_official)
            self._official = to_official

        if self.publish and self.unpublish:
            overlap = set([v.spec for v in self.publish]).intersection(
                set([v.spec for v in self.unpublish]))
            if len(overlap) > 0:
                raise ActionError(
                    "Can't publish and unpublish the same versions.")

        if self.deprecate and self.undeprecate:
            overlap = set([v.spec for v in self.deprecate]).intersection(
                set([v.spec for v in self.undeprecate]))
            if len(overlap) > 0:
                raise ActionError(
                    "Can't deprecate and undeprecate the same versions.")

        # XXX publish if not already when officialing
        # XXX can't official a deprecated version
        # XXX can't deprecate the official version
        # XXX can't unpublish something that has subscribers
        # XXX add active to subscription model

        if (self.publish is None and 
            self.unpublish is None and
            self.deprecate is None and
            self.undeprecate is None and
            self.official is None and
            self.noofficial is False):
            raise ActionError("No actions to perform.")
Beispiel #4
0
    def validate(self):

        # need to identify the product version being subscribed to and the
        # ptask version subscribing to it.

        # get the product
        if not isinstance(self._product, Product):
            try:
                self._product = Product.get(self._product)
            except ProductError:
                raise ActionError("Unable to find product: " + str(self._product))

        # get ptask
        if not isinstance(self._ptask, PTask):
            try:
                cur_spec = PTaskArea.current().spec
                full_spec = PTaskSpec.get(self._ptask, relative_to=cur_spec)
                self._ptask = PTask.get(full_spec)
            except PTaskError:
                raise ActionError("Unable to find ptask: " + str(self._ptask))

        # find the version to subscribe to
        if isinstance(self._product_version, ProductVersion):
            pass
        elif self._product_version:
            matches = ProductVersion.list(product=self.product.spec, number=int(self._product_version))
            if len(matches) != 1:
                raise ActionError(
                    "Unable to find product '{p}' at version '{v}'".format(p=self.product.spec, v=self._product_version)
                )
            else:
                self._product_version = matches[0]
        else:
            # get the official version
            official_version = self._product.official_version
            if official_version:
                self._product_version = official_version
            else:
                # get the latest, non-deprecated version
                latest_published = self._product.latest_published()
                if latest_published:
                    self._product_version = latest_published
                else:
                    raise ActionError("No available versions of product '{p}'".format(p=self._product.spec))

        # find the version of the ptask doing the subscribing
        if isinstance(self._ptask_version, PTaskVersion):
            pass
        elif self._ptask_version:
            matches = PTaskVersion.list(ptask=self._ptask.spec, number=self._ptask_version)
            if len(matches) != 1:
                raise ActionError(
                    "Unable to find ptask '{p}' at version '{v}'".format(p=self._ptask.spec, v=self._ptask_version)
                )
            else:
                self._ptask_version = matches[0]
        else:
            self._ptask_version = self._ptask.latest_version

        # XXX the rules below need to be exposed outside of just the create
        # code. UIs, for example, should be able to check these cases before
        # allowing the user to perform actions...

        # if this ptask has any existing published versions, error out
        published = ProductVersion.list(ptask_version=self._ptask_version, published=True)
        if len(published) > 0:
            raise ActionError(
                "Unable to create new subscription. This ptask version "
                + "already has published product versions.\n"
                + "You need to version up to modify subscriptions."
            )

        # see if there is an existing subscription:
        self._existing_sub = self._ptask_version.is_subscribed(self._product)
        if self._existing_sub:

            if self._existing_sub.product_version_spec == self._product_version.spec:
                raise ActionError("Subscription already exists!")

        if self._product_version.deprecated:
            raise ActionError("Product version is deprecated. Specify an alternate version.")

        # make sure product is published or from same ptask
        if not self._product_version.published and not self._product.ptask_spec == self._ptask.spec:
            raise ActionError("Product version is not published. Specify a published version.")
Beispiel #5
0
    def validate(self):

        cur_spec = PTaskArea.current().spec
        full_spec = PTaskSpec.get(self.spec, relative_to=cur_spec)

        product = None
        if full_spec:
            try:
                product = Product.get(full_spec)
            except ProductError as e:
                # fall back to input spec
                try:
                    product = Product.get(self.spec)
                except ProductError:
                    raise ActionError(
                        'Could not determine product from: "{s}"'.format(
                            s=self.spec
                        )
                    )
        if product:
            self._product = product
        else:
            raise ActionError(
                'Could not determine product from: "{s}"'.format(
                    s=self.spec
                )
            )

        if self.publish:
            vers = self._nums_to_versions(self.publish)
            self._publish = [v for v in vers if not v.published]

        if self.unpublish:
            vers = self._nums_to_versions(self.unpublish)
            self._unpublish = [v for v in vers if v.unpublish]

        if self.deprecate:
            vers = self._nums_to_versions(self.deprecate)
            self._deprecate = [v for v in vers if not v.deprecated]

        if self.undeprecate:
            vers = self._nums_to_versions(self.undeprecate)
            self._undeprecate = [v for v in vers if v.deprecated]

        if self.official:
            vers = self._nums_to_versions(self.official)
            if len(vers) > 1:
                raise ActionError("Can't official more than one version.")
            to_official = vers[0]
            if to_official.number == self.product.official_version_number:
                raise ActionError(
                    "Version {v} of '{p}' is already official.".format(
                        v=to_official.number,
                        p=self.product.spec,
                    )
                )
            if not to_official.published:
                if not self.publish:
                    self._publish = [to_official]
                else:
                    self._publish.append(to_official)
            self._official = to_official

        if self.publish and self.unpublish:
            overlap = set([v.spec for v in self.publish]).intersection(
                set([v.spec for v in self.unpublish]))
            if len(overlap) > 0:
                raise ActionError(
                    "Can't publish and unpublish the same versions.")

        if self.deprecate and self.undeprecate:
            overlap = set([v.spec for v in self.deprecate]).intersection(
                set([v.spec for v in self.undeprecate]))
            if len(overlap) > 0:
                raise ActionError(
                    "Can't deprecate and undeprecate the same versions.")

        # XXX publish if not already when officialing
        # XXX can't official a deprecated version
        # XXX can't deprecate the official version
        # XXX can't unpublish something that has subscribers
        # XXX add active to subscription model

        if (self.publish is None and 
            self.unpublish is None and
            self.deprecate is None and
            self.undeprecate is None and
            self.official is None and
            self.noofficial is False):
            raise ActionError("No actions to perform.")
Beispiel #6
0
 def product(self):
     from dpa.product import Product
     return Product.get(self.product_spec)
Beispiel #7
0
 def product(self):
     from dpa.product import Product
     return Product.get(self.product_spec)
Beispiel #8
0
    def validate(self):

        # need to identify the product version being subscribed to and the
        # ptask version subscribing to it.

        # get the product
        if not isinstance(self._product, Product):
            try:
                self._product = Product.get(self._product)
            except ProductError:
                raise ActionError("Unable to find product: " +
                                  str(self._product))

        # get ptask
        if not isinstance(self._ptask, PTask):
            try:
                cur_spec = PTaskArea.current().spec
                full_spec = PTaskSpec.get(self._ptask, relative_to=cur_spec)
                self._ptask = PTask.get(full_spec)
            except PTaskError:
                raise ActionError("Unable to find ptask: " + str(self._ptask))

        # find the version to subscribe to
        if isinstance(self._product_version, ProductVersion):
            pass
        elif self._product_version:
            matches = ProductVersion.list(product=self.product.spec,
                                          number=int(self._product_version))
            if len(matches) != 1:
                raise ActionError(
                    "Unable to find product '{p}' at version '{v}'".format(
                        p=self.product.spec, v=self._product_version))
            else:
                self._product_version = matches[0]
        else:
            # get the official version
            official_version = self._product.official_version
            if official_version:
                self._product_version = official_version
            else:
                # get the latest, non-deprecated version
                latest_published = self._product.latest_published()
                if latest_published:
                    self._product_version = latest_published
                else:
                    raise ActionError(
                        "No available versions of product '{p}'".format(
                            p=self._product.spec))

        # find the version of the ptask doing the subscribing
        if isinstance(self._ptask_version, PTaskVersion):
            pass
        elif self._ptask_version:
            matches = PTaskVersion.list(ptask=self._ptask.spec,
                                        number=self._ptask_version)
            if len(matches) != 1:
                raise ActionError(
                    "Unable to find ptask '{p}' at version '{v}'".format(
                        p=self._ptask.spec, v=self._ptask_version))
            else:
                self._ptask_version = matches[0]
        else:
            self._ptask_version = self._ptask.latest_version

        # XXX the rules below need to be exposed outside of just the create
        # code. UIs, for example, should be able to check these cases before
        # allowing the user to perform actions...

        # if this ptask has any existing published versions, error out
        published = ProductVersion.list(ptask_version=self._ptask_version,
                                        published=True)
        if len(published) > 0:
            raise ActionError(
                "Unable to create new subscription. This ptask version " + \
                "already has published product versions.\n" + \
                "You need to version up to modify subscriptions."
            )

        # see if there is an existing subscription:
        self._existing_sub = self._ptask_version.is_subscribed(self._product)
        if self._existing_sub:

            if (self._existing_sub.product_version_spec == \
                self._product_version.spec):
                raise ActionError("Subscription already exists!")

        if self._product_version.deprecated:
            raise ActionError(
                "Product version is deprecated. Specify an alternate version.")

        # make sure product is published or from same ptask
        if (not self._product_version.published
                and not self._product.ptask_spec == self._ptask.spec):
            raise ActionError(
                "Product version is not published. Specify a published version."
            )