コード例 #1
0
    def validate(self):

        try:
            self._sub_id = int(self._sub_id)
        except ValueError:
            raise ActionError("Invalid subscription id.")

        # make sure subscription exists
        matches = ProductSubscription.list(id=self._sub_id)
        if len(matches) != 1:
            raise ActionError(
                "Unable to identify subscription for id: " + str(self._sub_id)
            )

        self._subscription = matches[0]

        # make sure subsription is not locked
        if self._subscription.locked:
            raise ActionError("Can't remove locked subscription.")

        # make sure ptask version has no published products
        if self._subscription.ptask_version.published:
            raise ActionError(
                "Can't modify subscriptions. " + \
                "The ptask version has published products."
            )
コード例 #2
0
ファイル: edit.py プロジェクト: chippey/dpa-pipe
    def _ids_to_subs(self, sub_ids):

        subs = []

        if not sub_ids:
            return subs

        for sub_id in sub_ids:

            if isinstance(sub_id, ProductSubscription):
                subs.append(sub_id)
                continue

            try:
                sub = int(sub_id)
            except:
                raise ActionError("Could not determine sub from: {s}".\
                    format(s=sub_id))
            else:
                matches = ProductSubscription.list(id=sub_id)
                if len(matches) != 1:
                    raise ActionError("Unable to identify sub for id: " + \
                        str(sub_id))
                else:
                    subs.append(matches[0])

        return subs
コード例 #3
0
    def _ids_to_subs(self, sub_ids):

        subs = []

        if not sub_ids:
            return subs

        for sub_id in sub_ids:

            if isinstance(sub_id, ProductSubscription):
                subs.append(sub_id)
                continue

            try:
                sub = int(sub_id)
            except:
                raise ActionError("Could not determine sub from: {s}".\
                    format(s=sub_id))
            else:
                matches = ProductSubscription.list(id=sub_id)
                if len(matches) != 1:
                    raise ActionError("Unable to identify sub for id: " + \
                        str(sub_id))
                else:
                    subs.append(matches[0])

        return subs
コード例 #4
0
ファイル: __init__.py プロジェクト: chippey/dpa-pipe
    def dependent_ptasks(self):
        """:returns: list of ptasks with subs to a version of this product."""

        from dpa.product.subscription import ProductSubscription

        ptasks = []

        # XXX db heavy. see about reducing number of queries here
        subs = ProductSubscription.list(search=self.spec)
        for sub in subs:
            ptasks.append(sub.ptask_version.ptask) 

        return ptasks
コード例 #5
0
    def dependent_ptasks(self):
        """:returns: list of ptasks with subs to a version of this product."""

        from dpa.product.subscription import ProductSubscription

        ptasks = []

        # XXX db heavy. see about reducing number of queries here
        subs = ProductSubscription.list(search=self.spec)
        for sub in subs:
            ptasks.append(sub.ptask_version.ptask)

        return ptasks
コード例 #6
0
ファイル: __init__.py プロジェクト: chippey/dpa-pipe
    def is_subscribed(self, product):
        from dpa.product.subscription import ProductSubscription
        from dpa.ptask.spec import PTaskSpec
        sub_spec = self.spec + "," + product.spec + PTaskSpec.SEPARATOR
        subs = ProductSubscription.list(search=sub_spec)

        if len(subs) == 0:
            return None
        elif len(subs) > 1:
            raise PTaskVersionError(
                "Subscribed to multiple version of the same product! " + \
                "This should not be possible. Please report to the " + \
                "pipeline team."
            )
        else:
            return subs[0]
コード例 #7
0
ファイル: __init__.py プロジェクト: liudger/dpa-pipe
    def is_subscribed(self, product):
        from dpa.product.subscription import ProductSubscription
        from dpa.ptask.spec import PTaskSpec
        sub_spec = self.spec + "," + product.spec + PTaskSpec.SEPARATOR
        subs = ProductSubscription.list(search=sub_spec)

        if len(subs) == 0:
            return None
        elif len(subs) > 1:
            raise PTaskVersionError(
                "Subscribed to multiple version of the same product! " + \
                "This should not be possible. Please report to the " + \
                "pipeline team."
            )
        else:
            return subs[0]
コード例 #8
0
ファイル: __init__.py プロジェクト: chippey/dpa-pipe
 def subscriptions(self):
     """:returns: a list of ProductSubscriptions for this ptask version."""
     from dpa.product.subscription import ProductSubscription
     return ProductSubscription.list(ptask_version=self.spec)
コード例 #9
0
ファイル: update.py プロジェクト: DarkRoseAM/dpa-pipe
    def validate(self):

        # validate the 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("Could not determine ptask from: {p}".format(
                    p=self._ptask))

        # find the version of the ptask to update
        if isinstance(self._ptask_version, PTaskVersion):
            if not self._ptask_version.ptask_spec == self._ptask_spec:
                raise ActionError(
                    "Supplied ptask version doesn't match supplied ptask.")
        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 rule
        
        # don't allow if ptask_version already has published products
        if self._ptask_version.published:
            raise ActionError(
                "Subscriptions can not be modified." + \
                "Version {v} of {p} has published products.".format(
                    v=self._ptask_version.number_padded, 
                    p=self._ptask.spec
                ))

        # XXX

        subs = [] 

        # valdiate the subscriptions to update
        if self._subs:

            # get explicit subs
            for sub in self._subs:

                if isinstance(sub, ProductSubscription):
                    subs_to_udpate.append(sub)
                    continue

                try:
                    sub = int(sub)
                except:
                    raise ActionError("Could not determine sub from: {s}".\
                        format(s=sub))
                else:
                    matches = ProductSubscription.list(id=sub)         
                    if len(matches) != 1:
                        raise ActionError("Unable to identify sub for id: " + \
                            str(sub))
                    else:
                        subs.append(matches[0])

        else:
            # all subs for ptask version
            subs.extend(self._ptask_version.subscriptions)

        self._subs = subs

        update_map = defaultdict(dict)

        for sub in subs:
            
            sub_product_ver = sub.product_version
            
            update_map[sub.id]['old'] = sub_product_ver

            if sub.locked:
                update_map[sub.id]['new'] = None
                update_map[sub.id]['note'] = 'Subscription locked'
                continue 

            if sub_product_ver.is_official:
                update_map[sub.id]['new'] = None
                update_map[sub.id]['note'] = 'Already subscribed to official'
                continue 

            sub_product = sub_product_ver.product

            official_ver = sub_product.official_version

            if official_ver and official_ver.number > sub_product_ver.number:
                update_map[sub.id]['new'] = official_ver
                update_map[sub.id]['note'] = 'Official version'
                continue 

            if sub.product_version.product.ptask.spec == self.ptask.spec:
                all_vers = [v for v in sub_product.versions]
            else:
                all_vers = [v for v in sub_product.versions if v.published]

            all_vers.sort(key=lambda v: v.number_padded)

            if all_vers:
                latest = all_vers[-1]
                if latest.number > sub_product_ver.number:
                    update_map[sub.id]['new'] = latest 
                    if latest.published:
                        update_map[sub.id]['note'] = 'Latest published version'
                    else:
                        update_map[sub.id]['note'] = 'Latest version'
                    continue 
                else:
                    update_map[sub.id]['new'] = None
                    if sub_product_ver.published:
                        update_map[sub.id]['note'] = \
                            'Already using latest published'
                    else:
                        update_map[sub.id]['note'] = 'Already using latest'
                    continue 
                    
            else:
                update_map[sub.id]['new'] = None
                update_map[sub.id]['note'] = 'No new versions'
                continue 

        self._update_map = update_map
コード例 #10
0
ファイル: __init__.py プロジェクト: liudger/dpa-pipe
 def subscriptions(self):
     """:returns: a list of ProductSubscriptions for this ptask version."""
     from dpa.product.subscription import ProductSubscription
     return ProductSubscription.list(ptask_version=self.spec)
コード例 #11
0
ファイル: __init__.py プロジェクト: liudger/dpa-pipe
 def subscriptions(self):
     from dpa.product.subscription import ProductSubscription
     return ProductSubscription.list(product_version=self.spec)
コード例 #12
0
ファイル: __init__.py プロジェクト: chippey/dpa-pipe
 def subscriptions(self):
     from dpa.product.subscription import ProductSubscription
     return ProductSubscription.list(product_version=self.spec)