# HG changeset patch # User Idan Kamara # Date 1317065864 -10800 # Node ID 15485fa4b35e4fcad4ca4b63ddaa0649e3006003 # Parent 20ffb6486412791e56577e29dc3a95e8fc8a781f util: introduce popen diff -r 20ffb6486412 -r 15485fa4b35e hglib/__init__.py --- 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) diff -r 20ffb6486412 -r 15485fa4b35e hglib/client.py --- 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 diff -r 20ffb6486412 -r 15485fa4b35e hglib/util.py --- 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)