def DatabaseDirectorySize(root_path, extension):
 directories = collections.deque([root_path])
 total_size = 0
 total_files = 0
 while directories:
  directory = directories.popleft()
  try:
   items = os.listdir(directory)
  except OSError:
   continue
  for comp in items:
   if (comp == constants.REBALANCE_DIRECTORY):
    continue
   path = os.path.join(directory, comp)
   try:
    statinfo = os.lstat(path)
    if stat.S_ISLNK(statinfo.st_mode):
     continue
    if stat.S_ISDIR(statinfo.st_mode):
     directories.append(path)
    elif stat.S_ISREG(statinfo.st_mode):
     if comp.endswith(extension):
      total_size += statinfo.st_size
      total_files += 1
   except OSError:
    continue
 return (total_size, total_files)

def DatabaseDirectorySize ( root_path , extension ) : directories = collections . deque ( [ root_path ] ) total_size = 0 total_files = 0 while directories : directory = directories . popleft ( ) try : items = os . listdir ( directory ) except OSError : continue for comp in items : if ( comp == constants . REBALANCE_DIRECTORY ) : continue path = os . path . join ( directory , comp ) try : statinfo = os . lstat ( path ) if stat . S_ISLNK ( statinfo . st_mode ) : continue if stat . S_ISDIR ( statinfo . st_mode ) : directories . append ( path ) elif stat . S_ISREG ( statinfo . st_mode ) : if comp . endswith ( extension ) : total_size += statinfo . st_size total_files += 1 except OSError : continue return ( total_size , total_files )
compute size and number of files of a file-based data store .