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
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()
# Close the folder. # If at least one file found is not a symbolic link, stop. #----------------------------------------------------------------------------- lfc.lfc_closedir(dir) if not b_OK: sys.exit(1) print folder, ': ', len(symlinks), 'symbolic links found' if len(symlinks) > 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
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:]))
folder = os.environ['LFC_HOME'] + '/' + folder else: sys.exit('Relative folder path requires LFC_HOME to be set and exported') pos1 = source.rfind('/') sourcename = source[pos1+1:] pos2 = sourcename.rfind('.') if pos2 > -1: targetname = folder + '/' + sourcename[:pos2] suffix = sourcename[pos2:] else: targetname = folder + '/' + sourcename suffix = '' if lfc.lfc_startsess('', '') != 0: err_num = lfc.cvar.serrno err_string = lfc.sstrerror(err_num) sys.exit('Error ' + str(err_num) + ' starting LFC session: ' + err_string) for number in range(nb_symlinks): name = targetname + str(number).zfill(nb_char) + suffix res = lfc.lfc_symlink(source, name) if res != 0: err_num = lfc.cvar.serrno err_string = lfc.sstrerror(err_num) print 'Error ' + str(err_num) + ' while creating ' + name + ': ' + err_string number -= 1 break lfc.lfc_endsess()
#!/bin/env python import lfc import sys CHUNK=500 # How many replicas to delete in each call to LFC # Files are often registered in LFC with different URLs. List here # all the known url prefixes that can be added to your dq2-orphans # output to make LFC-registered SFNs SFN_PREFIXES=['srm://uct2-dc1.uchicago.edu/pnfs/uchicago.edu/', 'srm://uct2-dc1.uchicago.edu:8443/srm/managerv2?SFN=/pnfs/uchicago.edu/'] # Set your LFC server. s=lfc.lfc_startsess('ust2lfc.usatlas.bnl.gov',"") def del_replicas(sfns,guids): rem_guids=[] rem_sfns=[] for sfn_prefix in SFN_PREFIXES: prefixed_sfns=[ sfn_prefix + sfn for sfn in sfns ] result,err_nums=lfc.lfc_delreplicasbysfn(prefixed_sfns,guids) #print err_nums for i in range(len(err_nums)): err_num=err_nums[i] if err_num == 2: rem_guids.append(guids[i]) rem_sfns.append(sfns[i]) elif err_num != 0: err_string = lfc.sstrerror(err_num) print "There was an error for guid " + guids[i] + ": " + str(err_num) + " (" + err_string + ")" guids=rem_guids sfns=rem_sfns rem_guids=[]
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()
sys.stderr.write(msg) return -1 lfnList=file.readlines() # From command line options else: if(len(args)<1): print "Not enough input arguments" usage() return(-1) lfnList=[args[0]] # Do the removal (under session) lfc.lfc_startsess("", "") err = deleteEntries(lfnList, keepLfn, removeLinks, verbose) lfc.lfc_endsess() # Return the error code return err ######################### SCRIPT ########################### if __name__ == "__main__": sys.exit(main(sys.argv[1:]))