Gentoo Archives: gentoo-commits

From: "Fabian Groffen (grobian)" <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r14456 - in main/branches/prefix: bin pym/_emerge pym/portage pym/portage/dbapi pym/portage/tests/bin
Date: Mon, 28 Sep 2009 18:31:40
Message-Id: E1MsL0a-0004zw-CH@stork.gentoo.org
1 Author: grobian
2 Date: 2009-09-28 18:31:35 +0000 (Mon, 28 Sep 2009)
3 New Revision: 14456
4
5 Modified:
6 main/branches/prefix/bin/dispatch-conf
7 main/branches/prefix/pym/_emerge/actions.py
8 main/branches/prefix/pym/_emerge/depgraph.py
9 main/branches/prefix/pym/portage/__init__.py
10 main/branches/prefix/pym/portage/dbapi/__init__.py
11 main/branches/prefix/pym/portage/tests/bin/setup_env.py
12 main/branches/prefix/pym/portage/tests/bin/test_dobin.py
13 main/branches/prefix/pym/portage/tests/bin/test_dodir.py
14 Log:
15 Merged from trunk -r14442:14455
16
17 | 14445 | Use mkdtemp() instead of hardcoded |
18 | zmedico | pym/portage/tests/bin/root directory. |
19
20 | 14446 | Use explicit imports instead of *. |
21 | zmedico | |
22
23 | 14447 | Fix binTestsInit() to use correct values for |
24 | zmedico | PORTAGE_BIN_PATH and PORTAGE_PYM_PATH. |
25
26 | 14448 | Use catsplit() instead of a regex to generate |
27 | zmedico | dbapi._categories. Thanks to Marat Radchenko |
28 | | <marat@××××××××××××.org> for this patch. |
29
30 | 14449 | Make _test_pty_eof() use non-blocking IO, required for |
31 | zmedico | Darwin kernel. |
32
33 | 14450 | Fix TypeError in clear_screen() in dispatch-conf which |
34 | arfrever | occurs when Python 3 is used (bug #286682). |
35
36 | 14451 | Make _test_pty_eof() fork when writing to the slave_fd, |
37 | zmedico | since otherwise it would block on some platforms such as |
38 | | Darwin. |
39
40 | 14452 | In _test_pty_eof(), call waitpid on the child process only |
41 | zmedico | after reading all the data from the pty. |
42
43 | 14453 | Try to avoid blocking on Darwin in _test_pty_eof() by using |
44 | zmedico | slave_fd directly instead of fdopen. |
45
46 | 14454 | Make _test_pty_eof() call process.spawn() instead of |
47 | zmedico | os.fork(). |
48
49 | 14455 | Fix breakage in file path -> package lookup code. |
50 | zmedico | |
51
52
53 Modified: main/branches/prefix/bin/dispatch-conf
54 ===================================================================
55 --- main/branches/prefix/bin/dispatch-conf 2009-09-28 01:50:14 UTC (rev 14455)
56 +++ main/branches/prefix/bin/dispatch-conf 2009-09-28 18:31:35 UTC (rev 14456)
57 @@ -36,6 +36,7 @@
58
59 from portage import os
60 from portage import dispatch_conf
61 +from portage import _unicode_decode
62 from portage.process import find_binary
63 from portage.const import EPREFIX
64
65 @@ -399,7 +400,7 @@
66 import curses
67 try:
68 curses.setupterm()
69 - sys.stdout.write(curses.tigetstr("clear"))
70 + sys.stdout.write(_unicode_decode(curses.tigetstr("clear")))
71 sys.stdout.flush()
72 return
73 except curses.error:
74
75 Modified: main/branches/prefix/pym/_emerge/actions.py
76 ===================================================================
77 --- main/branches/prefix/pym/_emerge/actions.py 2009-09-28 01:50:14 UTC (rev 14455)
78 +++ main/branches/prefix/pym/_emerge/actions.py 2009-09-28 18:31:35 UTC (rev 14456)
79 @@ -2319,7 +2319,7 @@
80 for x in lookup_owners:
81 if not search_for_multiple and os.path.isdir(x):
82 search_for_multiple = True
83 - relative_paths.append(x[len(root):])
84 + relative_paths.append(x[len(root)-1:])
85
86 owners = set()
87 for pkg, relative_path in \
88
89 Modified: main/branches/prefix/pym/_emerge/depgraph.py
90 ===================================================================
91 --- main/branches/prefix/pym/_emerge/depgraph.py 2009-09-28 01:50:14 UTC (rev 14455)
92 +++ main/branches/prefix/pym/_emerge/depgraph.py 2009-09-28 18:31:35 UTC (rev 14456)
93 @@ -1578,7 +1578,7 @@
94 for x in lookup_owners:
95 if not search_for_multiple and os.path.isdir(x):
96 search_for_multiple = True
97 - relative_paths.append(x[len(myroot):])
98 + relative_paths.append(x[len(myroot)-1:])
99
100 owners = set()
101 for pkg, relative_path in \
102
103 Modified: main/branches/prefix/pym/portage/__init__.py
104 ===================================================================
105 --- main/branches/prefix/pym/portage/__init__.py 2009-09-28 01:50:14 UTC (rev 14455)
106 +++ main/branches/prefix/pym/portage/__init__.py 2009-09-28 18:31:35 UTC (rev 14456)
107 @@ -3762,7 +3762,7 @@
108 Raises an EnvironmentError from openpty() if it fails.
109 """
110
111 - import array, pty, termios
112 + import array, fcntl, pty, select, termios
113 test_string = 2 * "blah blah blah\n"
114 test_string = _unicode_decode(test_string,
115 encoding='utf_8', errors='strict')
116 @@ -3770,8 +3770,9 @@
117 # may raise EnvironmentError
118 master_fd, slave_fd = pty.openpty()
119
120 - master_file = os.fdopen(master_fd, 'rb')
121 - slave_file = os.fdopen(slave_fd, 'wb')
122 + # Non-blocking mode is required for Darwin kernel.
123 + fcntl.fcntl(master_fd, fcntl.F_SETFL,
124 + fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
125
126 # Disable post-processing of output since otherwise weird
127 # things like \n -> \r\n transformations may occur.
128 @@ -3780,16 +3781,33 @@
129 termios.tcsetattr(slave_fd, termios.TCSANOW, mode)
130
131 # Simulate a subprocess writing some data to the
132 - # slave end of the pipe, and then exiting.
133 - slave_file.write(_unicode_encode(test_string,
134 - encoding='utf_8', errors='strict'))
135 - slave_file.close()
136 + # slave end of the pipe, and then exiting. Do a
137 + # real fork here since otherwise os.close(slave_fd)
138 + # would block on some platforms such as Darwin.
139 + pids = process.spawn_bash(_unicode_encode("echo -n '%s'" % test_string,
140 + encoding='utf_8', errors='strict'), env=os.environ,
141 + fd_pipes={0:sys.stdin.fileno(), 1:slave_fd, 2:slave_fd},
142 + returnpid=True)
143 + if isinstance(pids, int):
144 + os.close(master_fd)
145 + os.close(slave_fd)
146 + raise EnvironmentError('spawn failed')
147 + os.close(slave_fd)
148
149 + master_file = os.fdopen(master_fd, 'rb')
150 eof = False
151 data = []
152 + iwtd = [master_file]
153 + owtd = []
154 + ewtd = []
155
156 while not eof:
157
158 + events = select.select(iwtd, owtd, ewtd)
159 + if not events[0]:
160 + eof = True
161 + break
162 +
163 buf = array.array('B')
164 try:
165 buf.fromfile(master_file, 1024)
166 @@ -3805,6 +3823,7 @@
167 data.append(_unicode_decode(buf.tostring(),
168 encoding='utf_8', errors='strict'))
169
170 + os.waitpid(pids[0], 0)
171 master_file.close()
172
173 return test_string == ''.join(data)
174
175 Modified: main/branches/prefix/pym/portage/dbapi/__init__.py
176 ===================================================================
177 --- main/branches/prefix/pym/portage/dbapi/__init__.py 2009-09-28 01:50:14 UTC (rev 14455)
178 +++ main/branches/prefix/pym/portage/dbapi/__init__.py 2009-09-28 18:31:35 UTC (rev 14456)
179 @@ -12,7 +12,7 @@
180 'portage.locks:unlockfile',
181 'portage.output:colorize',
182 'portage.util:cmp_sort_key,writemsg',
183 - 'portage.versions:catpkgsplit,vercmp',
184 + 'portage.versions:catsplit,catpkgsplit,vercmp',
185 )
186
187 from portage import os
188 @@ -39,11 +39,8 @@
189 """
190 if self._categories is not None:
191 return self._categories
192 - categories = set()
193 - cat_pattern = re.compile(r'(.*)/.*')
194 - for cp in self.cp_all():
195 - categories.add(cat_pattern.match(cp).group(1))
196 - self._categories = tuple(sorted(categories))
197 + self._categories = tuple(sorted(set(catsplit(x)[0] \
198 + for x in self.cp_all())))
199 return self._categories
200
201 def close_caches(self):
202
203 Modified: main/branches/prefix/pym/portage/tests/bin/setup_env.py
204 ===================================================================
205 --- main/branches/prefix/pym/portage/tests/bin/setup_env.py 2009-09-28 01:50:14 UTC (rev 14455)
206 +++ main/branches/prefix/pym/portage/tests/bin/setup_env.py 2009-09-28 18:31:35 UTC (rev 14456)
207 @@ -3,34 +3,45 @@
208 # Distributed under the terms of the GNU General Public License v2
209 # $Id$
210
211 +import tempfile
212 +
213 from portage import os
214 from portage import shutil
215 from portage.tests import TestCase
216 from portage.process import spawn
217 -from portage.const import PORTAGE_BIN_PATH
218
219 -bindir = os.path.join(os.path.dirname(os.path.dirname(
220 +basepath = os.path.join(os.path.dirname(os.path.dirname(
221 os.path.abspath(__file__))),
222 - "..", "..", "..", "bin", "ebuild-helpers")
223 -basedir = os.path.join(os.path.dirname(os.path.dirname(
224 - os.path.abspath(__file__))), "bin", "root")
225 -os.environ["D"] = os.path.join(basedir, "image")
226 -os.environ["T"] = os.path.join(basedir, "temp")
227 -os.environ["S"] = os.path.join(basedir, "workdir")
228 -os.environ["PF"] = "portage-tests-0.09-r1"
229 -os.environ["PATH"] = bindir + ":" + os.environ["PATH"]
230 -os.environ["PORTAGE_BIN_PATH"] = PORTAGE_BIN_PATH
231 + "..", "..", "..")
232 +bindir = os.path.join(basepath, "bin")
233 +pymdir = os.path.join(basepath, "pym")
234 +basedir = None
235 +env = None
236
237 def binTestsCleanup():
238 + global basedir
239 + if basedir is None:
240 + return
241 if os.access(basedir, os.W_OK):
242 shutil.rmtree(basedir)
243 + basedir = None
244 +
245 def binTestsInit():
246 binTestsCleanup()
247 - os.mkdir(basedir)
248 - os.mkdir(os.environ["D"])
249 - os.mkdir(os.environ["T"])
250 - os.mkdir(os.environ["S"])
251 - os.chdir(os.environ["S"])
252 + global basedir, env
253 + basedir = tempfile.mkdtemp()
254 + env = os.environ.copy()
255 + env["D"] = os.path.join(basedir, "image")
256 + env["T"] = os.path.join(basedir, "temp")
257 + env["S"] = os.path.join(basedir, "workdir")
258 + env["PF"] = "portage-tests-0.09-r1"
259 + env["PATH"] = bindir + ":" + env["PATH"]
260 + env["PORTAGE_BIN_PATH"] = bindir
261 + env["PORTAGE_PYM_PATH"] = pymdir
262 + os.mkdir(env["D"])
263 + os.mkdir(env["T"])
264 + os.mkdir(env["S"])
265 + os.chdir(env["S"])
266
267 class BinTestCase(TestCase):
268 def __init__(self, methodName):
269 @@ -43,7 +54,7 @@
270
271 def _exists_in_D(path):
272 # Note: do not use os.path.join() here, we assume D to end in /
273 - return os.access(os.environ["D"] + path, os.W_OK)
274 + return os.access(env["D"] + path, os.W_OK)
275 def exists_in_D(path):
276 if not _exists_in_D(path):
277 raise TestCase.failureException
278 @@ -54,9 +65,10 @@
279 def portage_func(func, args, exit_status=0):
280 # we don't care about the output of the programs,
281 # just their exit value and the state of $D
282 + global env
283 f = open('/dev/null', 'wb')
284 fd_pipes = {0:0,1:f.fileno(),2:f.fileno()}
285 - spawn(func+" "+args, env=os.environ, fd_pipes=fd_pipes)
286 + spawn([func] + args.split(), env=env, fd_pipes=fd_pipes)
287 f.close()
288
289 def create_portage_wrapper(bin):
290 @@ -66,9 +78,10 @@
291 return portage_func(*newargs)
292 return derived_func
293
294 -for bin in os.listdir(bindir):
295 +for bin in os.listdir(os.path.join(bindir, "ebuild-helpers")):
296 if bin.startswith("do") or \
297 bin.startswith("new") or \
298 bin.startswith("prep") or \
299 bin in ["ecompress","ecompressdir","fowners","fperms"]:
300 - globals()[bin] = create_portage_wrapper(bin)
301 + globals()[bin] = create_portage_wrapper(
302 + os.path.join(bindir, "ebuild-helpers", bin))
303
304 Modified: main/branches/prefix/pym/portage/tests/bin/test_dobin.py
305 ===================================================================
306 --- main/branches/prefix/pym/portage/tests/bin/test_dobin.py 2009-09-28 01:50:14 UTC (rev 14455)
307 +++ main/branches/prefix/pym/portage/tests/bin/test_dobin.py 2009-09-28 18:31:35 UTC (rev 14456)
308 @@ -3,7 +3,7 @@
309 # Distributed under the terms of the GNU General Public License v2
310 # $Id$
311
312 -from portage.tests.bin.setup_env import *
313 +from portage.tests.bin.setup_env import BinTestCase, dobin, xexists_in_D
314
315 class DoBin(BinTestCase):
316 def testDoBin(self):
317
318 Modified: main/branches/prefix/pym/portage/tests/bin/test_dodir.py
319 ===================================================================
320 --- main/branches/prefix/pym/portage/tests/bin/test_dodir.py 2009-09-28 01:50:14 UTC (rev 14455)
321 +++ main/branches/prefix/pym/portage/tests/bin/test_dodir.py 2009-09-28 18:31:35 UTC (rev 14456)
322 @@ -3,7 +3,7 @@
323 # Distributed under the terms of the GNU General Public License v2
324 # $Id$
325
326 -from portage.tests.bin.setup_env import *
327 +from portage.tests.bin.setup_env import BinTestCase, dodir, exists_in_D
328
329 class DoDir(BinTestCase):
330 def testDoDir(self):