From cfa6237e902d911303ca4e5da19a6dfdb362eccb Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Wed, 1 Apr 2015 15:26:16 +0000 Subject: 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. --- morphlib/buildcommand.py | 3 ++- morphlib/ostreeartifactcache.py | 27 +++++++++++++++++++-------- morphlib/util.py | 6 +++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py index 68f53906..6f9457fe 100644 --- a/morphlib/buildcommand.py +++ b/morphlib/buildcommand.py @@ -74,7 +74,8 @@ class BuildCommand(object): This includes creating the directories on disk if they are missing. ''' - return morphlib.util.new_artifact_caches(self.app.settings) + return morphlib.util.new_artifact_caches( + self.app.settings, status_cb=self.app.status) def new_repo_caches(self): return morphlib.util.new_repo_caches(self.app) 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: diff --git a/morphlib/util.py b/morphlib/util.py index e5cdce7d..91880988 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -120,7 +120,7 @@ def get_git_resolve_cache_server(settings): # pragma: no cover return None -def new_artifact_caches(settings): # pragma: no cover +def new_artifact_caches(settings, status_cb=None): # pragma: no cover '''Create new objects for local and remote artifact caches. This includes creating the directories on disk, if missing. @@ -133,8 +133,8 @@ def new_artifact_caches(settings): # pragma: no cover os.mkdir(artifact_cachedir) mode = settings['ostree-repo-mode'] - lac = morphlib.ostreeartifactcache.OSTreeArtifactCache(artifact_cachedir, - mode=mode) + lac = morphlib.ostreeartifactcache.OSTreeArtifactCache( + artifact_cachedir, mode=mode, status_cb=status_cb) rac_url = get_artifact_cache_server(settings) rac = None -- cgit v1.2.1