mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-31 02:01:16 +00:00
fw/DatabaseOutput: Enabled retrieving of directory artifacts
To provide the same user experience of accessing a directory artifact from a standard `wa_output` when attempting to retrieve the path of the artifact extract the stored tar file and extract it to a temporary location on the host returning the path.
This commit is contained in:
parent
e915436661
commit
98b787e326
@ -315,9 +315,12 @@ methods
|
|||||||
|
|
||||||
.. method:: RunDatabaseOutput.get_artifact_path(name)
|
.. method:: RunDatabaseOutput.get_artifact_path(name)
|
||||||
|
|
||||||
Returns a `StringIO` object containing the contents of the artifact
|
If the artifcat is a file this method returns a `StringIO` object containing
|
||||||
specified by ``name``. This will only look at the run artifacts; this will
|
the contents of the artifact specified by ``name``. If the aritifcat is a
|
||||||
not search the artifacts of the individual jobs.
|
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.
|
:param name: The name of the artifact who's path to retrieve.
|
||||||
:return: A `StringIO` object with the contents of the artifact
|
:return: A `StringIO` object with the contents of the artifact
|
||||||
@ -452,8 +455,11 @@ methods
|
|||||||
|
|
||||||
.. method:: JobDatabaseOutput.get_artifact_path(name)
|
.. method:: JobDatabaseOutput.get_artifact_path(name)
|
||||||
|
|
||||||
Returns a ``StringIO`` object containing the contents of the artifact
|
If the artifcat is a file this method returns a `StringIO` object containing
|
||||||
specified by ``name`` associated with this job.
|
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.
|
:param name: The name of the artifact who's path to retrieve.
|
||||||
:return: A `StringIO` object with the contents of the artifact
|
:return: A `StringIO` object with the contents of the artifact
|
||||||
|
@ -23,6 +23,8 @@ except ImportError:
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import tarfile
|
||||||
|
import tempfile
|
||||||
from collections import OrderedDict, defaultdict
|
from collections import OrderedDict, defaultdict
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -822,6 +824,19 @@ class DatabaseOutput(Output):
|
|||||||
|
|
||||||
def get_artifact_path(self, name):
|
def get_artifact_path(self, name):
|
||||||
artifact = self.get_artifact(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())
|
artifact = StringIO(self.conn.lobject(int(artifact.path)).read())
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
return artifact
|
return artifact
|
||||||
@ -910,7 +925,7 @@ class DatabaseOutput(Output):
|
|||||||
|
|
||||||
def _get_artifacts(self):
|
def _get_artifacts(self):
|
||||||
columns = ['artifacts.name', 'artifacts.description', 'artifacts.kind',
|
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']
|
'artifacts._pod_version', 'artifacts._pod_serialization_version']
|
||||||
tables = ['largeobjects', 'artifacts']
|
tables = ['largeobjects', 'artifacts']
|
||||||
joins = [('classifiers', 'classifiers.artifact_oid = artifacts.oid')]
|
joins = [('classifiers', 'classifiers.artifact_oid = artifacts.oid')]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user