diff --git a/nodeodm/api_client.py b/nodeodm/api_client.py index b46ce456..fbb08be4 100644 --- a/nodeodm/api_client.py +++ b/nodeodm/api_client.py @@ -40,6 +40,13 @@ class ApiClient: def task_restart(self, uuid): return requests.post(self.url('/task/restart'), data={'uuid': uuid}).json() + def task_download(self, uuid, asset): + res = requests.get(self.url('/task/{}/download/{}').format(uuid, asset)) + if "Content-Type" in res.headers and "application/json" in res.headers['Content-Type']: + return res.json() + else: + return res.content + def new_task(self, images, name=None, options=[]): """ Starts processing of a new task diff --git a/nodeodm/external/node-OpenDroneMap b/nodeodm/external/node-OpenDroneMap index 03894086..c056dee4 160000 --- a/nodeodm/external/node-OpenDroneMap +++ b/nodeodm/external/node-OpenDroneMap @@ -1 +1 @@ -Subproject commit 038940860d043439b184c4fbd990f8a71b60c324 +Subproject commit c056dee4857066e4c3b65a9a3cbf1b5aa1282ac9 diff --git a/nodeodm/models.py b/nodeodm/models.py index c543ee80..1c3bc568 100644 --- a/nodeodm/models.py +++ b/nodeodm/models.py @@ -115,6 +115,17 @@ class ProcessingNode(models.Model): api_client = self.api_client() return self.handle_generic_post_response(api_client.task_remove(uuid)) + def download_task_asset(self, uuid, asset): + """ + Downloads a task asset + """ + api_client = self.api_client() + res = api_client.task_download(uuid, asset) + if isinstance(res, dict) and 'error' in res: + raise ProcessingException(res['error']) + else: + return res + def restart_task(self, uuid): """ Restarts a task that was previously canceled or that had failed to process diff --git a/nodeodm/tests.py b/nodeodm/tests.py index f838b5c4..af38c279 100644 --- a/nodeodm/tests.py +++ b/nodeodm/tests.py @@ -6,6 +6,8 @@ from .models import ProcessingNode from .api_client import ApiClient from requests.exceptions import ConnectionError from .exceptions import ProcessingException +import status_codes + current_dir = path.dirname(path.realpath(__file__)) @@ -91,6 +93,25 @@ class TestClientApi(TestCase): self.assertTrue(isinstance(task_info['dateCreated'], (int, long))) self.assertTrue(isinstance(task_info['uuid'], (str, unicode))) + # Can download assets? + # Here we are waiting for the task to be completed + retries = 0 + while True: + try: + task_info = api.task_info(uuid) + if task_info['status']['code'] == status_codes.COMPLETED: + asset = api.task_download(uuid, "all.zip") + self.assertTrue(isinstance(asset, (str, unicode))) # Binary content, really + break + except ProcessingException: + pass + + time.sleep(0.5) + retries += 1 + if retries >= 10: + self.assertTrue(False, "Could not download assets") + break + # task_output self.assertTrue(isinstance(api.task_output(uuid, 0), list)) self.assertTrue(isinstance(online_node.get_task_console_output(uuid, 0), (str, unicode)))