-
Notifications
You must be signed in to change notification settings - Fork 9
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 --include
and --exclude
filters to the ls
and rm
commands
#253
Changes from 4 commits
365c7f2
863e0d4
7a3aa9e
daa64f0
19316a8
e0a9644
a3b2d30
b96a0c4
6abde18
e5b72eb
12f889e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ | |
EncryptionSetting, | ||
FileRetentionSetting, | ||
FileVersion, | ||
Filter, | ||
KeepOrDeleteMode, | ||
LegalHold, | ||
LifecycleRule, | ||
|
@@ -2175,6 +2176,8 @@ def _setup_parser(cls, parser): | |
parser.add_argument('--versions', action='store_true') | ||
parser.add_argument('-r', '--recursive', action='store_true') | ||
parser.add_argument('--withWildcard', action='store_true') | ||
parser.add_argument('--include', dest='filters', action='append', type=Filter.include) | ||
parser.add_argument('--exclude', dest='filters', action='append', type=Filter.exclude) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docstring is outdated now. |
||
super()._setup_parser(parser) | ||
|
||
def _print_files(self, args): | ||
|
@@ -2198,6 +2201,7 @@ def _get_ls_generator(self, args): | |
latest_only=not args.versions, | ||
recursive=args.recursive, | ||
with_wildcard=args.withWildcard, | ||
filters=args.filters or (), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use default value in parser.add_argument('--include', dest='filters', action='append', type=Filter.include, default=()) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That doesn't work. With But we can have |
||
) | ||
|
||
def get_b2_uri_from_arg(self, args: argparse.Namespace) -> B2URI: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add `--include` and `--exclude` filters to the `ls` and `rm` commands. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2445,6 +2445,64 @@ def test_ls_b2id(self): | |
''' | ||
self._run_command(['ls', f'b2id://{file_version.id_}'], expected_stdout, '', 0) | ||
|
||
def test_ls_filters(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks filters working on |
||
self._authorize_account() | ||
self._create_my_bucket() | ||
|
||
# Create some files, including files in a folder | ||
bucket = self.b2_api.get_bucket_by_name('my-bucket') | ||
data = UploadSourceBytes(b'test-data') | ||
bucket.upload(data, 'a/test.csv') | ||
bucket.upload(data, 'a/test.tsv') | ||
bucket.upload(data, 'b/b/test.csv') | ||
bucket.upload(data, 'c/test.csv') | ||
bucket.upload(data, 'c/test.tsv') | ||
bucket.upload(data, 'test.csv') | ||
bucket.upload(data, 'test.tsv') | ||
|
||
expected_stdout = ''' | ||
a/ | ||
b/ | ||
c/ | ||
test.csv | ||
''' | ||
self._run_command( | ||
['ls', *self.b2_uri_args('my-bucket'), '--include', '*.csv'], | ||
expected_stdout, | ||
) | ||
self._run_command( | ||
['ls', *self.b2_uri_args('my-bucket'), '--exclude', '*.tsv'], | ||
expected_stdout, | ||
) | ||
|
||
expected_stdout = ''' | ||
a/test.csv | ||
b/b/test.csv | ||
c/test.csv | ||
test.csv | ||
''' | ||
self._run_command( | ||
['ls', *self.b2_uri_args('my-bucket'), '--recursive', '--include', '*.csv'], | ||
expected_stdout, | ||
) | ||
self._run_command( | ||
['ls', *self.b2_uri_args('my-bucket'), '--recursive', '--exclude', '*.tsv'], | ||
expected_stdout, | ||
) | ||
|
||
expected_stdout = ''' | ||
b/b/test.csv | ||
c/test.csv | ||
test.csv | ||
''' | ||
self._run_command( | ||
[ | ||
'ls', *self.b2_uri_args('my-bucket'), '--recursive', '--exclude', '*', '--include', | ||
'*.csv', '--exclude', 'a/*' | ||
], | ||
expected_stdout, | ||
) | ||
|
||
|
||
class TestConsoleToolWithV1(BaseConsoleToolTest): | ||
"""These tests use v1 interface to perform various setups before running CLI commands""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type hint?