s4cmd.py
def s3walk(self, basedir, show_dir=None):
    '''Walk through a S3 directory. This function initiate a walk with a basedir.
       It also supports multiple wildcards.
    '''
    # Provide the default value from command line if no override.
    if not show_dir:
      show_dir = self.opt.show_dir

    # trailing slash normalization, this is for the reason that we want
    # ls 's3://foo/bar/' has the same result as 's3://foo/bar'. Since we
    # call partial_match() to check wildcards, we need to ensure the number
    # of slashes stays the same when we do this.
    if basedir[-1] == PATH_SEP:
      basedir = basedir[0:-1]

    s3url = S3URL(basedir)
    result = []

    pool = ThreadPool(ThreadUtil, self.opt)
    pool.s3walk(s3url, s3url.get_fixed_path(), s3url.path, result)
    pool.join()

    # automatic directory detection
    if not show_dir and len(result) == 1 and result[0]['is_dir']:
      path = result[0]['name']
      s3url = S3URL(path)
      result = []
      pool = ThreadPool(ThreadUtil, self.opt)
      pool.s3walk(s3url, s3url.get_fixed_path(), s3url.path, result)
      pool.join()

    def compare(x, y):
      '''Comparator for ls output'''
      result = -cmp(x['is_dir'], y['is_dir'])
      if result != 0:
        return result
      return cmp(x['name'], y['name'])
    return sorted(result, key=cmp_to_key(compare))
def s3walk(self, basedir, show_dir=None):
    '''Walk through a S3 directory. This function initiate a walk with a basedir.
       It also supports multiple wildcards.
    '''
    # Provide the default value from command line if no override.
    if not show_dir:
      show_dir = self.opt.show_dir

    # trailing slash normalization, this is for the reason that we want
    # ls 's3://foo/bar/' has the same result as 's3://foo/bar'. Since we
    # call partial_match() to check wildcards, we need to ensure the number
    # of slashes stays the same when we do this.
    if basedir[-1] == PATH_SEP:
      basedir = basedir[0:-1]

    s3url = S3URL(basedir)
    result = []

    pool = ThreadPool(ThreadUtil, self.opt)
    pool.s3walk(s3url, s3url.get_fixed_path(), s3url.path, result)
    pool.join()

    # automatic directory detection
    if not show_dir and len(result) == 1 and result[0]['is_dir']:
      path = result[0]['name']
      s3url = S3URL(path)
      result = []
      pool = ThreadPool(ThreadUtil, self.opt)
      pool.s3walk(s3url, s3url.get_fixed_path(), s3url.path, result)
      pool.join()

    def compare(x, y):
      '''Comparator for ls output'''
      result = -cmp(x['is_dir'], y['is_dir'])
      if result != 0:
        return result
      return cmp(x['name'], y['name'])
    return sorted(result, key=cmp_to_key(compare))
def s3walk ( self , basedir , show_dir = None ) : # Provide the default value from command line if no override. if not show_dir : show_dir = self . opt . show_dir # trailing slash normalization, this is for the reason that we want # ls 's3://foo/bar/' has the same result as 's3://foo/bar'. Since we # call partial_match() to check wildcards, we need to ensure the number # of slashes stays the same when we do this. if basedir [ - 1 ] == PATH_SEP : basedir = basedir [ 0 : - 1 ] s3url = S3URL ( basedir ) result = [ ] pool = ThreadPool ( ThreadUtil , self . opt ) pool . s3walk ( s3url , s3url . get_fixed_path ( ) , s3url . path , result ) pool . join ( ) # automatic directory detection if not show_dir and len ( result ) == 1 and result [ 0 ] [ 'is_dir' ] : path = result [ 0 ] [ 'name' ] s3url = S3URL ( path ) result = [ ] pool = ThreadPool ( ThreadUtil , self . opt ) pool . s3walk ( s3url , s3url . get_fixed_path ( ) , s3url . path , result ) pool . join ( ) def compare ( x , y ) : '''Comparator for ls output''' result = - cmp ( x [ 'is_dir' ] , y [ 'is_dir' ] ) if result != 0 : return result return cmp ( x [ 'name' ] , y [ 'name' ] ) return sorted ( result , key = cmp_to_key ( compare ) )
Walk through a S3 directory. This function initiate a walk with a basedir.
       It also supports multiple wildcards.
Walk through a S3 directory . This function initiate a walk with a basedir . It also supports multiple wildcards .