Exemplo n.º 1
0
def processElementNodeByDerivation(derivation, elementNode):
    'Process the xml element by derivation.'
    if derivation == None:
        derivation = ImportDerivation(elementNode)
    if derivation.fileName == None:
        return
    parserFileName = elementNode.getOwnerDocument().fileName
    absoluteFileName = archive.getAbsoluteFolderPath(parserFileName,
                                                     derivation.fileName)
    if 'models/' not in absoluteFileName:
        print(
            'Warning, models/ was not in the absolute file path, so for security nothing will be done for:'
        )
        print(elementNode)
        print('For which the absolute file path is:')
        print(absoluteFileName)
        print(
            'The import tool can only read a file which has models/ in the file path.'
        )
        print(
            'To import the file, move the file into a folder called model/ or a subfolder which is inside the model folder tree.'
        )
        return
    xmlText = ''
    if derivation.fileName.endswith('.xml'):
        xmlText = archive.getFileText(absoluteFileName)
    else:
        xmlText = getXMLFromCarvingFileName(absoluteFileName)
    print('The import tool is opening the file:')
    print(absoluteFileName)
    if xmlText == '':
        print(
            'The file %s could not be found by processElementNode in import.' %
            derivation.fileName)
        return
    if derivation.importName == None:
        elementNode.attributes['_importName'] = archive.getUntilDot(
            derivation.fileName)
        if derivation.basename:
            elementNode.attributes['_importName'] = os.path.basename(
                elementNode.attributes['_importName'])
    xml_simple_reader.createAppendByText(elementNode, xmlText)
    if derivation.appendDocumentElement:
        appendAttributes(elementNode, elementNode.getDocumentElement())
    if derivation.appendElement:
        appendAttributes(elementNode, elementNode)
    elementNode.localName = 'group'
    evaluate.processArchivable(group.Group, elementNode)
Exemplo n.º 2
0
def processElementNodeByDerivation(derivation, elementNode):
    "Process the xml element by derivation."
    if derivation == None:
        derivation = ImportDerivation(elementNode)
    if derivation.fileName == None:
        return
    parserFileName = elementNode.getOwnerDocument().fileName
    absoluteFileName = archive.getAbsoluteFolderPath(parserFileName, derivation.fileName)
    if "models/" not in absoluteFileName:
        print("Warning, models/ was not in the absolute file path, so for security nothing will be done for:")
        print(elementNode)
        print("For which the absolute file path is:")
        print(absoluteFileName)
        print("The import tool can only read a file which has models/ in the file path.")
        print(
            "To import the file, move the file into a folder called model/ or a subfolder which is inside the model folder tree."
        )
        return
    xmlText = ""
    if derivation.fileName.endswith(".xml"):
        xmlText = archive.getFileText(absoluteFileName)
    else:
        xmlText = getXMLFromCarvingFileName(absoluteFileName)
    print("The import tool is opening the file:")
    print(absoluteFileName)
    if xmlText == "":
        print("The file %s could not be found by processElementNode in import." % derivation.fileName)
        return
    if derivation.importName == None:
        elementNode.attributes["_importName"] = archive.getUntilDot(derivation.fileName)
        if derivation.basename:
            elementNode.attributes["_importName"] = os.path.basename(elementNode.attributes["_importName"])
    xml_simple_reader.createAppendByText(elementNode, xmlText)
    if derivation.appendDocumentElement:
        appendAttributes(elementNode, elementNode.getDocumentElement())
    if derivation.appendElement:
        appendAttributes(elementNode, elementNode)
    elementNode.localName = "group"
    evaluate.processArchivable(group.Group, elementNode)