Commit 0e183bb3 authored by Mike Hommey's avatar Mike Hommey
Browse files

Bug 1257516 - Allow the log_handle given to the virtualenv manager to be a file-like object. r=ted

subprocess functions doesn't directly take file-like objects, so add a
minimalistic wrapper to do the right thing instead of subprocess.call
when given a file-like object.
parent ba80937b
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -162,6 +162,19 @@ class VirtualenvManager(object):
            return self.virtualenv_root
        return self.build(python)

    def _log_process_output(self, *args, **kwargs):
        if hasattr(self.log_handle, 'fileno'):
            return subprocess.call(*args, stdout=self.log_handle,
                                   stderr=subprocess.STDOUT, **kwargs)

        proc = subprocess.Popen(*args, stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT, **kwargs)

        for line in proc.stdout:
            self.log_handle.write(line)

        return proc.wait()

    def create(self, python=sys.executable):
        """Create a new, empty virtualenv.

@@ -180,8 +193,7 @@ class VirtualenvManager(object):
            '--no-download',
            self.virtualenv_root]

        result = subprocess.call(args, stdout=self.log_handle,
            stderr=subprocess.STDOUT, env=env)
        result = self._log_process_output(args, env=env)

        if result:
            raise Exception(
@@ -429,8 +441,7 @@ class VirtualenvManager(object):
        args = [self.python_path, __file__, 'populate', self.topsrcdir,
            self.topobjdir, self.virtualenv_root, self.manifest_path]

        result = subprocess.call(args, stdout=self.log_handle,
            stderr=subprocess.STDOUT, cwd=self.topsrcdir)
        result = self._log_process_output(args, cwd=self.topsrcdir)

        if result != 0:
            raise Exception('Error populating virtualenv.')