def getXmlNames(filepath):
    ''' Extracts the xml names from a describe '''

    if not os.path.isfile( filepath ):
        raise NotCreatedDescribeLog( filepath )
    
    with open( filepath, 'r' ) as filepath:
        lines = filepath.read()

    regex_string = (r'\*+\nXMLName: ([a-zA-Z0-9]+)\nDirName: ([a-zA-Z0-9]+)\nSuffix:'
                    r' ([a-zA-Z0-9]+)\nHasMetaFile: ([a-zA-Z]+)\nInFolder:'
                    r' ([a-zA-Z]+)\nChildObjects: (?:([a-zA-Z,]+),|)\*+')

    xmlNames    = re.findall(regex_string, lines, re.MULTILINE)
    dictionary  = dict()

    for (xmlName, dirName, suffix, hasMetadata, inFolder, childObjects) in xmlNames:
        inFolder    = castToBoolean( inFolder )
        hasMetadata = castToBoolean( hasMetadata )
        dictKey     = dirName

        if 'territory2Models' == dirName and 'territory2Model' != suffix:
            dictKey = suffix
        dictionary[ dictKey ] = MetadataType( xmlName, dirName, suffix, hasMetadata, inFolder, childObjects )

    return dictionary
def getXmlNamesFromJSON(filepath):
    ''' Extracts the xml names from a describe '''

    if not os.path.isfile( filepath ):
        raise NotCreatedDescribeLog( filepath )
    
    with open( filepath, 'r' ) as file:
        data = json.load( file )

    dictionary = {}

    for metadataInfo in data[ 'metadataObjects' ]:
        inFolder        = metadataInfo[ 'inFolder' ]
        hasMetadata     = metadataInfo[ 'metaFile' ]
        childObjects    = metadataInfo[ 'childXmlNames' ] if 'childXmlNames' in metadataInfo else []
        suffix          = metadataInfo[ 'suffix' ] if 'suffix' in metadataInfo else ''
        xmlName         = metadataInfo[ 'xmlName' ]
        dirName         = metadataInfo[ 'directoryName' ]
        dictKey         = dirName

        if 'territory2Models' == dirName and 'territory2Model' != suffix:
            dictKey = suffix
        dictionary[ dictKey ] = MetadataType( xmlName, dirName, suffix, hasMetadata, inFolder, childObjects )

    return dictionary
Esempio n. 3
0
def readDescribe(pathDescribe, setParseableObjects):
    ''' Extracts the xml names from a describe '''
    if not os.path.isfile( pathDescribe ):
        raise NotCreatedDescribeLog( pathDescribe )
    
    with open( pathDescribe, 'r' ) as file:
        data = json.load( file )

    for metadataInfo in data[ 'metadataObjects' ]:
        dirName         = metadataInfo[ 'directoryName' ]
        childObjects    = metadataInfo[ 'childXmlNames' ] if 'childXmlNames' in metadataInfo else []
        if dirName != 'objects' and len( childObjects ) > 0:
            setParseableObjects.add( dirName )

    return setParseableObjects
def get_xml_names(filepath):
    ''' Extracts the xml names from a describe '''
    if not os.path.isfile(filepath):
        raise NotCreatedDescribeLog(filepath)

    with open(filepath, 'r') as file:
        try:
            data = json.load(file)
            isJSON = True
        except:
            data = file.read()
            isJSON = False

    if isJSON:
        dictionary = getXmlNamesFromJSON(data)
    else:
        dictionary = getXmlNamesFromLog(data)

    return dictionary