Mercurial > python-hglib
annotate hglib/util.py @ 134:1b47146a4a2c 1.4
style: fix long lines
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 30 Sep 2014 12:48:04 -0500 |
parents | f98d6e234cd9 |
children | ea80bd2775f6 |
rev | line source |
---|---|
72 | 1 import itertools, cStringIO, error, os, subprocess |
0 | 2 |
3 def grouper(n, iterable): | |
4 ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] ''' | |
5 args = [iter(iterable)] * n | |
6 return itertools.izip(*args) | |
3
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
7 |
8
3ac38d500d68
move hgclient._eatlines to util
Idan Kamara <idankk86@gmail.com>
parents:
3
diff
changeset
|
8 def eatlines(s, n): |
9
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
9 """ |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
10 >>> eatlines("1\\n2", 1) |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
11 '2' |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
12 >>> eatlines("1\\n2", 2) |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
13 '' |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
14 >>> eatlines("1\\n2", 3) |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
15 '' |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
16 >>> eatlines("1\\n2\\n3", 1) |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
17 '2\\n3' |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
18 """ |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
19 cs = cStringIO.StringIO(s) |
8
3ac38d500d68
move hgclient._eatlines to util
Idan Kamara <idankk86@gmail.com>
parents:
3
diff
changeset
|
20 |
9
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
21 for line in cs: |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
22 n -= 1 |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
23 if n == 0: |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
24 return cs.read() |
5882a698ad5c
util: rewrite eatlines (faster and simpler version)
Idan Kamara <idankk86@gmail.com>
parents:
8
diff
changeset
|
25 return '' |
8
3ac38d500d68
move hgclient._eatlines to util
Idan Kamara <idankk86@gmail.com>
parents:
3
diff
changeset
|
26 |
19 | 27 def skiplines(s, prefix): |
28 """ | |
29 Skip lines starting with prefix in s | |
30 | |
31 >>> skiplines('a\\nb\\na\\n', 'a') | |
32 'b\\na\\n' | |
33 >>> skiplines('a\\na\\n', 'a') | |
34 '' | |
35 >>> skiplines('', 'a') | |
36 '' | |
37 >>> skiplines('a\\nb', 'b') | |
38 'a\\nb' | |
39 """ | |
40 cs = cStringIO.StringIO(s) | |
41 | |
42 for line in cs: | |
43 if not line.startswith(prefix): | |
44 return line + cs.read() | |
45 | |
46 return '' | |
47 | |
3
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
48 def cmdbuilder(name, *args, **kwargs): |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
49 """ |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
50 A helper for building the command arguments |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
51 |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
52 args are the positional arguments |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
53 |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
54 kwargs are the options |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
55 keys that are single lettered are prepended with '-', others with '--', |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
56 underscores are replaced with dashes |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
57 |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
58 keys with False boolean values are ignored, lists add the key multiple times |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
59 |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
60 None arguments are skipped |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
61 |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
62 >>> cmdbuilder('cmd', a=True, b=False, c=None) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
63 ['cmd', '-a'] |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
64 >>> cmdbuilder('cmd', long=True) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
65 ['cmd', '--long'] |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
66 >>> cmdbuilder('cmd', str='s') |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
67 ['cmd', '--str', 's'] |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
68 >>> cmdbuilder('cmd', d_ash=True) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
69 ['cmd', '--d-ash'] |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
70 >>> cmdbuilder('cmd', _=True) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
71 ['cmd', '-'] |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
72 >>> cmdbuilder('cmd', list=[1, 2]) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
73 ['cmd', '--list', '1', '--list', '2'] |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
74 >>> cmdbuilder('cmd', None) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
75 ['cmd'] |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
76 """ |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
77 cmd = [name] |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
78 for arg, val in kwargs.items(): |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
79 if val is None: |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
80 continue |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
81 |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
82 arg = arg.replace('_', '-') |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
83 if arg != '-': |
86
f98d6e234cd9
util: eliminate py2.6 if/else expression
Matt Mackall <mpm@selenic.com>
parents:
77
diff
changeset
|
84 if len(arg) == 1: |
f98d6e234cd9
util: eliminate py2.6 if/else expression
Matt Mackall <mpm@selenic.com>
parents:
77
diff
changeset
|
85 arg = '-' + arg |
f98d6e234cd9
util: eliminate py2.6 if/else expression
Matt Mackall <mpm@selenic.com>
parents:
77
diff
changeset
|
86 else: |
f98d6e234cd9
util: eliminate py2.6 if/else expression
Matt Mackall <mpm@selenic.com>
parents:
77
diff
changeset
|
87 arg = '--' + arg |
3
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
88 if isinstance(val, bool): |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
89 if val: |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
90 cmd.append(arg) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
91 elif isinstance(val, list): |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
92 for v in val: |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
93 cmd.append(arg) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
94 cmd.append(str(v)) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
95 else: |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
96 cmd.append(arg) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
97 cmd.append(str(val)) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
98 |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
99 for a in args: |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
100 if a is not None: |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
101 cmd.append(a) |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
102 |
d7903b923217
util: add cmdbuilder, a helper function to generate the command to run
Idan Kamara <idankk86@gmail.com>
parents:
0
diff
changeset
|
103 return cmd |
49
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
104 |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
105 class reterrorhandler(object): |
134 | 106 """This class is meant to be used with rawcommand() error handler |
107 argument. It remembers the return value the command returned if | |
108 it's one of allowed values, which is only 1 if none are given. | |
109 Otherwise it raises a CommandError. | |
49
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
110 |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
111 >>> e = reterrorhandler('') |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
112 >>> bool(e) |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
113 True |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
114 >>> e(1, 'a', '') |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
115 'a' |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
116 >>> bool(e) |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
117 False |
134 | 118 |
49
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
119 """ |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
120 def __init__(self, args, allowed=None): |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
121 self.args = args |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
122 self.ret = 0 |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
123 if allowed is None: |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
124 self.allowed = [1] |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
125 else: |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
126 self.allowed = allowed |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
127 |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
128 def __call__(self, ret, out, err): |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
129 self.ret = ret |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
130 if ret not in self.allowed: |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
131 raise error.CommandError(self.args, ret, out, err) |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
132 return out |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
133 |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
134 def __nonzero__(self): |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
135 """ Returns True if the return code was 0, False otherwise """ |
3d7e0325ba1c
util: introduce a generic error handler that is aware of return codes
Idan Kamara <idankk86@gmail.com>
parents:
19
diff
changeset
|
136 return self.ret == 0 |
72 | 137 |
77
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
138 class propertycache(object): |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
139 """ |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
140 Decorator that remembers the return value of a function call. |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
141 |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
142 >>> class obj(object): |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
143 ... def func(self): |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
144 ... print 'func' |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
145 ... return [] |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
146 ... func = propertycache(func) |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
147 >>> o = obj() |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
148 >>> o.func |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
149 func |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
150 [] |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
151 >>> o.func |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
152 [] |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
153 """ |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
154 def __init__(self, func): |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
155 self.func = func |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
156 self.name = func.__name__ |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
157 def __get__(self, obj, type=None): |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
158 result = self.func(obj) |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
159 setattr(obj, self.name, result) |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
160 return result |
4282391dd693
util: add propertycache decorator
Idan Kamara <idankk86@gmail.com>
parents:
74
diff
changeset
|
161 |
72 | 162 close_fds = os.name == 'posix' |
163 | |
74
a5dd7b5d0be1
util, popen: hide subprocess window
Idan Kamara <idankk86@gmail.com>
parents:
73
diff
changeset
|
164 startupinfo = None |
a5dd7b5d0be1
util, popen: hide subprocess window
Idan Kamara <idankk86@gmail.com>
parents:
73
diff
changeset
|
165 if os.name == 'nt': |
a5dd7b5d0be1
util, popen: hide subprocess window
Idan Kamara <idankk86@gmail.com>
parents:
73
diff
changeset
|
166 startupinfo = subprocess.STARTUPINFO() |
a5dd7b5d0be1
util, popen: hide subprocess window
Idan Kamara <idankk86@gmail.com>
parents:
73
diff
changeset
|
167 startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW |
a5dd7b5d0be1
util, popen: hide subprocess window
Idan Kamara <idankk86@gmail.com>
parents:
73
diff
changeset
|
168 |
72 | 169 def popen(args, env={}): |
170 environ = None | |
171 if env: | |
172 environ = dict(os.environ) | |
173 environ.update(env) | |
174 | |
175 return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, | |
73
77ae99e032f6
util, popen: redirect stderr as well (for hglib.init in case of error)
Idan Kamara <idankk86@gmail.com>
parents:
72
diff
changeset
|
176 stderr=subprocess.PIPE, close_fds=close_fds, |
74
a5dd7b5d0be1
util, popen: hide subprocess window
Idan Kamara <idankk86@gmail.com>
parents:
73
diff
changeset
|
177 startupinfo=startupinfo, env=environ) |