Skip to content
Snippets Groups Projects
Commit fe2cd684 authored by John Chilton's avatar John Chilton
Browse files

ActionMapperRefactor: path -> source dict.

parent 5d301909
No related branches found
No related tags found
No related merge requests found
...@@ -104,46 +104,46 @@ class FileActionMapper(object): ...@@ -104,46 +104,46 @@ class FileActionMapper(object):
... return mapper ... return mapper
>>> mapper = mapper_for(default_action='none', config_contents=json_string) >>> mapper = mapper_for(default_action='none', config_contents=json_string)
>>> # Test first config line above, implicit path prefix mapper >>> # Test first config line above, implicit path prefix mapper
>>> action = mapper.action('/opt/galaxy/tools/filters/catWrapper.py', 'input') >>> action = mapper.action({'path': '/opt/galaxy/tools/filters/catWrapper.py'}, 'input')
>>> action.action_type == u'none' >>> action.action_type == u'none'
True True
>>> action.staging_needed >>> action.staging_needed
False False
>>> # Test another (2nd) mapper, this one with a different action >>> # Test another (2nd) mapper, this one with a different action
>>> action = mapper.action('/galaxy/data/files/000/dataset_1.dat', 'input') >>> action = mapper.action({'path': '/galaxy/data/files/000/dataset_1.dat'}, 'input')
>>> action.action_type == u'transfer' >>> action.action_type == u'transfer'
True True
>>> action.staging_needed >>> action.staging_needed
True True
>>> # Always at least copy work_dir outputs. >>> # Always at least copy work_dir outputs.
>>> action = mapper.action('/opt/galaxy/database/working_directory/45.sh', 'workdir') >>> action = mapper.action({'path': '/opt/galaxy/database/working_directory/45.sh'}, 'workdir')
>>> action.action_type == u'copy' >>> action.action_type == u'copy'
True True
>>> action.staging_needed >>> action.staging_needed
True True
>>> # Test glob mapper (matching test) >>> # Test glob mapper (matching test)
>>> mapper.action('/cool/bamfiles/projectABC/study1/patient3.bam', 'input').action_type == u'copy' >>> mapper.action({'path': '/cool/bamfiles/projectABC/study1/patient3.bam'}, 'input').action_type == u'copy'
True True
>>> # Test glob mapper (non-matching test) >>> # Test glob mapper (non-matching test)
>>> mapper.action('/cool/bamfiles/projectABC/study1/patient3.bam.bai', 'input').action_type == u'none' >>> mapper.action({'path': '/cool/bamfiles/projectABC/study1/patient3.bam.bai'}, 'input').action_type == u'none'
True True
>>> # Regex mapper test. >>> # Regex mapper test.
>>> mapper.action('/old/galaxy/data/dataset_10245.dat', 'input').action_type == u'copy' >>> mapper.action({'path': '/old/galaxy/data/dataset_10245.dat'}, 'input').action_type == u'copy'
True True
>>> # Doesn't map unstructured paths by default >>> # Doesn't map unstructured paths by default
>>> mapper.action('/old/galaxy/data/dataset_10245.dat', 'unstructured').action_type == u'none' >>> mapper.action({'path': '/old/galaxy/data/dataset_10245.dat'}, 'unstructured').action_type == u'none'
True True
>>> input_only_mapper = mapper_for(default_action="none", config_contents=r'''{"paths": [ \ >>> input_only_mapper = mapper_for(default_action="none", config_contents=r'''{"paths": [ \
{"path": "/", "action": "transfer", "path_types": "input"} \ {"path": "/", "action": "transfer", "path_types": "input"} \
] }''') ] }''')
>>> input_only_mapper.action('/dataset_1.dat', 'input').action_type == u'transfer' >>> input_only_mapper.action({'path': '/dataset_1.dat'}, 'input').action_type == u'transfer'
True True
>>> input_only_mapper.action('/dataset_1.dat', 'output').action_type == u'none' >>> input_only_mapper.action({'path': '/dataset_1.dat'}, 'output').action_type == u'none'
True True
>>> unstructured_mapper = mapper_for(default_action="none", config_contents=r'''{"paths": [ \ >>> unstructured_mapper = mapper_for(default_action="none", config_contents=r'''{"paths": [ \
{"path": "/", "action": "transfer", "path_types": "*any*"} \ {"path": "/", "action": "transfer", "path_types": "*any*"} \
] }''') ] }''')
>>> unstructured_mapper.action('/old/galaxy/data/dataset_10245.dat', 'unstructured').action_type == u'transfer' >>> unstructured_mapper.action({'path': '/old/galaxy/data/dataset_10245.dat'}, 'unstructured').action_type == u'transfer'
True True
""" """
...@@ -161,7 +161,8 @@ class FileActionMapper(object): ...@@ -161,7 +161,8 @@ class FileActionMapper(object):
self.mappers = mappers_from_dicts(config.get("paths", [])) self.mappers = mappers_from_dicts(config.get("paths", []))
self.files_endpoint = config.get("files_endpoint", None) self.files_endpoint = config.get("files_endpoint", None)
def action(self, path, type, mapper=None): def action(self, source, type, mapper=None):
path = source["path"]
mapper = self.__find_mapper(path, type, mapper) mapper = self.__find_mapper(path, type, mapper)
action_class = self.__action_class(path, type, mapper) action_class = self.__action_class(path, type, mapper)
file_lister = DEFAULT_FILE_LISTER file_lister = DEFAULT_FILE_LISTER
......
...@@ -60,7 +60,7 @@ class PathMapper(object): ...@@ -60,7 +60,7 @@ class PathMapper(object):
def check_for_arbitrary_rewrite(self, local_path): def check_for_arbitrary_rewrite(self, local_path):
path = str(local_path) # Use false_path if needed. path = str(local_path) # Use false_path if needed.
action = self.action_mapper.action(path, path_type.UNSTRUCTURED) action = self.action_mapper.action({"path": path}, path_type.UNSTRUCTURED)
if not action.staging_needed: if not action.staging_needed:
return action.path_rewrite(self.path_helper), [] return action.path_rewrite(self.path_helper), []
unique_names = action.unstructured_map() unique_names = action.unstructured_map()
...@@ -72,7 +72,7 @@ class PathMapper(object): ...@@ -72,7 +72,7 @@ class PathMapper(object):
""" Return remote path of this file (if staging is required) else None. """ Return remote path of this file (if staging is required) else None.
""" """
path = str(dataset_path) # Use false_path if needed. path = str(dataset_path) # Use false_path if needed.
action = self.action_mapper.action(path, dataset_path_type) action = self.action_mapper.action({"path": path}, dataset_path_type)
if action.staging_needed: if action.staging_needed:
if name is None: if name is None:
name = os.path.basename(path) name = os.path.basename(path)
......
...@@ -135,7 +135,7 @@ class ResultsCollector(object): ...@@ -135,7 +135,7 @@ class ResultsCollector(object):
# path. # path.
collected = False collected = False
with self.exception_tracker(): with self.exception_tracker():
action = self.action_mapper.action(path, output_type) action = self.action_mapper.action({"path": path}, output_type)
if self._collect_output(output_type, action, name): if self._collect_output(output_type, action, name):
collected = True collected = True
......
...@@ -197,7 +197,7 @@ class FileStager(object): ...@@ -197,7 +197,7 @@ class FileStager(object):
if path not in referenced_arbitrary_path_mappers: if path not in referenced_arbitrary_path_mappers:
referenced_arbitrary_path_mappers[path] = mapper referenced_arbitrary_path_mappers[path] = mapper
for path, mapper in referenced_arbitrary_path_mappers.items(): for path, mapper in referenced_arbitrary_path_mappers.items():
action = self.action_mapper.action(path, path_type.UNSTRUCTURED, mapper) action = self.action_mapper.action({"path": path}, path_type.UNSTRUCTURED, mapper)
unstructured_map = action.unstructured_map(self.path_helper) unstructured_map = action.unstructured_map(self.path_helper)
self.arbitrary_files.update(unstructured_map) self.arbitrary_files.update(unstructured_map)
...@@ -501,7 +501,7 @@ class TransferTracker(object): ...@@ -501,7 +501,7 @@ class TransferTracker(object):
self.job_inputs.rewrite_paths(local_path, remote_path) self.job_inputs.rewrite_paths(local_path, remote_path)
def __action(self, path, type): def __action(self, path, type):
return self.action_mapper.action(path, type) return self.action_mapper.action({"path": path}, type)
def _read(path): def _read(path):
......
...@@ -9,7 +9,7 @@ def test_endpoint_validation(): ...@@ -9,7 +9,7 @@ def test_endpoint_validation():
mapper = FileActionMapper(client) mapper = FileActionMapper(client)
exception_found = False exception_found = False
try: try:
mapper.action('/opt/galaxy/tools/filters/catWrapper.py', 'input') mapper.action({'path': '/opt/galaxy/tools/filters/catWrapper.py'}, 'input')
except Exception as e: except Exception as e:
exception_found = True exception_found = True
assert "files_endpoint" in str(e) assert "files_endpoint" in str(e)
...@@ -21,7 +21,7 @@ def test_ssh_key_validation(): ...@@ -21,7 +21,7 @@ def test_ssh_key_validation():
mapper = FileActionMapper(client) mapper = FileActionMapper(client)
exception_found = False exception_found = False
try: try:
mapper.action('/opt/galaxy/tools/filters/catWrapper.py', 'input') mapper.action({'path': '/opt/galaxy/tools/filters/catWrapper.py'}, 'input')
except Exception as e: except Exception as e:
exception_found = True exception_found = True
assert "ssh_key" in str(e) assert "ssh_key" in str(e)
...@@ -31,7 +31,7 @@ def test_ssh_key_validation(): ...@@ -31,7 +31,7 @@ def test_ssh_key_validation():
def test_ssh_key_defaults(): def test_ssh_key_defaults():
client = _client("remote_rsync_transfer") client = _client("remote_rsync_transfer")
mapper = FileActionMapper(client) mapper = FileActionMapper(client)
action = mapper.action('/opt/galaxy/tools/filters/catWrapper.py', 'input') action = mapper.action({'path': '/opt/galaxy/tools/filters/catWrapper.py'}, 'input')
action.to_dict() action.to_dict()
......
...@@ -75,7 +75,7 @@ class TestActionMapper(object): ...@@ -75,7 +75,7 @@ class TestActionMapper(object):
if not staging_needed: if not staging_needed:
self._action.path_rewrite = lambda path: None self._action.path_rewrite = lambda path: None
def action(self, path, type): def action(self, source, type):
assert self.expected_path == path assert self.expected_path == source["path"]
assert self.expected_type == type assert self.expected_type == type
return self._action return self._action
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment