summaryrefslogtreecommitdiff
path: root/morphlib/localrepocache.py
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-10-29 17:12:15 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-10-29 17:16:41 +0000
commit426526c692fecd520b1946f362e148d043c61441 (patch)
treeff1069aeea1f03a4cfe8233a6aa2def6c05bc9d2 /morphlib/localrepocache.py
parent4f959335730d37be8d7cd53a2af668d8887e72cc (diff)
downloadmorph-426526c692fecd520b1946f362e148d043c61441.tar.gz
Echo stderr of subcommands that do network IO when --verbose is used
Morph can appear to hang in situations where it is actually waiting on a slow network operation. This change gives users a way to see the output of the subcommands that are doing the network IO (either 'wget', 'git clone' or 'git remote update'). The status information goes onto stderr, because that is where the subcommands write it. Morph tends to put its status output on stdout, but (a) some commands are machine-parsed, such as `serialise-artifact` and (b) it's tricky to get Git to put status output on stdout.
Diffstat (limited to 'morphlib/localrepocache.py')
-rw-r--r--morphlib/localrepocache.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/morphlib/localrepocache.py b/morphlib/localrepocache.py
index 002022b9..92c5e763 100644
--- a/morphlib/localrepocache.py
+++ b/morphlib/localrepocache.py
@@ -20,6 +20,7 @@ import re
import urllib2
import urlparse
import string
+import sys
import tempfile
import cliapp
@@ -102,7 +103,7 @@ class LocalRepoCache(object):
self._tarball_base_url = tarball_base_url
self._cached_repo_objects = {}
- def _git(self, args, cwd=None): # pragma: no cover
+ def _git(self, args, **kwargs): # pragma: no cover
'''Execute git command.
This is a method of its own so that unit tests can easily override
@@ -110,7 +111,7 @@ class LocalRepoCache(object):
'''
- morphlib.git.gitcmd(self._app.runcmd, *args, cwd=cwd)
+ morphlib.git.gitcmd(self._app.runcmd, *args, **kwargs)
def _fetch(self, url, path): # pragma: no cover
'''Fetch contents of url into a file.
@@ -120,8 +121,20 @@ class LocalRepoCache(object):
'''
self._app.status(msg="Trying to fetch %(tarball)s to seed the cache",
tarball=url, chatty=True)
- self._app.runcmd(['wget', '-q', '-O-', url],
- ['tar', 'xf', '-'], cwd=path)
+
+ if self._app.settings['verbose']:
+ verbosity_flags = []
+ kwargs = dict(stderr=sys.stderr)
+ else:
+ verbosity_flags = ['--quiet']
+ kwargs = dict()
+
+ def wget_command():
+ return ['wget'] + verbosity_flags + ['-O-', url]
+
+ self._app.runcmd(wget_command(),
+ ['tar', 'xf', '-'],
+ cwd=path, **kwargs)
def _mkdtemp(self, dirname): # pragma: no cover
'''Creates a temporary directory.
@@ -196,9 +209,12 @@ class LocalRepoCache(object):
errors.append(error)
self._app.status(
msg='Using git clone.')
+
target = self._mkdtemp(self._cachedir)
+
try:
- self._git(['clone', '--mirror', '-n', repourl, target])
+ self._git(['clone', '--mirror', '-n', repourl, target],
+ echo_stderr=self._app.settings['verbose'])
except cliapp.AppException, e:
errors.append('Unable to clone from %s to %s: %s' %
(repourl, target, e))