Skip to content

Commit 25ea8cf

Browse files
committed
Add glob functionality for attachments.
1 parent 53af8a5 commit 25ea8cf

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

test/test_client_util.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from __future__ import absolute_import
2+
3+
import unittest
4+
import os
5+
import logging
6+
import subprocess
7+
8+
from wes_client.util import expand_globs
9+
10+
logging.basicConfig(level=logging.INFO)
11+
12+
13+
class IntegrationTest(unittest.TestCase):
14+
def setUp(self):
15+
dirname, filename = os.path.split(os.path.abspath(__file__))
16+
self.testdata_dir = dirname + 'data'
17+
18+
def tearDown(self):
19+
unittest.TestCase.tearDown(self)
20+
21+
def test_expand_globs(self):
22+
"""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')
24+
if '' in files:
25+
files.remove('')
26+
glob_files = expand_globs('*')
27+
assert set(files) == glob_files
28+
29+
30+
if __name__ == '__main__':
31+
unittest.main() # run all tests

wes_client/util.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import json
3+
import glob
34
import requests
45
import urllib
56
import logging
@@ -90,6 +91,13 @@ def fixpaths(d):
9091
visit(input_dict, fixpaths)
9192

9293

94+
def expand_globs(attachments):
95+
expanded_list = []
96+
for filepath in attachments:
97+
expanded_list += glob.glob(filepath)
98+
return set(expanded_list)
99+
100+
93101
def wes_reponse(postresult):
94102
if postresult.status_code != 200:
95103
logging.error("%s", json.loads(postresult.text))

wes_client/wes_client_main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import logging
99
import requests
1010
from requests.exceptions import InvalidSchema, MissingSchema
11-
from wes_client.util import modify_jsonyaml_paths, WESClient
11+
from wes_client.util import modify_jsonyaml_paths, expand_globs, WESClient
1212

1313

1414
def main(argv=sys.argv[1:]):
@@ -87,6 +87,7 @@ def main(argv=sys.argv[1:]):
8787
logging.basicConfig(level=logging.INFO)
8888

8989
args.attachments = args.attachments if not args.attachments else args.attachments.split(',')
90+
args.attachments = list(expand_globs(args.attachments))
9091
r = client.run(args.workflow_url, args.job_order, args.attachments)
9192

9293
if args.wait:

0 commit comments

Comments
 (0)