diff hglib/util.py @ 72:15485fa4b35e

util: introduce popen
author Idan Kamara <idankk86@gmail.com>
date Mon, 26 Sep 2011 22:37:44 +0300
parents d1f57f162274
children 77ae99e032f6
line wrap: on
line diff
--- 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)