Mercurial > python-hglib
changeset 72:15485fa4b35e
util: introduce popen
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Mon, 26 Sep 2011 22:37:44 +0300 |
parents | 20ffb6486412 |
children | 77ae99e032f6 |
files | hglib/__init__.py hglib/client.py hglib/util.py |
diffstat | 3 files changed, 15 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/hglib/__init__.py Mon Sep 26 22:25:36 2011 +0300 +++ b/hglib/__init__.py Mon Sep 26 22:37:44 2011 +0300 @@ -14,9 +14,7 @@ insecure=insecure) args.insert(0, HGPATH) - proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - close_fds=util.closefds) - + proc = util.popen(args) out, err = proc.communicate() if proc.returncode: raise error.CommandError(args, proc.returncode, out, err)
--- a/hglib/client.py Mon Sep 26 22:25:36 2011 +0300 +++ b/hglib/client.py Mon Sep 26 22:37:44 2011 +0300 @@ -19,14 +19,11 @@ args += ['-R', path] if configs: args += ['--config'] + configs - env = dict(os.environ) + env = {} if encoding: env['HGENCODING'] = encoding - self.server = subprocess.Popen(args, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, env=env, - close_fds=util.closefds) - + self.server = util.popen(args, env) self._readhello() self._version = None
--- a/hglib/util.py Mon Sep 26 22:25:36 2011 +0300 +++ b/hglib/util.py Mon Sep 26 22:37:44 2011 +0300 @@ -1,6 +1,4 @@ -import itertools, cStringIO, error, os - -closefds = os.name == 'posix' +import itertools, cStringIO, error, os, subprocess def grouper(n, iterable): ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] ''' @@ -132,3 +130,14 @@ def __nonzero__(self): """ Returns True if the return code was 0, False otherwise """ return self.ret == 0 + +close_fds = os.name == 'posix' + +def popen(args, env={}): + environ = None + if env: + environ = dict(os.environ) + environ.update(env) + + return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + close_fds=close_fds, env=environ)