Beispiel #1
0
def create_file(
    xml_element: etree.Element,
    doc_name: str,
    file_path: Path,
    server: DistributedServer = None,
) -> None:
    """
    Create xml file.

    :param xml_element: root element to write to file
    :param doc_name: name to use in the emane doctype
    :param file_path: file path to write xml file to
    :param server: remote server to create file on
    :return: nothing
    """
    doctype = (
        f'<!DOCTYPE {doc_name} SYSTEM "file:///usr/share/emane/dtd/{doc_name}.dtd">'
    )
    if server:
        temp = NamedTemporaryFile(delete=False)
        temp_path = Path(temp.name)
        corexml.write_xml_file(xml_element, temp_path, doctype=doctype)
        temp.close()
        server.remote_put(temp_path, file_path)
        temp_path.unlink()
    else:
        corexml.write_xml_file(xml_element, file_path, doctype=doctype)
Beispiel #2
0
def create_file(
    xml_element: etree.Element,
    doc_name: str,
    file_path: str,
    server: DistributedServer = None,
) -> None:
    """
    Create xml file.

    :param xml_element: root element to write to file
    :param doc_name: name to use in the emane doctype
    :param file_path: file path to write xml file to
    :param server: remote server node
            will run on, default is None for localhost
    :return: nothing
    """
    doctype = (
        f'<!DOCTYPE {doc_name} SYSTEM "file:///usr/share/emane/dtd/{doc_name}.dtd">'
    )
    if server is not None:
        temp = NamedTemporaryFile(delete=False)
        create_file(xml_element, doc_name, temp.name)
        temp.close()
        server.remote_put(temp.name, file_path)
        os.unlink(temp.name)
    else:
        corexml.write_xml_file(xml_element, file_path, doctype=doctype)
Beispiel #3
0
def create_file(xml_element, doc_name, file_path):
    """
    Create xml file.

    :param lxml.etree.Element xml_element: root element to write to file
    :param str doc_name: name to use in the emane doctype
    :param str file_path: file path to write xml file to
    :return: nothing
    """
    doctype = '<!DOCTYPE %(doc_name)s SYSTEM "file:///usr/share/emane/dtd/%(doc_name)s.dtd">' % {"doc_name": doc_name}
    corexml.write_xml_file(xml_element, file_path, doctype=doctype)
Beispiel #4
0
def create_file(xml_element, doc_name, file_path):
    """
    Create xml file.

    :param lxml.etree.Element xml_element: root element to write to file
    :param str doc_name: name to use in the emane doctype
    :param str file_path: file path to write xml file to
    :return: nothing
    """
    doctype = '<!DOCTYPE %(doc_name)s SYSTEM "file:///usr/share/emane/dtd/%(doc_name)s.dtd">' % {"doc_name": doc_name}
    corexml.write_xml_file(xml_element, file_path, doctype=doctype)