diff options
author | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2015-04-01 15:26:16 +0000 |
---|---|---|
committer | Adam Coldrick <adam.coldrick@codethink.co.uk> | 2015-04-10 13:52:27 +0000 |
commit | cfa6237e902d911303ca4e5da19a6dfdb362eccb (patch) | |
tree | b2af5b7a07c1e8ae365f23a79ced93e6c190066a /morphlib/ostreeartifactcache.py | |
parent | 5ae139d6427b2f114518d7fd1b8d8d29b46b7a81 (diff) | |
download | morph-cfa6237e902d911303ca4e5da19a6dfdb362eccb.tar.gz |
Output more information in --verbose mode
Previously this info was just in the log file, but I think it should be
on the console too.
Also, the 'Downloading xx as tarball' message would appear even when
there was no tarball to download, which was a bit weird.
Output with `morph build --verbose` now looks like this:
2015-03-25 15:00:53 [Build 8/226] [stage2-gcc] Fetching to local cache: artifact stage2-gcc-locale
2015-03-25 15:00:53 [Build 8/226] [stage2-gcc] Downloading stage2-gcc-locale as a tarball.
2015-03-25 15:00:53 [Build 8/226] [stage2-gcc] Committing stage2-gcc-locale to artifact cache at 14ae4efeeaeea43f8a4f9198172ca9961f343cde663ec98e7061259d6542c35a-locale.
2015-03-25 15:00:53 [Build 8/226] [stage2-gcc] Fetching to local cache: artifact stage2-gcc-libs
2015-03-25 15:00:53 [Build 8/226] [stage2-gcc] Downloading stage2-gcc-libs as a tarball.
2015-03-25 15:00:53 [Build 8/226] [stage2-gcc] Committing stage2-gcc-libs to artifact cache at 14ae4efeeaeea43f8a4f9198172ca9961f343cde663ec98e7061259d6542c35a-libs.
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: |