Exemplo n.º 1
0
def getOutputType(outputs, inputs, directory=''):
    """ This function searches the directory for POOL XML catalog files and extracts the type of the pfn.

      If not found, inherits from the type of the inputs
  """

    if not isinstance(outputs, list):
        outputs = [outputs]

    catalog = PoolXMLCatalog(_getPoolCatalogs(directory))

    # inputs - by lfn
    generatedIn = False
    typeFileIn = []
    for fname in inputs:
        try:
            tFileIn = str(
                catalog.getTypeByPfn(
                    str(catalog.getPfnsByLfn(fname)['Replicas'].values()[0])))
        except KeyError:
            tFileIn = None
        if not tFileIn:
            generatedIn = True
        else:
            typeFileIn.append(tFileIn)

    if generatedIn and inputs:
        raise ValueError('Could not find Type for inputs')

    # outputs - by pfn
    pfnTypesOut = {}
    for fname in outputs:
        tFileOut = str(catalog.getTypeByPfn(fname))
        if not tFileOut:
            if typeFileIn:
                tFileOut = typeFileIn[0]
            else:
                tFileOut = 'ROOT'
        pfnTypesOut[fname] = tFileOut

    return pfnTypesOut
Exemplo n.º 2
0
def getType(fileNames, directory=""):
    """This function searches the directory for POOL XML catalog files and extracts the type of the pfn.

    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 file types in %s for %s" %
                    (directory, ", ".join(fileNames)))

    finalCatList = _getPoolCatalogs(directory)

    # Create POOL catalog with final list of catalog files and extract GUIDs
    generated = []
    pfnTypes = {}
    catalog = PoolXMLCatalog(finalCatList)
    for fname in fileNames:
        typeFile = str(catalog.getTypeByPfn(fname))
        if not typeFile:
            typeFile = "ROOT_All"
            generated.append(fname)

        pfnTypes[fname] = typeFile

    if not generated:
        gLogger.info("Found Types 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(pfnTypes)
    result["directory"] = directory
    result["generated"] = generated
    return result
Exemplo n.º 3
0
def getType( fileNames, directory = '' ):
  """ This function searches the directory for POOL XML catalog files and extracts the type of the pfn.

      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 file types in %s for %s' % ( directory, ', '.join( fileNames ) ) )

  finalCatList = _getPoolCatalogs( directory )

  #Create POOL catalog with final list of catalog files and extract GUIDs
  generated = []
  pfnTypes = {}
  catalog = PoolXMLCatalog( finalCatList )
  for fname in fileNames:
    typeFile = str( catalog.getTypeByPfn( fname ) )
    if not typeFile:
      typeFile = 'ROOT_All'
      generated.append( fname )

    pfnTypes[fname] = typeFile

  if not generated:
    gLogger.info( 'Found Types 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( pfnTypes )
  result['directory'] = directory
  result['generated'] = generated
  return result