Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add prefix/delimiter arguments to file listing #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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