Beispiel #1
0
def getPFNsFromLFC(guidLfnMap):
    """Check LFC for local site and find the PFNs of the required files.
    """
    #    print "Getting PFNs from LFC..."
    if os.environ['LFC_HOST'] == '':
        raise ConfigError("Error: LFC_HOST is not set! Exiting now...")

    try:
        pfns = {}
        lfc.lfc_startsess('', '')
        for guid, lfn in guidLfnMap.iteritems():
            rc, frs = lfc.lfc_getreplica('', guid, '')
            if rc == 0 and frs != None and len(frs) != 0:
                # get SURL
                sfn = frs[0].sfn

                # remove protocol and host
                #TODO       # currently hardwired for local access - need to make this more flexible
                #            pfn = re.sub('^[^:]+://[^/]+','rfio:',sfn)
                pfn = 'file:///tmp/aod/' + lfn

                pfns[lfn] = pfn
        lfc.lfc_endsess()
    except:
        logger.warning("Error in getPFNsFromLFC")
        pass

    return pfns
def getPFNsFromLFC(guidLfnMap):
    """Check LFC for local site and find the PFNs of the required files.
    """
#    print "Getting PFNs from LFC..."
    if os.environ['LFC_HOST'] == '':
        raise ConfigError("Error: LFC_HOST is not set! Exiting now...")

    try:
        pfns = {}
        lfc.lfc_startsess('','')
        for guid, lfn in guidLfnMap.iteritems():
            rc,frs = lfc.lfc_getreplica('',guid,'')
            if rc == 0 and frs != None and len(frs) != 0:
                # get SURL
                sfn = frs[0].sfn
                                                                                                      
            # remove protocol and host
#TODO       # currently hardwired for local access - need to make this more flexible
#            pfn = re.sub('^[^:]+://[^/]+','rfio:',sfn)
                pfn = 'file:///tmp/aod/'+lfn
                                                                                                      
                pfns[lfn] = pfn
        lfc.lfc_endsess()
    except:
        logger.warning("Error in getPFNsFromLFC")
        pass

    return pfns
Beispiel #3
0
def get_replicas(files):
    
  #---------------------------------------------------------------------------
  # Loop on the list of files
  #---------------------------------------------------------------------------
  lfc.lfc_startsess('', '')
  
  for myfile in files:
    print myfile['name']
    
    #-------------------------------------------------------------------------
    # If the entry is a regular file, list its replicas using its GUID
    #-------------------------------------------------------------------------
    if not (myfile['mode'] & 060000):     # Exclude folders and symbolic links
      (res, replicas) = lfc.lfc_getreplica('', myfile['guid'], '')
      if res == 0:
        for replica in replicas:
          print '   ==>', replica.sfn
  
  lfc.lfc_endsess()
Beispiel #4
0
  #  Here all files inside the folder are symbolic links.
  #  Open an LFC session.
  #---------------------------------------------------------------------------
  res = lfc.lfc_startsess('', '')
  if res != 0:
    err_num = lfc.cvar.serrno
    err_string = lfc.sstrerror(err_num)
    sys.exit('Error ' + str(err_num) + ' starting LFC session: ' + err_string)
  
  #---------------------------------------------------------------------------
  #  Loop on the symbolic links contained by the folder to delete them
  #---------------------------------------------------------------------------
  number = 0
  
  for name in symlinks:
    name = folder + '/' + name
    res  = lfc.lfc_unlink(name)
    if res == 0:
      number += 1
    else:
      err_num = lfc.cvar.serrno
      err_string = lfc.sstrerror(err_num)
      print "Error " + str(err_num) + " while deleting " + name + ": " + err_string
  
  print folder, ': ', number, 'symbolic links deleted'
  
  #---------------------------------------------------------------------------
  #  Close the LFC session.
  #---------------------------------------------------------------------------
  lfc.lfc_endsess()
Beispiel #5
0
        try:
            file = open(fname, 'r')
        except IOError, inst:
            msg = "The file " + fname + " could not be opened: " + str(
                inst) + "\n"
            sys.stderr.write(msg)
            return -1
        dirList = file.readlines()

    # From command line options
    else:
        if (len(args) < 1):
            print "Not enough input arguments"
            usage()
            return (-1)
        dirList = [args[0]]

# Do the removal (under session)
    lfc.lfc_startsess("", "")
    err = deleteDirs(dirList, force, extLinks, extLfns, verbose)
    lfc.lfc_endsess()

    # Finally, if no error exited before, exit succesfully
    return err


######################### SCRIPT ###########################

if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))
Beispiel #6
0
def readdirg_gr(*args):
  
  if len(args) < 1:
    folder = ''
  else:
    folder = args[0]
  
  if (folder == '') or (folder[0] != '/'):
    if 'LFC_HOME' in os.environ:
      folder = os.environ['LFC_HOME'] + '/' + folder
    else:
      sys.exit('Relative folder path requires LFC_HOME to be set and exported')
  
  #---------------------------------------------------------------------------
  # Open the folder
  #---------------------------------------------------------------------------
  dir = lfc.lfc_opendirg(folder, '')
  if dir == None:
    err_num    = lfc.cvar.serrno
    err_string = lfc.sstrerror(err_num)
    sys.exit('Error ' + str(err_num) + ' on folder ' + folder + ': ' + err_string)
  
  files = []
  listp = lfc.lfc_list()
  
  #---------------------------------------------------------------------------
  # Loop on the entries of the folder to build the list of files
  #---------------------------------------------------------------------------
  while 1:
    entry = lfc.lfc_readdirg(dir)
    if entry == None:
      break
    if   entry.filemode & 040000:
      marker = '/'
    elif entry.filemode & 020000:     # not entry.guid:
      marker = '@'
    else:
      marker = ''
    files.append({'name': entry.d_name + marker,
                  'mode': entry.filemode,
                  'guid': entry.guid})
  
  lfc.lfc_closedir(dir)
  
  #---------------------------------------------------------------------------
  # Loop on the list of files
  #---------------------------------------------------------------------------
  lfc.lfc_startsess('', '')
  
  for myfile in files:
    print ('%06o' % myfile['mode']) + '  ' + myfile['name']
    
    #-------------------------------------------------------------------------
    # If the entry is a regular file, list its replicas using its GUID
    #-------------------------------------------------------------------------
    if not (myfile['mode'] & 060000):     # Exclude folders and symbolic links
      (res, replicas) = lfc.lfc_getreplica('', myfile['guid'], '')
      if res == 0:
        for replica in replicas:
          print '   ==>', replica.sfn
        print 'Found ' + str(len(replicas)) + ' replica(s)'
    
    print
  
  lfc.lfc_endsess()