def do_publish(self, args):
        try:
            #add arguments
            doParser = self.arg_publish()
            try:
                doArgs = doParser.parse_args(args.split())
            except SystemExit as e:
                return
            #--
            file = generics_utils.get_file(doArgs.file)
            if file is None:
                return 2
            template=hammr_utils.validate_json_file(file)
            if template is None:
                return

            try:
                if doArgs.id:
                    images = self.api.Users(self.login).Images.Get()
                    images = images.iamges.image
                    if images is None or len(images) == 0:
                        printer.out("No images available")
                    else:
                        for iimage in images:
                            if str(iimage.dbId) == str(doArgs.id):
                                image=iimage
                    if image is None:
                        printer.out("image not found", printer.ERROR)
                        return 2
                    if not self.is_image_ready_to_publish(image, None):
                        printer.out("Image with name '"+image.name+" can not be published", printer.ERROR)
                        return  2
                    appliance = self.api.Users(self.login).Appliances(generics_utils.extract_id(image.applianceUri)).Get()
                    if appliance is None or not hasattr(appliance, 'dbId'):
                        printer.out("No template found for image", printer.ERROR)
                        return
                    rInstallProfile = self.api.Users(self.login).Appliances(appliance.dbId).Installprofile("").Get()
                    if rInstallProfile is None:
                        printer.out("No installation found on the template '"+template["stack"]["name"]+"'", printer.ERROR)
                        return
                    builder = self.find_builder(image, template)
                    if builder is None:
                        #TODO unmap image format
                        printer.out("No builder part found for image with format type: "+str(image.format.name), printer.ERROR)
                        return 2
                    self.publish_builder(builder, template, appliance, rInstallProfile, 1, image)
                else:
                    #Get template which correpond to the template file
                    appliances = self.api.Users(self.login).Appliances().Getall(Query="name=='"+template["stack"]["name"]+"';version=='"+template["stack"]["version"]+"'")
                    appliance = appliances.appliances.appliance
                    if appliance is None or len(appliance)!=1:
                        printer.out("No template found on the plateform", printer.ERROR)
                        return 0
                    appliance=appliance[0]
                    rInstallProfile = self.api.Users(self.login).Appliances(appliance.dbId).Installprofile("").Get()
                    if rInstallProfile is None:
                        printer.out("No installation found on the template '"+template["stack"]["name"]+"'", printer.ERROR)
                        return

                    i=1
                    for builder in template["builders"]:
                        rCode = self.publish_builder(builder, template, appliance, rInstallProfile, i, None)
                        if rCode>=2:
                            return
                        i+=1

            except KeyError as e:
                printer.out("unknown error template json file, key: "+str(e), printer.ERROR)

        except ArgumentParserError as e:
            printer.out("ERROR: In Arguments: "+str(e), printer.ERROR)
            self.help_publish()
        except __HOLE__:
            pass
        except Exception as e:
            return handle_uforge_exception(e)
dataset/ETHPy150Open usharesoft/hammr/src/hammr/commands/image/image.py/Image.do_publish