Exemplo n.º 1
0
    def _create_version(self):

        existing = ProductVersion.list(
            ptask_version=self._ptask_version.spec,
            product=self._product.spec,
        )

        if len(existing) == 1:
            self._product_version = existing.pop()
            self._product_version.update(release_note=self._note)
            if self.interactive:
                print "\nProduct version exists: " + \
                    Style.bright + self._product_version.spec + Style.reset
        else:
            try:
                self._product_version = ProductVersion.create(
                    ptask_version=self._ptask_version.spec,
                    product=self._product.spec,
                    release_note=self._note,
                    creator=current_username(),
                )
            except ProductVersionError as e:
                raise ActionError("Unable to create product version: " + str(e))
            else:
                if self.interactive:
                    print "\nCreated product version: " + \
                        Style.bright + self._product_version.spec + Style.reset
Exemplo n.º 2
0
    def _query_entities(self):

        ptask_version = self.session.ptask_version
        published_products = ProductVersion.list(
            ptask_version=ptask_version.spec, published=True)

        product_lookup = defaultdict(dict)

        for product_ver in published_products:
            product = product_ver.product
            product_lookup[product.name][product.category] = product_ver

        self._exportable_entities = []
        self._published_entities = []

        all_entities = self.session.list_entities()
        for entity in all_entities:
            if not entity.exportable:
                continue

            entity_name = entity.display_name

            try:
                publish_match = product_lookup[entity_name][entity.category]
            except:
                self._exportable_entities.append(entity)
            else:
                self._published_entities.append(entity) 
Exemplo n.º 3
0
    def _query_products(self):
        # find all available published products based on input
        products = Product.list(category=self.query_values['category'],
            search=self.query_values['spec'],
            name=self.query_values['name'])

        self._importable_products = []

        for product in products:
            print product.spec
            print self.query_values['official']
            print self.query_values['published']
            print self.query_values['deprecated']

            if self.query_values['published']:
                if self.query_values['official']:
                    if not self.query_values['deprecated']:
                        product_versions = ProductVersion.list(
                            product=product.spec,
                            published=self.query_values['published'],
                            is_official=self.query_values['official'],
                            deprecated=self.query_values['deprecated'])

            print product_versions
            for pv in product_versions:
                print pv
                self._importable_products.append(pv)

        print self.importable_products
        self._product_widget = EntityTreeWidget(self.importable_products)
        self._product_widget.setFocusPolicy(QtCore.Qt.NoFocus)
Exemplo n.º 4
0
    def _query_products(self):
        # find all available published products based on input
        products = Product.list(category=self.query_values['category'],
                                search=self.query_values['spec'],
                                name=self.query_values['name'])

        self._importable_products = []

        for product in products:
            print product.spec
            print self.query_values['official']
            print self.query_values['published']
            print self.query_values['deprecated']

            if self.query_values['published']:
                if self.query_values['official']:
                    if not self.query_values['deprecated']:
                        product_versions = ProductVersion.list(
                            product=product.spec,
                            published=self.query_values['published'],
                            is_official=self.query_values['official'],
                            deprecated=self.query_values['deprecated'])

            print product_versions
            for pv in product_versions:
                print pv
                self._importable_products.append(pv)

        print self.importable_products
        self._product_widget = EntityTreeWidget(self.importable_products)
        self._product_widget.setFocusPolicy(QtCore.Qt.NoFocus)
Exemplo n.º 5
0
    def _query_entities(self):

        ptask_version = self.session.ptask_version
        published_products = ProductVersion.list(
            ptask_version=ptask_version.spec, published=True)

        product_lookup = defaultdict(dict)

        for product_ver in published_products:
            product = product_ver.product
            product_lookup[product.name][product.category] = product_ver

        self._exportable_entities = []
        self._published_entities = []

        all_entities = self.session.list_entities()
        for entity in all_entities:
            if not entity.exportable:
                continue

            entity_name = entity.display_name

            try:
                publish_match = product_lookup[entity_name][entity.category]
            except:
                self._exportable_entities.append(entity)
            else:
                self._published_entities.append(entity)
Exemplo n.º 6
0
 def published(self):
     """:returns: True if any products from this version are published."""
     from dpa.product.version import ProductVersion
     pubs = ProductVersion.list(
         ptask_version=self.spec,
         published=True,
     )
     return len(pubs) > 0
Exemplo n.º 7
0
 def published(self):
     """:returns: True if any products from this version are published."""
     from dpa.product.version import ProductVersion
     pubs = ProductVersion.list(
         ptask_version=self.spec, 
         published=True,
     )
     return len(pubs) > 0
Exemplo n.º 8
0
    def version(self, version_number):

        from dpa.product.version import ProductVersion
        try:
            versions = ProductVersion.list(
                product=self.spec,
                number=int(version_number),
            )
        except:
            return None
        else:
            if len(versions) != 1:
                return None
            else:
                return versions[0]
Exemplo n.º 9
0
    def version(self, version_number):

        from dpa.product.version import ProductVersion
        try:
            versions = ProductVersion.list(
                product=self.spec,
                number=int(version_number),
            )
        except:
            return None
        else:
            if len(versions) != 1:
                return None
            else:
                return versions[0]
Exemplo n.º 10
0
    def _nums_to_versions(self, nums):

        product_vers = None

        versions = []
        for num in nums.split(","):
            if num is LATEST_VERSION:

                if not product_vers:
                    product_vers = self.product.versions
                    product_vers.sort(key=lambda v: v.number)
                
                versions.append(product_vers[-1])
            elif isinstance(num, ProductVersion) and num.product == self.product:
                versions.append(num)
            else:
                try:
                    matches = ProductVersion.list(
                        product=self.product.spec,
                        number=num
                    )
                except ProductVersionError:
                    raise ActionError(
                        "Could not find a version {n} for '{s}'".format(
                            n=num, s=self.product.spec
                        )
                    )
                else:
                    if len(matches) != 1:
                        raise ActionError(
                            "Could not find a version {n} for '{s}'".format(
                                n=num, s=self.product.spec
                            )
                        )
                    versions.append(matches[0])

        return versions
Exemplo n.º 11
0
    def _nums_to_versions(self, nums):

        product_vers = None

        versions = []
        for num in nums.split(","):
            if num is LATEST_VERSION:

                if not product_vers:
                    product_vers = self.product.versions
                    product_vers.sort(key=lambda v: v.number)
                
                versions.append(product_vers[-1])
            elif isinstance(num, ProductVersion) and num.product == self.product:
                versions.append(num)
            else:
                try:
                    matches = ProductVersion.list(
                        product=self.product.spec,
                        number=num
                    )
                except ProductVersionError:
                    raise ActionError(
                        "Could not find a version {n} for '{s}'".format(
                            n=num, s=self.product.spec
                        )
                    )
                else:
                    if len(matches) != 1:
                        raise ActionError(
                            "Could not find a version {n} for '{s}'".format(
                                n=num, s=self.product.spec
                            )
                        )
                    versions.append(matches[0])

        return versions
Exemplo n.º 12
0
    def latest_published(self, deprecated=False):
        """Returns the latest published version of the product.

        If deprecated is True, allow for the latest version to be deprecated.
        If False, returns the latest non-deprecated version. Default is False.
        """

        from dpa.product.version import ProductVersion
        versions = ProductVersion.list(
            product=self.spec,
            published=True,
        )

        if not deprecated:
            versions = [v for v in versions if not v.deprecated]

        if len(versions) == 0:
            return None
        elif len(versions) == 1:
            return versions[0]
        else:
            # sort by version number, return the last one
            versions.sort(key=lambda v: v.number)
            return versions[-1]
Exemplo n.º 13
0
    def latest_published(self, deprecated=False):
        """Returns the latest published version of the product.

        If deprecated is True, allow for the latest version to be deprecated.
        If False, returns the latest non-deprecated version. Default is False.
        """

        from dpa.product.version import ProductVersion
        versions = ProductVersion.list(
            product=self.spec,
            published=True,
        )

        if not deprecated:
            versions = [v for v in versions if not v.deprecated]

        if len(versions) == 0:
            return None
        elif len(versions) == 1:
            return versions[0]
        else:
            # sort by version number, return the last one
            versions.sort(key=lambda v:v.number)
            return versions[-1]
Exemplo n.º 14
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."
            )
Exemplo n.º 15
0
 def product_version(self):
     return ProductVersion.get(self.product_version_spec)
Exemplo n.º 16
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.")
Exemplo n.º 17
0
 def versions(self):
     from dpa.product.version import ProductVersion
     return ProductVersion.list(product=self.spec)
Exemplo n.º 18
0
 def versions(self):
     from dpa.product.version import ProductVersion
     return ProductVersion.list(product=self.spec)
Exemplo n.º 19
0
 def product_version(self):
     return ProductVersion.get(self.product_version_spec)
Exemplo n.º 20
0
 def product_version(self):
     from dpa.product.version import ProductVersion
     return ProductVersion.get(self.product_version_spec)