summaryrefslogtreecommitdiff
path: root/morphlib/localartifactcache.py
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-04-11 16:58:28 +0100
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-04-11 17:06:48 +0100
commitd7a7fc31242ba4ff88252bb0d6eca62ca327f8f0 (patch)
tree46268a3041dc2af15b9e53a5be9cd3105472686f /morphlib/localartifactcache.py
parentffc01a3572a8f74d2d6664e6e4d4d9c514a14b97 (diff)
downloadmorph-d7a7fc31242ba4ff88252bb0d6eca62ca327f8f0.tar.gz
Add Artifact and LocalArtifactCache classes.
An Artifact represents a thing that morph has built. An example would be eglibc-runtime which morph may have built from the eglibc chunk morphology. Another example would be a ready-to-use system image. The LocalArtifactCache allows to store build artifacts in a local directory. Users of this class can ask it whether it has a certain artifact. They can also optain an I/O handle to read the artifact data from. In addition to just abstracting the way artifacts are stored, LocalArtifactCache also allows to store and retrieve metadata for (a) artifacts and (b) sources (the latter requires a cache key to be provided to the LocalArtifactCache).
Diffstat (limited to 'morphlib/localartifactcache.py')
-rw-r--r--morphlib/localartifactcache.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/morphlib/localartifactcache.py b/morphlib/localartifactcache.py
new file mode 100644
index 00000000..52b5772c
--- /dev/null
+++ b/morphlib/localartifactcache.py
@@ -0,0 +1,79 @@
+# Copyright (C) 2012 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+import os
+
+import morphlib
+
+
+class LocalArtifactCache(object):
+
+ def __init__(self, cachedir):
+ self.cachedir = cachedir
+
+ def put(self, artifact):
+ filename = self._artifact_filename(artifact)
+ return morphlib.savefile.SaveFile(filename, mode='w')
+
+ def put_artifact_metadata(self, artifact, name):
+ filename = self._artifact_metadata_filename(artifact, name)
+ return morphlib.savefile.SaveFile(filename, mode='w')
+
+ def put_source_metadata(self, source, cachekey, name):
+ filename = self._source_metadata_filename(source, cachekey, name)
+ return morphlib.savefile.SaveFile(filename, mode='w')
+
+ def has(self, artifact):
+ filename = self._artifact_filename(artifact)
+ return os.path.exists(filename)
+
+ def has_artifact_metadata(self, artifact, name):
+ filename = self._artifact_metadata_filename(artifact, name)
+ return os.path.exists(filename)
+
+ def has_source_metadata(self, source, cachekey, name):
+ filename = self._source_metadata_filename(source, cachekey, name)
+ return os.path.exists(filename)
+
+ def get(self, artifact):
+ filename = self._artifact_filename(artifact)
+ return open(filename)
+
+ def get_artifact_metadata(self, artifact, name):
+ filename = self._artifact_metadata_filename(artifact, name)
+ return open(filename)
+
+ def get_source_metadata(self, source, cachekey, name):
+ filename = self._source_metadata_filename(source, cachekey, name)
+ return open(filename)
+
+ def _artifact_basename(self, artifact):
+ return '%s.%s.%s' % (artifact.cache_key,
+ artifact.source.morphology['kind'],
+ artifact.name)
+
+ def _artifact_filename(self, artifact):
+ basename = self._artifact_basename(artifact)
+ return os.path.join(self.cachedir, basename)
+
+ def _artifact_metadata_filename(self, artifact, name):
+ basename = '%s.%s' % (self._artifact_basename(artifact), name)
+ return os.path.join(self.cachedir, basename)
+
+
+ def _source_metadata_filename(self, source, cachekey, name):
+ basename = '%s.%s' % (cachekey, name)
+ return os.path.join(self.cachedir, basename)