def _RecComputeRebalanceSize(mapping, server_id, dspath, subpath):
 total = 0
 fulldir = utils.JoinPath(dspath, subpath)
 for comp in os.listdir(fulldir):
  if (comp == constants.REBALANCE_DIRECTORY):
   continue
  path = utils.JoinPath(fulldir, comp)
  (name, unused_extension) = os.path.splitext(comp)
  if (name in COPY_EXCEPTIONS):
   logging.info('Skip %s', comp)
   continue
  if os.path.isdir(path):
   total += _RecComputeRebalanceSize(mapping, server_id, dspath, utils.JoinPath(subpath, comp))
  elif os.path.isfile(path):
   key = common.MakeDestinationKey(subpath, name)
   where = sutils.MapKeyToServer(mapping, key)
   if (where != server_id):
    logging.info('Need to move %s from %d to %d', path, server_id, where)
    total += os.path.getsize(path)
   else:
    logging.info('File %s stays here', path)
 return total

def _RecComputeRebalanceSize ( mapping , server_id , dspath , subpath ) : total = 0 fulldir = utils . JoinPath ( dspath , subpath ) for comp in os . listdir ( fulldir ) : if ( comp == constants . REBALANCE_DIRECTORY ) : continue path = utils . JoinPath ( fulldir , comp ) ( name , unused_extension ) = os . path . splitext ( comp ) if ( name in COPY_EXCEPTIONS ) : logging . info ( 'Skip %s' , comp ) continue if os . path . isdir ( path ) : total += _RecComputeRebalanceSize ( mapping , server_id , dspath , utils . JoinPath ( subpath , comp ) ) elif os . path . isfile ( path ) : key = common . MakeDestinationKey ( subpath , name ) where = sutils . MapKeyToServer ( mapping , key ) if ( where != server_id ) : logging . info ( 'Need to move %s from %d to %d' , path , server_id , where ) total += os . path . getsize ( path ) else : logging . info ( 'File %s stays here' , path ) return total
recursively compute the size of files that need to be moved .