diff options
Diffstat (limited to 'morphlib/ostreeartifactcache.py')
-rw-r--r-- | morphlib/ostreeartifactcache.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/morphlib/ostreeartifactcache.py b/morphlib/ostreeartifactcache.py index 816b3cec..64c6e8f8 100644 --- a/morphlib/ostreeartifactcache.py +++ b/morphlib/ostreeartifactcache.py @@ -30,16 +30,28 @@ from morphlib.artifactcachereference import ArtifactCacheReference class OSTreeArtifactCache(object): """Class to provide the artifact cache API using an OSTree repo.""" - def __init__(self, cachedir, mode): + def __init__(self, cachedir, mode='bare', status_cb=None): repo_dir = os.path.join(cachedir, 'repo') self.repo = morphlib.ostree.OSTreeRepo(repo_dir, mode=mode) self.cachedir = cachedir + self.status_cb = status_cb + + def status(self, *args, **kwargs): + if self.status_cb is not None: + self.status_cb(*args, **kwargs) def _get_file_from_remote(self, artifact, remote, metadata_name=None): if metadata_name: handle = remote.get_artifact_metadata(artifact, metadata_name) + self.status( + msg='Downloading %(name)s %(metadata_name)s as a file.', + chatty=True, name=artifact.name, metadata_name=metadata_name) else: handle = remote.get(artifact) + self.status( + msg='Downloading %(name)s as a tarball.', chatty=True, + name=artifact.name) + fd, path = tempfile.mkstemp() with open(path, 'w+') as temp: shutil.copyfileobj(handle, temp) @@ -61,8 +73,9 @@ class OSTreeArtifactCache(object): ref = self._get_artifact_cache_name(artifact) subject = artifact.name try: - logging.debug('Committing %s to artifact cache at %s.' % - (subject, ref)) + self.status( + msg='Committing %(subject)s to artifact cache at %(ref)s.', + chatty=True, subject=subject, ref=ref) self.repo.commit(subject, directory, ref) except GLib.GError as e: logging.debug('OSTree raised an exception: %s' % e) @@ -82,8 +95,6 @@ class OSTreeArtifactCache(object): def copy_from_remote(self, artifact, remote): """Get 'artifact' from remote artifact cache and store it locally.""" if remote.method == 'tarball': - logging.debug('Downloading artifact tarball for %s.' % - artifact.name) location = self._get_file_from_remote(artifact, remote) try: tempdir = tempfile.mkdtemp() @@ -100,8 +111,8 @@ class OSTreeArtifactCache(object): self.put_non_ostree_artifact(artifact, location) elif remote.method == 'ostree': - logging.debug('Pulling artifact for %s from remote.' % - artifact.basename()) + self.status(msg='Pulling artifact for %(name)s from remote.', + chatty=True, name=artifact.basename()) try: ref = self._get_artifact_cache_name(artifact) except Exception: @@ -174,7 +185,7 @@ class OSTreeArtifactCache(object): def has(self, artifact): cachekey, kind, name = artifact.basename().split('.', 2) - logging.debug('OSTreeArtifactCache: got %s, %s, %s' % + logging.debug('OSTreeArtifactCache: checking for %s, %s, %s' % (cachekey, kind, name)) sha = self.repo.resolve_rev(self._get_artifact_cache_name(artifact)) if sha: |