Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Fixed ls with asterisk calls #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion gsutilwrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,20 @@ def ls(pattern: str, dont_recurse: bool = False) -> List[str]: # pylint: disabl
return []

if proc.returncode == 0:
return [line.strip() for line in out.split('\n') if line.strip() != '']
lines = [] # type: List[str]
for line in out.split('\n'):
line = line.strip()

# empty line
if line == '':
continue

# subdirectory matching resolved wildcard *
if line.endswith('/:'):
continue

lines.append(line)
return lines

raise RuntimeError("gsutil failed: command was: {!r}\n, stderr:\n{}".format(" ".join(
[shlex.quote(part) for part in cmd]), err))
Expand Down
18 changes: 18 additions & 0 deletions tests/live_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ def test_long_ls(self) -> None:
if len(gsutilwrap.ls(pattern=base_url)) > 0:
gsutilwrap.remove(pattern=base_url, quiet=True, multithreaded=True, recursive=True)

def test_ls_with_asterisk(self) -> None:
quiet = False

base_url = "{}/{}".format(TEST_GSUTILWRAP_URL_PREFIX, uuid.uuid4())

urls = ['{}/d1/one.txt'.format(base_url), '{}/d2/two.txt'.format(base_url)]
try:
for url in urls:
gsutilwrap.write_text(url=url, text="some dummy content", quiet=quiet)

self.assertEqual(2, len(gsutilwrap.ls(pattern='{}/d*'.format(base_url))))

listed_urls = gsutilwrap.ls(pattern='{}/d*'.format(base_url))
self.assertListEqual(urls, listed_urls)
finally:
if len(gsutilwrap.ls(pattern=base_url)) > 0:
gsutilwrap.remove(pattern=base_url, quiet=True, multithreaded=True, recursive=True)

def test_write_read_text(self) -> None:
quiet = True

Expand Down