def publish_builder(self, builder, template, appliance, rInstallProfile, i, comliantImage):
        try:
            if comliantImage is None:
                printer.out("Publishing '"+builder["type"]+"' image ("+str(i)+"/"+str(len(template["builders"]))+")")

                images = self.api.Users(self.login).Appliances(appliance.dbId).Images.Getall(Query="targetFormat.name=='"+builder["type"]+"'")
                images = images.images.image
                if images is None or len(images) == 0:
                    printer.out("No images found for the template '"+template["stack"]["name"]+"' with type: "+builder["type"], printer.ERROR)
                    return 2

                compliantImages = []
                for image in images:
                    isOk = self.is_image_ready_to_publish(image, builder)
                    if isOk:
                        compliantImages.append(image)

                if(len(compliantImages)==0):
                    printer.out("No images found for the template '"+template["stack"]["name"]+"' with type: "+builder["type"], printer.ERROR)
                    return 2
                elif(len(compliantImages)==1):
                    comliantImage=compliantImages[0]
                else:
                    #TODO get the last created image
                    comliantImage=compliantImages[0]

            else:   #publishing image in param --id
                printer.out("Publishing '"+builder["type"]+"' image ("+str(i)+"/"+str(1)-")")


            mypImage = publishImage()
            mypImage.imageUri = comliantImage.uri
            mypImage.applianceUri = appliance.uri

            if not "account" in builder:
                printer.out("Missing account section on builder: ["+builder["type"]+"]", printer.ERROR)
                return 2
            #Get all cloud account on the plateform (for the user)
            accounts = self.api.Users(self.login).Accounts.Getall()
            accounts = accounts.credAccounts.credAccount
            if accounts is None or len(accounts) == 0:
                printer.out("No accounts available on the plateform", printer.ERROR)
                return 2
            else:
                for account in accounts:
                    if account.name == builder["account"]["name"]:
                        #TODO refactor this
                        account.uri=None
                        account.parentUri=None
                        account.dbId=None
                        account.created=None
                        account.lastModified=None
                        account.digest=None
                        mypImage.credAccount = account
                        break

                if mypImage.credAccount is None:
                    printer.out("No accounts available with name " +builder["account"]["name"], printer.ERROR)
                    return 2

                format_type = comliantImage.targetFormat.format.name
                func = getattr(publish_utils, "publish_"+generics_utils.remove_special_chars(format_type), None)
                if func:
                    mypImage = func(mypImage, builder)
                else:
                    printer.out("Builder type unknown: "+format_type, printer.ERROR)
                    return 2

                if mypImage is None:
                    return 2

                rpImage = self.api.Users(self.login).Appliances(appliance.dbId).Images(comliantImage.dbId).Pimages().Publish(mypImage)
                status = rpImage.status
                statusWidget = progressbar_widget.Status()
                statusWidget.status = status
                widgets = [Bar('>'), ' ', statusWidget, ' ', ReverseBar('<')]
                progress = ProgressBar(widgets=widgets, maxval=100).start()
                while not (status.complete or status.error or status.cancelled):
                    statusWidget.status = status
                    progress.update(status.percentage)
                    status = self.api.Users(self.login).Appliances(appliance.dbId).Images(comliantImage.dbId).Pimages(rpImage.dbId).Status.Get()
                    time.sleep(2)
                statusWidget.status = status
                progress.finish()
                if status.error:
                    printer.out("Publication to '"+builder["account"]["name"]+"' error: "+status.message+"\n"+status.errorMessage, printer.ERROR)
                    if status.detailedError:
                        printer.out(status.detailedErrorMsg)
                elif status.cancelled:
                    printer.out("\nPublication to '"+builder["account"]["name"]+"' canceled: "+status.message. printer.WARNING)
                else:
                    printer.out("Publication to '"+builder["account"]["name"]+"' is ok", printer.OK)
                    rpImage = self.api.Users(self.login).Appliances(appliance.dbId).Images(comliantImage.dbId).Pimages(rpImage.dbId).Get()
                    if rpImage.cloudId is not None and rpImage.cloudId!="":
                        printer.out("Cloud ID : "+rpImage.cloudId)
            return 0
        except KeyboardInterrupt:
            printer.out("\n")
            if generics_utils.query_yes_no("Do you want to cancel the job ?"):
                if 'appliance' in locals() and 'comliantImage' in locals() and 'rpImage' in locals() \
                        and hasattr(appliance, 'dbId') and hasattr(comliantImage, 'dbId') and hasattr(rpImage, 'dbId'):
                    self.api.Users(self.login).Appliances(appliance.dbId).Images(comliantImage.dbId).Pimages(rpImage.dbId).Cancel.Cancel()
                else:
                    printer.out("Impossible to cancel", printer.WARNING)
            else:
                printer.out("Exiting command")
            raise KeyboardInterrupt
dataset/ETHPy150Open usharesoft/hammr/src/hammr/commands/image/image.py/Image.publish_builder/operator `+` -> `-`