コード例 #1
0
ファイル: lfc_count_entries.py プロジェクト: goiwai/kekcc
def count_entry(root_dir):
    dir = lfc.lfc_opendirg(root_dir, "")

    counter = {"dir":0, "file":0}

    if (dir == None) or (dir == 0):
        print_error("Error while looking for " + root_dir)
        return counter

    while True:
        read_pt = lfc.lfc_readdirxr(dir,"")
        
        if (read_pt == None) or (read_pt == 0):
            break
        entry, list = read_pt
        p = root_dir + '/' + entry.d_name
        if stat.S_ISDIR(entry.filemode):
            counter['dir'] += 1
            cnt = count_entry(p)
            #print cnt
            counter['dir'] += cnt['dir']
            counter['file'] += cnt['file']
        else:
            counter['file'] += 1

    lfc.lfc_closedir(dir)
    return counter
コード例 #2
0
def readdirxr_recurse(*args):
  
  if len(args) < 1:
    folder = ''
    prefix = ''
  else:
    folder = args[0]
    prefix = folder + '/'
  
  if (folder == '') or (folder[0] != '/'):
    if 'LFC_HOME' in os.environ:
      folder = os.environ['LFC_HOME'] + '/' + prefix
    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)
  
  #---------------------------------------------------------------------------
  # Loop on the entries of the folder
  #---------------------------------------------------------------------------
  folders = []
  
  while 1:
    read_pt = lfc.lfc_readdirxr(dir, '')
    if read_pt == None:
      break
    entry, replicas = read_pt
    name = prefix + entry.d_name
    if   entry.filemode & 040000:
      folders.append(name)
      comment = '   (Folder)'
    elif entry.nbreplicas == 0:
      comment = '   (No replica)'
    else:
      comment = ''
    print name + comment
    #-------------------------------------------------------------------------
    # If the entry is a regular file, list its replicas
    #-------------------------------------------------------------------------
    if comment == '':
      for replica in replicas:
         print '    ==>', replica.sfn
  
  lfc.lfc_closedir(dir)
  
  #---------------------------------------------------------------------------
  # Recurse on subfolders
  #---------------------------------------------------------------------------
  for name in folders:
    readdirxr_recurse(name)
コード例 #3
0
def readdirxr(folderFiles):
  
  folderKeys = folderFiles.keys()
  folderKeys.sort()
  #print folderKeys
  
  #---------------------------------------------------------------------------
  # Loop on the folders
  #---------------------------------------------------------------------------
  for folder in folderKeys:
    prefix = folder
    #print '\n' + prefix + ':', folderFiles[prefix]
    
    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)
    
    #-------------------------------------------------------------------------
    # Loop on the entries of the folder which are in the dictionary
    #-------------------------------------------------------------------------
    while 1:
      read_pt = lfc.lfc_readdirxr(dir, '')
      if read_pt == None:
        break
      
      entry, replicas = read_pt
      if entry.d_name not in folderFiles[prefix]:
        break
      
      if   entry.filemode & 040000:
        comment = '   (Folder)'
      elif entry.nbreplicas == 0:
        comment = '   (No replica)'
      else:
        comment = ''
      print prefix + entry.d_name
      #-----------------------------------------------------------------------
      # If the entry is a regular file, list its replicas
      #-----------------------------------------------------------------------
      if comment == '':
        for replica in replicas:
           print '    ==>', replica.sfn
    
    lfc.lfc_closedir(dir)
コード例 #4
0
    def scan_dir(self, root_dir):
        dir = lfc.lfc_opendirg(root_dir, "")

        if (dir == None) or (dir == 0):
            return self.print_error("Error while looking for " + root_dir)

        while True:
            read_pt = lfc.lfc_readdirxr(dir,"")
        
            if (read_pt == None) or (read_pt == 0):
                break

            entry, list = read_pt
            p = root_dir + '/' + entry.d_name
            if stat.S_ISDIR(entry.filemode):
                self.scan_dir(p)
            else:
                self.print_GUID(p)
                try:
                    n_replica = len(list)
                    for i in range(n_replica):
                        print " ==> replica (%d/%d) %s" % (i+1, n_replica, list[i].sfn)
                except TypeError, x:
                    print " ==> None"
コード例 #5
0
print "result = " + str(result)
print "len(list) = " + str(len(list)) + " replicas found"

if (result == 0):
	for i in list:
		print i.host
		print i.sfn

#
# using lfc_readdirxr method
#

dir = lfc.lfc_opendirg(directory,"")

while 1:
	read_pt = lfc.lfc_readdirxr(dir,"")
	if (read_pt == None) or (read_pt == 0):
		break
	entry,list=read_pt
	print entry.d_name
	try:
		for i in range(len(list)):
			print "   ==> %s" % list[i].sfn
	except TypeError, x:
		print "   ==> None"

lfc.lfc_closedir(dir)

#
# delete test entry
#
コード例 #6
0
ファイル: getReplicas.py プロジェクト: mapa17/PeggyVine
#import lfc2 as lfc
#Add path to lcg library to search path in order to find lfc library
sys.path.append("/opt/lcg")
import lfc as lfc


try:
    if len(sys.argv) < 2:
        print "Syntax: %s <LFC_directory>" % sys.argv[0]
        sys.exit(-1)

    name = sys.argv[1]

    dir = lfc.lfc_opendir(name)

    while 1:
        entry = lfc.lfc_readdirxr(dir)
        if entry == None:
            break
        print entry.d_name
        for i in range(entry.nbreplicas):
            print " ==> %s" % entry.rep[i].sfn

    lfc.lfc_closedir(dir)
    
except TypeError, x:
    print " ==> None"
except Exception:
    traceback.print_exc()
    sys.exit(1)
コード例 #7
0
ファイル: readdirxr.py プロジェクト: mapa17/PeggyVine
"""
# Using the lfc_getacl to get ACL entries for a file/directory
"""

if len(sys.argv) < 2:
        print "Syntax: %s <LFC_path>" % sys.argv[0]
        sys.exit(-1)

name = sys.argv[1]


dir = lfc.lfc_opendirg(name,"")


entry,list = lfc.lfc_readdirxr(dir,"")
while entry != None : 
        print "---"
        print entry.d_name
        if entry.guid == "":
                print "Dir"
        else:
                print entry.guid
        if list != None:
                for i in range(len(list) ):
                        print list[i].sfn 
        try:
                entry,list = lfc.lfc_readdirxr(dir,"")
        except Exception , e:
                break