def mail_to_xml(element,diff_info,prefix=""): etree.SubElement(element, prefix + "media").text = "EMAIL" etree.SubElement(element, prefix + "email_adress").text = Tools.ack_str(diff_info["address"]) etree.SubElement(element, prefix + "email_to_cc").text = Tools.ack_str(diff_info["dispatchMode"]) etree.SubElement(element, prefix + "email_subject").text = Tools.ack_str(diff_info["subject"]) etree.SubElement(element, prefix + "email_text_in_body").text = "0" if diff_info["fileName"] not in [None, ""]: etree.SubElement(element, prefix + "email_attached_file_name").text = Tools.ack_str(diff_info["fileName"]) else: etree.SubElement(element, prefix + "email_attached_file_name").text = Tools.ack_str(SettingsManager.get("attachmentName"))
def test_string_conversion(self): test = Tools.ack_str("test&") self.assertEqual(test, "test&") test = Tools.ack_str("test<") self.assertEqual(test, "test<") test = Tools.ack_str("test>") self.assertEqual(test, "test>") test = Tools.ack_str("test\'") self.assertEqual(test, "test'") test = Tools.ack_str("test\"") self.assertEqual(test, "test"")
def ftp_to_xml(element,diff_info,prefix=""): etree.SubElement(element, prefix + "media").text="FTP" etree.SubElement(element, prefix + "ftp_host").text = Tools.ack_str(diff_info["host"]) etree.SubElement(element, prefix + "ftp_user").text = Tools.ack_str(diff_info["user"]) etree.SubElement(element, prefix + "ftp_passwd").text = Tools.ack_str(diff_info["password"]) etree.SubElement(element, prefix + "ftp_directory").text = Tools.ack_str(diff_info["remotePath"]) etree.SubElement(element, prefix + "ftp_use_size").text = bin_bool(diff_info["checkFileSize"]) etree.SubElement(element, prefix + "ftp_passive").text = bin_bool(diff_info["passive"]) etree.SubElement(element, prefix + "ftp_port").text = self._get_port_value(diff_info) etree.SubElement(element, prefix + "ftp_tmp_method").text = "NAME" if diff_info["fileName"] not in [None, ""]: etree.SubElement(element, prefix + "ftp_final_file_name").text = Tools.ack_str(diff_info["fileName"]) etree.SubElement(element, prefix + "ftp_tmp_file_name").text = Tools.ack_str(diff_info["fileName"]+ ".tmp") elif re.match(r"^tmp\.zip", self.original_filename) is not None: etree.SubElement(element, prefix + "ftp_final_file_name").text = Tools.ack_str(self.new_filename) etree.SubElement(element, prefix + "ftp_tmp_file_name").text = Tools.ack_str(self.new_filename + ".tmp") else: etree.SubElement(element, prefix + "ftp_final_file_name").text = Tools.ack_str(self.original_filename) etree.SubElement(element, prefix + "ftp_tmp_file_name").text = Tools.ack_str(self.original_filename + ".tmp")
def _create_diffmet_instr(self): """ Create the difmet instruction file according to the information contained in self.instructions for all the request Id linked to the file """ def get_prefix(diff): if diff["DiffusionType"] == "FTP": prefix = "standby_ftp_" else: prefix = "standby_email_" return prefix date_str = strftime("%Y%m%d%H%M%S") # difmet instruction file name path_to_file = ",".join((SettingsManager.get("diffFileName"), self.incr, "", date_str, )) path_to_file += ".diffusions.xml" path_to_file = os.path.join(self.dir_b, path_to_file) # create the xml structure root = etree.Element("product_diffusion") product = etree.SubElement(root, "product") etree.SubElement(product,"file_name").text = Tools.ack_str(self.new_filename) etree.SubElement(product,"file_size").text = Tools.ack_str(self._get_file_size()) etree.SubElement(product,"priority").text = Tools.ack_str(self._get_priority()) etree.SubElement(product,"archive").text = "0" end_date = self._get_end_date() # add a end_date only if user specified one if end_date is not None: etree.SubElement(product,"end_to_live_date").text = Tools.ack_str(end_date) # loop on all the requests linked to the file to send to difmet for req_id in self.id_list: diffusion = etree.SubElement(product,"diffusion") # fetch the informations stored from json instruction file instr = self.instructions[req_id] diff = instr["diffusion"] etree.SubElement(diffusion,"diffusion_externalid").text = Database.get_external_id(req_id, self.new_filename) etree.SubElement(diffusion,"archive").text = "0" self.diff_info_to_xml(diffusion, diff) # if an alternative diffusion is requested, it is added if "alternativeDiffusion" in instr.keys(): altdiff = instr["alternativeDiffusion"] prefix = get_prefix(altdiff) self.diff_info_to_xml(diffusion,altdiff, prefix=prefix) etree.SubElement(diffusion,"standby_media").text = altdiff["DiffusionType"] if altdiff["DiffusionType"] == "FTP" and diff["DiffusionType"] == "FTP": etree.SubElement(diffusion, "switch_method_medias_ftp").text = "NTRY" etree.SubElement(diffusion,"standby_switch_try_number").text = "3" etree.SubElement(product, "diffusionnumber").text=str(len(self.id_list)) etree.SubElement(root, "productnumber").text="1" # Dump the xml tree into a file etree.ElementTree(root).write(path_to_file, pretty_print=True, encoding='UTF-8', xml_declaration=True) return path_to_file