def getGUID(fileNames, directory=""): """This function searches the directory for POOL XML catalog files and extracts the GUID. fileNames can be a string or a list, directory defaults to PWD. """ if not directory: directory = os.getcwd() if not os.path.isdir(directory): return S_ERROR("%s is not a directory" % directory) if not isinstance(fileNames, list): fileNames = [fileNames] gLogger.verbose("Will look for POOL XML Catalog GUIDs in %s for %s" % (directory, ", ".join(fileNames))) finalCatList = _getPoolCatalogs(directory) # Create POOL catalog with final list of catalog files and extract GUIDs generated = [] pfnGUIDs = {} catalog = PoolXMLCatalog(finalCatList) for fname in fileNames: guid = str(catalog.getGuidByPfn(fname)) if not guid: guid = makeGuid(fname) generated.append(fname) pfnGUIDs[fname] = guid if not generated: gLogger.info("Found GUIDs from POOL XML Catalogue for all files: %s" % ", ".join(fileNames)) else: gLogger.info( "GUIDs not found from POOL XML Catalogue (and were generated) for: %s" % ", ".join(generated)) result = S_OK(pfnGUIDs) result["directory"] = directory result["generated"] = generated return result
def getGUID( fileNames, directory = '' ): """ This function searches the directory for POOL XML catalog files and extracts the GUID. fileNames can be a string or a list, directory defaults to PWD. """ if not directory: directory = os.getcwd() if not os.path.isdir( directory ): return S_ERROR( '%s is not a directory' % directory ) if not type( fileNames ) == type( [] ): fileNames = [fileNames] gLogger.verbose( 'Will look for POOL XML Catalog GUIDs in %s for %s' % ( directory, ', '.join( fileNames ) ) ) finalCatList = _getPoolCatalogs( directory ) #Create POOL catalog with final list of catalog files and extract GUIDs generated = [] pfnGUIDs = {} catalog = PoolXMLCatalog( finalCatList ) for fname in fileNames: guid = str( catalog.getGuidByPfn( fname ) ) if not guid: guid = makeGuid( fname ) generated.append( fname ) pfnGUIDs[fname] = guid if not generated: gLogger.info( 'Found GUIDs from POOL XML Catalogue for all files: %s' % ', '.join( fileNames) ) else: gLogger.info( 'GUIDs not found from POOL XML Catalogue (and were generated) for: %s' % ', '.join( generated) ) result = S_OK( pfnGUIDs ) result['directory'] = directory result['generated'] = generated return result
finalCatList = [] for possibleCat in poolCatalogList: try: cat = PoolXMLCatalog(possibleCat) finalCatList.append(possibleCat) except Exception, x: gLogger.debug('Ignoring non-POOL catalogue file %s' % possibleCat) #Create POOL catalog with final list of catalog files and extract GUIDs generated = [] pfnGUIDs = {} gLogger.debug('Final list of catalog files are: %s' % string.join(finalCatList, ', ')) catalog = PoolXMLCatalog(finalCatList) for fname in fileNames: guid = str(catalog.getGuidByPfn(fname)) if not guid: guid = makeGuid(fname) generated.append(fname) pfnGUIDs[fname] = guid if not generated: gLogger.info('Found GUIDs from POOL XML Catalogue for all files: %s' % string.join(fileNames, ', ')) else: gLogger.info( 'GUIDs not found from POOL XML Catalogue (and were generated) for: %s' % string.join(generated, ', ')) result = S_OK(pfnGUIDs)
#Now have list of all XML files but some may not be Pool XML catalogs... finalCatList = [] for possibleCat in poolCatalogList: try: cat = PoolXMLCatalog(possibleCat) finalCatList.append(possibleCat) except Exception,x: gLogger.debug('Ignoring non-POOL catalogue file %s' %possibleCat) #Create POOL catalog with final list of catalog files and extract GUIDs generated = [] pfnGUIDs = {} gLogger.debug('Final list of catalog files are: %s' %string.join(finalCatList,', ')) catalog = PoolXMLCatalog(finalCatList) for fname in fileNames: guid = str(catalog.getGuidByPfn(fname)) if not guid: guid = makeGuid(fname) generated.append(fname) pfnGUIDs[fname]=guid if not generated: gLogger.info('Found GUIDs from POOL XML Catalogue for all files: %s' %string.join(fileNames,', ')) else: gLogger.info('GUIDs not found from POOL XML Catalogue (and were generated) for: %s' %string.join(generated,', ')) result = S_OK(pfnGUIDs) result['directory']=directory result['generated']=generated return result