comparison 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
comparison
equal deleted inserted replaced
71:20ffb6486412 72:15485fa4b35e
1 import itertools, cStringIO, error, os 1 import itertools, cStringIO, error, os, subprocess
2
3 closefds = os.name == 'posix'
4 2
5 def grouper(n, iterable): 3 def grouper(n, iterable):
6 ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] ''' 4 ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] '''
7 args = [iter(iterable)] * n 5 args = [iter(iterable)] * n
8 return itertools.izip(*args) 6 return itertools.izip(*args)
130 return out 128 return out
131 129
132 def __nonzero__(self): 130 def __nonzero__(self):
133 """ Returns True if the return code was 0, False otherwise """ 131 """ Returns True if the return code was 0, False otherwise """
134 return self.ret == 0 132 return self.ret == 0
133
134 close_fds = os.name == 'posix'
135
136 def popen(args, env={}):
137 environ = None
138 if env:
139 environ = dict(os.environ)
140 environ.update(env)
141
142 return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
143 close_fds=close_fds, env=environ)