Commit 613a30fe authored by James Ennis's avatar James Ennis
Browse files

_artifactelement.py: New module containing ArtifactElement class

The ArtifactElement class is to be used when we want to pass a
dummy artifact to our scheduler, typically this will be when we
are directly working with artifact refs.
parent ff46ae41
Loading
Loading
Loading
Loading
+46 −0
Original line number Original line Diff line number Diff line
#
#  Copyright (C) 2019 Bloomberg Finance LP
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
#
#  Authors:
#        James Ennis <james.ennis@codethink.co.uk>
from ._exceptions import ArtifactElementError


# ArtifactElement()
#
# Object to be used for directly processing an artifact
#
# Args:
#    context (Context): The Context object
#    ref (str): The artifact ref
#
class ArtifactElement():
    def __init__(self, context, ref):
        try:
            project_name, element, key = ref.split('/', 2)
        except ValueError:
            raise ArtifactElementError("Artifact: {} is not of the expected format".format(ref))

        self._project_name = project_name
        self._element = element
        self._key = key
        self._context = context

    def get_artifact_name(self):
        return '{0}/{1}/{2}'.format(self._project_name, self._element, self._key)

    def _cached(self):
        return self._context.artifactcache.contains_ref(self.get_artifact_name())