Skip to content

Commit

Permalink
add prefix/delimiter arguments to file listing
Browse files Browse the repository at this point in the history
  • Loading branch information
danmilon committed Aug 30, 2019
1 parent 5976bde commit 9fab52a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions b2blaze/models/file_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ def __init__(self, connector, bucket):
self._files_by_name = {}
self._files_by_id = {}

def all(self, include_hidden=False, limit=None):
def all(self, include_hidden=False, limit=None, prefix="", delimiter=None):
""" Return an updated list of all files.
(This does not include hidden files unless include_hidden flag set to True)
Parameters:
include_hidden: (bool) Include hidden files
limit: (int) Limit number of file results
prefix: (str) Limit files to those with the given prefix (default: empty string)
delimiter: (str) Files returned will be limited to those within the top folder, or any one subfolder. (default: null)
"""
if not include_hidden:
return self._update_files_list(retrieve=True, limit=limit)
return self._update_files_list(retrieve=True, limit=limit, prefix=prefix, delimiter=delimiter)
else:
results = self.all_file_versions(limit=limit)
versions = results['file_versions']
Expand Down Expand Up @@ -61,18 +63,22 @@ def delete_all(self, confirm=False):
return []


def _update_files_list(self, retrieve=False, limit=None):
def _update_files_list(self, retrieve=False, limit=None, prefix="", delimiter=None):
""" Retrieve list of all files in bucket
Parameters:
limit: (int) Max number of file results, default 10000
retrieve: (bool) Refresh local store. (default: false)
prefix: (str) Limit files to those with the given prefix (default: empty string)
delimiter: (str) Files returned will be limited to those within the top folder, or any one subfolder. (default: null)
"""
path = API.list_all_files
files = []
new_files_to_retrieve = True
params = {
'bucketId': self.bucket.bucket_id,
'maxFileCount': limit or 10000
'maxFileCount': limit or 10000,
'prefix': prefix,
'delimiter': delimiter
}
while new_files_to_retrieve:
response = self.connector.make_request(path=path, method='post', params=params)
Expand Down

0 comments on commit 9fab52a

Please sign in to comment.