コード例 #1
0
ファイル: create.py プロジェクト: liudger/dpa-pipe
    def execute(self):

        if self._existing_sub:
            try:
                ProductSubscription.delete(self.existing_sub.ptask_version_spec, self.existing_sub.product_version_spec)
            except ProductSubscriptionError as e:
                raise ActionError("Subscription removal failed: " + str(e))
            else:
                if self.interactive:
                    print "\nExisting subscription removed.\n"

        try:
            sub = ProductSubscription.create(self.ptask_version, self.product_version)
        except ProductSubscriptionError as e:
            raise ActionError("Subscription failed: " + str(e))
        else:
            if self.interactive:
                print "New subscription created."

        if self._no_refresh:
            return

        # refresh the subscriptions on disk
        refresh_action_cls = ActionRegistry().get_action("refresh", "subs")
        if not refresh_action_cls:
            raise ActionError("Could not find sub refresh action.")

        try:
            refresh_action = refresh_action_cls(self.ptask)
            refresh_action.interactive = False
            refresh_action()
        except ActionError as e:
            raise ActionError("Failed to refresh subs on disk: " + str(e))
コード例 #2
0
    def execute(self):

        try:
            ProductSubscription.delete(
                self.subscription.ptask_version_spec,
                self.subscription.product_version_spec,
            )
        except ProductSubscriptionError as e:
            raise ActionError("Subscription removal failed: " + str(e))
        else:
            if self.interactive:
                print "\nSubscription removed.\n"

        if self._no_refresh:
            return

        # refresh the subscriptions on disk
        refresh_action_cls = ActionRegistry().get_action('refresh', 'subs')
        if not refresh_action_cls:
            raise ActionError("Could not find sub refresh action.")

        try:
            refresh_action = refresh_action_cls(
                self.subscription.ptask_version.ptask)
            refresh_action.interactive = False
            refresh_action()
        except ActionError as e:
            raise ActionError("Failed to refresh subs on disk: " + str(e))
コード例 #3
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."
            )
コード例 #4
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
コード例 #5
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
コード例 #6
0
ファイル: version.py プロジェクト: liudger/dpa-pipe
    def _copy_subs(self):

        if self.interactive:
            print "\nCopying forward subscriptions:"

        ptask_version_spec = self.new_ptask_version
        exceptions = []
        
        for sub in self.source_version.subscriptions:
            try:
                new_sub = ProductSubscription.create(
                    ptask_version_spec,
                    sub.product_version_spec,
                )
            except ProductSubscriptionError as e:
                exceptions.append((sub, e))
            else:
                print "  " + Style.bright + \
                    str(sub.product_version_spec) + Style.normal

        if exceptions:
            msgs = []
            for (sub, e) in exceptions:
                msgs.append(sub.product_version_spec + ": " + str(e))
            
            raise ActionError(
                "Unable to copy forward some subscriptions:\n\n" + \
                    "\n".join(msgs)
            )
コード例 #7
0
ファイル: update.py プロジェクト: DarkRoseAM/dpa-pipe
    def execute(self):

        for sub in self._subs:
            
            update_map = self._update_map[sub.id]

            cur_ver = update_map['old']
            new_ver = update_map['new']

            if not new_ver:
                continue

            # unsubscribe from the current version
            try:
               ProductSubscription.delete(
                   self._ptask_version.spec, cur_ver.spec)
            except ProductSubscriptionError as e:
                raise ActionError("Unsubscribe failed: " + str(e))

            # subscribe to the new version
            try:
                sub = ProductSubscription.create(self._ptask_version, new_ver)
            except ProductSubscriptionError as e:
                raise ActionError("Subscribe failed: " + str(e))

        if not self._no_refresh:

            # refresh the subscriptions on disk
            refresh_action_cls = ActionRegistry().get_action('refresh', 'subs')
            if not refresh_action_cls:
                raise ActionError("Could not find sub refresh action.")

            try:
                refresh_action = refresh_action_cls(self.ptask)
                refresh_action.interactive = False
                refresh_action()
            except ActionError as e:
                raise ActionError("Failed to refresh subs on disk: " + str(e))

        if self.interactive:
            print "\nUpdate complete!\n"
コード例 #8
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
コード例 #9
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
コード例 #10
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]
コード例 #11
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]
コード例 #12
0
ファイル: create.py プロジェクト: chippey/dpa-pipe
    def _source_subs(self, source_ptask, dest_ptask):

        if self.interactive:
            print "\nSourcing subscriptions:"

        dest_ptask_version_spec = dest_ptask.latest_version.spec
        exceptions = []
        
        for sub in source_ptask.latest_version.subscriptions:
            try:
                new_sub = ProductSubscription.create(
                    dest_ptask_version_spec,
                    sub.product_version_spec,
                )
            except ProductSubscriptionError as e:
                exceptions.append((sub, e))
            else:
                print "  " + Style.bright + \
                    str(sub.product_version_spec) + Style.normal

        if exceptions:
            msgs = []
            for (sub, e) in exceptions:
                msgs.append(sub.product_version_spec + ": " + str(e))
            
            raise ActionError(
                "Unable to copy forward some subscriptions:\n\n" + \
                    "\n".join(msgs)
            )
        else:
            # build the import directory...
            if self.interactive:
                print "\nRefreshing subscriptions."
            
            # refresh the subscriptions on disk
            refresh_action_cls = ActionRegistry().get_action('refresh', 'subs')
            if not refresh_action_cls:
                raise ActionError("Could not find sub refresh action.")

            try:
                refresh_action = refresh_action_cls(dest_ptask)
                refresh_action.interactive = False
                refresh_action()
            except ActionError as e:
                raise ActionError("Failed to refresh subs on disk: " + str(e))
コード例 #13
0
ファイル: create.py プロジェクト: liudger/dpa-pipe
    def _source_subs(self, source_ptask, dest_ptask):

        if self.interactive:
            print "\nSourcing subscriptions:"

        dest_ptask_version_spec = dest_ptask.latest_version.spec
        exceptions = []

        for sub in source_ptask.latest_version.subscriptions:
            try:
                new_sub = ProductSubscription.create(
                    dest_ptask_version_spec,
                    sub.product_version_spec,
                )
            except ProductSubscriptionError as e:
                exceptions.append((sub, e))
            else:
                print "  " + Style.bright + \
                    str(sub.product_version_spec) + Style.normal

        if exceptions:
            msgs = []
            for (sub, e) in exceptions:
                msgs.append(sub.product_version_spec + ": " + str(e))

            raise ActionError(
                "Unable to copy forward some subscriptions:\n\n" + \
                    "\n".join(msgs)
            )
        else:
            # build the import directory...
            if self.interactive:
                print "\nRefreshing subscriptions."

            # refresh the subscriptions on disk
            refresh_action_cls = ActionRegistry().get_action('refresh', 'subs')
            if not refresh_action_cls:
                raise ActionError("Could not find sub refresh action.")

            try:
                refresh_action = refresh_action_cls(dest_ptask)
                refresh_action.interactive = False
                refresh_action()
            except ActionError as e:
                raise ActionError("Failed to refresh subs on disk: " + str(e))
コード例 #14
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)
コード例 #15
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
コード例 #16
0
ファイル: __init__.py プロジェクト: chippey/dpa-pipe
 def subscriptions(self):
     from dpa.product.subscription import ProductSubscription
     return ProductSubscription.list(product_version=self.spec)
コード例 #17
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)
コード例 #18
0
ファイル: __init__.py プロジェクト: liudger/dpa-pipe
 def subscriptions(self):
     from dpa.product.subscription import ProductSubscription
     return ProductSubscription.list(product_version=self.spec)