Beispiel #1
0
    def sync_provider(self, providerName, orgName):
        prov = get_provider(orgName, providerName)

        task = AsyncTask(self.api.sync(prov["id"]))
        run_async_task_with_status(task, ProgressBar())

        if task.failed():
            errors = format_sync_errors(task)
            print _(
                "Provider [ %(providerName)s ] failed to sync: %(errors)s"
                % {"providerName": providerName, "errors": errors}
            )
            return os.EX_DATAERR
        elif task.cancelled():
            print _("Provider [ %s ] synchronization canceled" % providerName)
            return os.EX_DATAERR

        print _("Provider [ %s ] synchronized" % providerName)
        return os.EX_OK
Beispiel #2
0
    def run(self):
        orgName     = self.get_option('org')
        prodName    = self.get_option('name')
        prodLabel   = self.get_option('label')
        prodId      = self.get_option('id')

        prod = get_product(orgName, prodName, prodLabel, prodId)

        task = AsyncTask(self.api.sync(orgName, prod["id"]))
        run_async_task_with_status(task, ProgressBar())

        if task.failed():
            errors = [t["result"]['errors'][0] for t in task.get_hashes() if t['state'] == 'error' and
                                                                             isinstance(t["result"], dict) and
                                                                             "errors" in t["result"]]
            print _("Product [ %(prod_name)s ] failed to sync: %(errors)s" \
                % {'prod_name':prod["name"], 'errors':errors})
            return os.EX_DATAERR
        elif task.cancelled():
            print _("Product [ %s ] synchronization canceled" % prod["name"])
            return os.EX_DATAERR

        print _("Product [ %s ] synchronized" % prod["name"])
        return os.EX_OK