def create_sample(file: str): logger.info('create the sample config XML file: ' + str(file)) root = ET.Element(Tag.source) tree = ET.ElementTree(root) #tree._setroot(root) root.append(ET.Comment(' Supported version of "app_source" ')) LMetree.create_subelem(root, Tag.version, __version__) apps = ET.SubElement(root, Tag.apps) append_eclipse(apps) append_java(apps) append_npp(apps) append_putty(apps) append_python(apps) append_git(apps) append_winmerge(apps) LMetree.indent(root) # NOTE: ElementTree.write() will use new line cgar CRLF but git repo has line ending LF #tree.write(file, encoding="UTF-8", xml_declaration=True) ''' # NOTE: copied from ElementTree module _get_writer(...) -function # This does not work -> byte writer is expected by ElementTree._get_writer() file_objects = open(file, "w", encoding="UTF-8", newline='\n', errors="xmlcharrefreplace") ''' file_objects = open(file, "wb") # TODO: ElementTree.write() -function should have parameter 'newline' and it should be passed to _get_writer() -function # TODO: Send request to ElementTree toolkit project. Python core project? # https://docs.python.org/3/library/xml.etree.elementtree.html tree.write(file_objects, encoding="UTF-8", xml_declaration=True)
def set_file(elem: Element, file: str = None): LMetree.create_subelem(elem, Tag.file, file)
def set_sha256url(elem: Element, sha256url: str = None, sha256file: str = None): LMetree.create_subelem(elem, Tag.sha256url, sha256url) LMetree.create_subelem(elem, Tag.sha256file, sha256file)
def set_md5sum(elem: Element, md5sum: str = None): LMetree.create_subelem(elem, Tag.md5sum, md5sum)
def set_sha256sum(elem: Element, sha256sum: str = None): LMetree.create_subelem(elem, Tag.sha256sum, sha256sum)
def set_md5url(elem: Element, md5url: str = None, md5file: str = None): LMetree.create_subelem(elem, Tag.md5url, md5url) LMetree.create_subelem(elem, Tag.md5file, md5file)
def set_url(elem: Element, url: str = None): LMetree.create_subelem(elem, Tag.url, url)
def append_lateset_element(elem: Element, text: str): LMetree.create_subelem(elem, Tag.latest, text)