diff --git a/doc/source/api/output.rst b/doc/source/api/output.rst index 34c8b1ff..63eec3bc 100644 --- a/doc/source/api/output.rst +++ b/doc/source/api/output.rst @@ -315,9 +315,12 @@ methods .. method:: RunDatabaseOutput.get_artifact_path(name) - Returns a `StringIO` object containing the contents of the artifact - specified by ``name``. This will only look at the run artifacts; this will - not search the artifacts of the individual jobs. + If the artifcat is a file this method returns a `StringIO` object containing + the contents of the artifact specified by ``name``. If the aritifcat is a + directory, the method returns a path to a locally extracted version of the + directory which is left to the user to remove after use. This will only look + at the run artifacts; this will not search the artifacts of the individual + jobs. :param name: The name of the artifact who's path to retrieve. :return: A `StringIO` object with the contents of the artifact @@ -452,8 +455,11 @@ methods .. method:: JobDatabaseOutput.get_artifact_path(name) - Returns a ``StringIO`` object containing the contents of the artifact - specified by ``name`` associated with this job. + If the artifcat is a file this method returns a `StringIO` object containing + the contents of the artifact specified by ``name`` associated with this job. + If the aritifcat is a directory, the method returns a path to a locally + extracted version of the directory which is left to the user to remove after + use. :param name: The name of the artifact who's path to retrieve. :return: A `StringIO` object with the contents of the artifact diff --git a/wa/framework/output.py b/wa/framework/output.py index 09287283..e927f959 100644 --- a/wa/framework/output.py +++ b/wa/framework/output.py @@ -23,6 +23,8 @@ except ImportError: import logging import os import shutil +import tarfile +import tempfile from collections import OrderedDict, defaultdict from copy import copy, deepcopy from datetime import datetime @@ -822,6 +824,19 @@ class DatabaseOutput(Output): def get_artifact_path(self, name): artifact = self.get_artifact(name) + if artifact.is_dir: + return self._read_dir_artifact(artifact) + else: + return self._read_file_artifact(artifact) + + def _read_dir_artifact(self, artifact): + artifact_path = tempfile.mkdtemp(prefix='wa_') + with tarfile.open(fileobj=self.conn.lobject(int(artifact.path), mode='b'), mode='r|gz') as tar_file: + tar_file.extractall(artifact_path) + self.conn.commit() + return artifact_path + + def _read_file_artifact(self, artifact): artifact = StringIO(self.conn.lobject(int(artifact.path)).read()) self.conn.commit() return artifact @@ -910,7 +925,7 @@ class DatabaseOutput(Output): def _get_artifacts(self): columns = ['artifacts.name', 'artifacts.description', 'artifacts.kind', - ('largeobjects.lo_oid', 'path'), 'artifacts.oid', + ('largeobjects.lo_oid', 'path'), 'artifacts.oid', 'artifacts.is_dir', 'artifacts._pod_version', 'artifacts._pod_serialization_version'] tables = ['largeobjects', 'artifacts'] joins = [('classifiers', 'classifiers.artifact_oid = artifacts.oid')]