Skip to content

Commit 9b95f3b

Browse files
committed
Better glob mapping.
1 parent 53d4ee6 commit 9b95f3b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

test/test_client_util.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ def tearDown(self):
2020

2121
def test_expand_globs(self):
2222
"""Asserts that wes_client.expand_globs() sees the same files in the cwd as 'ls'."""
23-
files = subprocess.check_output(['ls', '-1', '.']).decode('utf-8').split('\n')
23+
files = subprocess.check_output(['ls', '-1', '.'])
24+
25+
# python 2/3 bytestring/utf-8 compatibility
26+
if isinstance(files, str):
27+
files = files.split('\n')
28+
else:
29+
files = files.decode('utf-8').split('\n')
30+
2431
if '' in files:
2532
files.remove('')
33+
files = ['file://' + os.path.abspath(f) for f in files]
2634
glob_files = expand_globs('*')
27-
assert set(files) == glob_files
35+
assert set(files) == glob_files, '\n' + str(set(files)) + '\n' + str(glob_files)
2836

2937

3038
if __name__ == '__main__':

wes_client/util.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ def fixpaths(d):
9494
def expand_globs(attachments):
9595
expanded_list = []
9696
for filepath in attachments:
97-
expanded_list += glob.glob(filepath)
97+
if 'file://' in filepath:
98+
for f in glob.glob(filepath[7:]):
99+
expanded_list += ['file://' + os.path.abspath(f)]
100+
elif ':' not in filepath:
101+
for f in glob.glob(filepath):
102+
expanded_list += ['file://' + os.path.abspath(f)]
103+
else:
104+
expanded_list += [filepath]
98105
return set(expanded_list)
99106

100107

0 commit comments

Comments
 (0)