diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-11-21 12:49:14 +0000 |
---|---|---|
committer | Richard Ipsum <richardipsum@fastmail.co.uk> | 2014-11-27 15:04:59 +0000 |
commit | 3ebca1e99b7de4556ea7bc59c508d5205870486f (patch) | |
tree | 134e5a30a7aaccb7418cd532feec26883e06570e | |
parent | 9ddbdb0c24da2261641f1fefde08eac5f4389779 (diff) | |
download | import-3ebca1e99b7de4556ea7bc59c508d5205870486f.tar.gz |
Put version control output into log
-rwxr-xr-x | exts/pip.to_lorry | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/exts/pip.to_lorry b/exts/pip.to_lorry index 8a36ac8..be207f7 100755 --- a/exts/pip.to_lorry +++ b/exts/pip.to_lorry @@ -27,6 +27,7 @@ import shutil import tempfile import xmlrpclib import logging +import select import pkg_resources @@ -49,9 +50,31 @@ def find_repo_type(url): tempdir = tempfile.mkdtemp() p = subprocess.Popen([vcs, vcs_command, url], stdout=subprocess.PIPE, - stderr=subprocess.PIPE, cwd=tempdir) + stderr=subprocess.PIPE, stdin=subprocess.PIPE, + cwd=tempdir) + + # We close stdin on parent side to prevent the child from blocking + # if it reads on stdin + p.stdin.close() + + poll = select.poll() + + fdmap = {p.stdout.fileno(): p.stdout, p.stderr.fileno(): p.stderr} + poll.register(p.stdout) + poll.register(p.stderr) + + # Multiplex stdout and stderr + while fdmap != {}: + fds = poll.poll() + + for (fd, _) in fds: + line = fdmap[fd].readline().rstrip() + if line == '': + poll.unregister(fd) + del fdmap[fd] + else: + logging.debug('%s' % line) - _, _ = p.communicate() shutil.rmtree(tempdir) if p.returncode == 0: |