From: Fabian Groffen Date: Mon, 28 Sep 2009 18:31:35 +0000 (-0000) Subject: Merged from trunk -r14442:14455 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=fa60dc5405473f4ba0a60da6fe73f7f0f24542bf;p=portage.git Merged from trunk -r14442:14455 | 14445 | Use mkdtemp() instead of hardcoded | | zmedico | pym/portage/tests/bin/root directory. | | 14446 | Use explicit imports instead of *. | | zmedico | | | 14447 | Fix binTestsInit() to use correct values for | | zmedico | PORTAGE_BIN_PATH and PORTAGE_PYM_PATH. | | 14448 | Use catsplit() instead of a regex to generate | | zmedico | dbapi._categories. Thanks to Marat Radchenko | | | for this patch. | | 14449 | Make _test_pty_eof() use non-blocking IO, required for | | zmedico | Darwin kernel. | | 14450 | Fix TypeError in clear_screen() in dispatch-conf which | | arfrever | occurs when Python 3 is used (bug #286682). | | 14451 | Make _test_pty_eof() fork when writing to the slave_fd, | | zmedico | since otherwise it would block on some platforms such as | | | Darwin. | | 14452 | In _test_pty_eof(), call waitpid on the child process only | | zmedico | after reading all the data from the pty. | | 14453 | Try to avoid blocking on Darwin in _test_pty_eof() by using | | zmedico | slave_fd directly instead of fdopen. | | 14454 | Make _test_pty_eof() call process.spawn() instead of | | zmedico | os.fork(). | | 14455 | Fix breakage in file path -> package lookup code. | | zmedico | | svn path=/main/branches/prefix/; revision=14456 --- diff --git a/bin/dispatch-conf b/bin/dispatch-conf index 4d2c1bc31..3fdee4078 100755 --- a/bin/dispatch-conf +++ b/bin/dispatch-conf @@ -36,6 +36,7 @@ import portage from portage import os from portage import dispatch_conf +from portage import _unicode_decode from portage.process import find_binary from portage.const import EPREFIX @@ -399,7 +400,7 @@ def clear_screen(): import curses try: curses.setupterm() - sys.stdout.write(curses.tigetstr("clear")) + sys.stdout.write(_unicode_decode(curses.tigetstr("clear"))) sys.stdout.flush() return except curses.error: diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index 31d85dd40..99db6fbb8 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -2319,7 +2319,7 @@ def action_uninstall(settings, trees, ldpath_mtimes, for x in lookup_owners: if not search_for_multiple and os.path.isdir(x): search_for_multiple = True - relative_paths.append(x[len(root):]) + relative_paths.append(x[len(root)-1:]) owners = set() for pkg, relative_path in \ diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index a5d6c9f60..551022b56 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -1578,7 +1578,7 @@ class depgraph(object): for x in lookup_owners: if not search_for_multiple and os.path.isdir(x): search_for_multiple = True - relative_paths.append(x[len(myroot):]) + relative_paths.append(x[len(myroot)-1:]) owners = set() for pkg, relative_path in \ diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index a83eb5f0c..7983d2f6f 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -3762,7 +3762,7 @@ def _test_pty_eof(): Raises an EnvironmentError from openpty() if it fails. """ - import array, pty, termios + import array, fcntl, pty, select, termios test_string = 2 * "blah blah blah\n" test_string = _unicode_decode(test_string, encoding='utf_8', errors='strict') @@ -3770,8 +3770,9 @@ def _test_pty_eof(): # may raise EnvironmentError master_fd, slave_fd = pty.openpty() - master_file = os.fdopen(master_fd, 'rb') - slave_file = os.fdopen(slave_fd, 'wb') + # Non-blocking mode is required for Darwin kernel. + fcntl.fcntl(master_fd, fcntl.F_SETFL, + fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK) # Disable post-processing of output since otherwise weird # things like \n -> \r\n transformations may occur. @@ -3780,16 +3781,33 @@ def _test_pty_eof(): termios.tcsetattr(slave_fd, termios.TCSANOW, mode) # Simulate a subprocess writing some data to the - # slave end of the pipe, and then exiting. - slave_file.write(_unicode_encode(test_string, - encoding='utf_8', errors='strict')) - slave_file.close() + # slave end of the pipe, and then exiting. Do a + # real fork here since otherwise os.close(slave_fd) + # would block on some platforms such as Darwin. + pids = process.spawn_bash(_unicode_encode("echo -n '%s'" % test_string, + encoding='utf_8', errors='strict'), env=os.environ, + fd_pipes={0:sys.stdin.fileno(), 1:slave_fd, 2:slave_fd}, + returnpid=True) + if isinstance(pids, int): + os.close(master_fd) + os.close(slave_fd) + raise EnvironmentError('spawn failed') + os.close(slave_fd) + master_file = os.fdopen(master_fd, 'rb') eof = False data = [] + iwtd = [master_file] + owtd = [] + ewtd = [] while not eof: + events = select.select(iwtd, owtd, ewtd) + if not events[0]: + eof = True + break + buf = array.array('B') try: buf.fromfile(master_file, 1024) @@ -3805,6 +3823,7 @@ def _test_pty_eof(): data.append(_unicode_decode(buf.tostring(), encoding='utf_8', errors='strict')) + os.waitpid(pids[0], 0) master_file.close() return test_string == ''.join(data) diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index c904d5d2c..53358c829 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -12,7 +12,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.locks:unlockfile', 'portage.output:colorize', 'portage.util:cmp_sort_key,writemsg', - 'portage.versions:catpkgsplit,vercmp', + 'portage.versions:catsplit,catpkgsplit,vercmp', ) from portage import os @@ -39,11 +39,8 @@ class dbapi(object): """ if self._categories is not None: return self._categories - categories = set() - cat_pattern = re.compile(r'(.*)/.*') - for cp in self.cp_all(): - categories.add(cat_pattern.match(cp).group(1)) - self._categories = tuple(sorted(categories)) + self._categories = tuple(sorted(set(catsplit(x)[0] \ + for x in self.cp_all()))) return self._categories def close_caches(self): diff --git a/pym/portage/tests/bin/setup_env.py b/pym/portage/tests/bin/setup_env.py index aab210ee9..fdc5cd21c 100644 --- a/pym/portage/tests/bin/setup_env.py +++ b/pym/portage/tests/bin/setup_env.py @@ -3,34 +3,45 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ +import tempfile + from portage import os from portage import shutil from portage.tests import TestCase from portage.process import spawn -from portage.const import PORTAGE_BIN_PATH -bindir = os.path.join(os.path.dirname(os.path.dirname( +basepath = os.path.join(os.path.dirname(os.path.dirname( os.path.abspath(__file__))), - "..", "..", "..", "bin", "ebuild-helpers") -basedir = os.path.join(os.path.dirname(os.path.dirname( - os.path.abspath(__file__))), "bin", "root") -os.environ["D"] = os.path.join(basedir, "image") -os.environ["T"] = os.path.join(basedir, "temp") -os.environ["S"] = os.path.join(basedir, "workdir") -os.environ["PF"] = "portage-tests-0.09-r1" -os.environ["PATH"] = bindir + ":" + os.environ["PATH"] -os.environ["PORTAGE_BIN_PATH"] = PORTAGE_BIN_PATH + "..", "..", "..") +bindir = os.path.join(basepath, "bin") +pymdir = os.path.join(basepath, "pym") +basedir = None +env = None def binTestsCleanup(): + global basedir + if basedir is None: + return if os.access(basedir, os.W_OK): shutil.rmtree(basedir) + basedir = None + def binTestsInit(): binTestsCleanup() - os.mkdir(basedir) - os.mkdir(os.environ["D"]) - os.mkdir(os.environ["T"]) - os.mkdir(os.environ["S"]) - os.chdir(os.environ["S"]) + global basedir, env + basedir = tempfile.mkdtemp() + env = os.environ.copy() + env["D"] = os.path.join(basedir, "image") + env["T"] = os.path.join(basedir, "temp") + env["S"] = os.path.join(basedir, "workdir") + env["PF"] = "portage-tests-0.09-r1" + env["PATH"] = bindir + ":" + env["PATH"] + env["PORTAGE_BIN_PATH"] = bindir + env["PORTAGE_PYM_PATH"] = pymdir + os.mkdir(env["D"]) + os.mkdir(env["T"]) + os.mkdir(env["S"]) + os.chdir(env["S"]) class BinTestCase(TestCase): def __init__(self, methodName): @@ -43,7 +54,7 @@ class BinTestCase(TestCase): def _exists_in_D(path): # Note: do not use os.path.join() here, we assume D to end in / - return os.access(os.environ["D"] + path, os.W_OK) + return os.access(env["D"] + path, os.W_OK) def exists_in_D(path): if not _exists_in_D(path): raise TestCase.failureException @@ -54,9 +65,10 @@ def xexists_in_D(path): def portage_func(func, args, exit_status=0): # we don't care about the output of the programs, # just their exit value and the state of $D + global env f = open('/dev/null', 'wb') fd_pipes = {0:0,1:f.fileno(),2:f.fileno()} - spawn(func+" "+args, env=os.environ, fd_pipes=fd_pipes) + spawn([func] + args.split(), env=env, fd_pipes=fd_pipes) f.close() def create_portage_wrapper(bin): @@ -66,9 +78,10 @@ def create_portage_wrapper(bin): return portage_func(*newargs) return derived_func -for bin in os.listdir(bindir): +for bin in os.listdir(os.path.join(bindir, "ebuild-helpers")): if bin.startswith("do") or \ bin.startswith("new") or \ bin.startswith("prep") or \ bin in ["ecompress","ecompressdir","fowners","fperms"]: - globals()[bin] = create_portage_wrapper(bin) + globals()[bin] = create_portage_wrapper( + os.path.join(bindir, "ebuild-helpers", bin)) diff --git a/pym/portage/tests/bin/test_dobin.py b/pym/portage/tests/bin/test_dobin.py index 40854d046..7b22f14a6 100644 --- a/pym/portage/tests/bin/test_dobin.py +++ b/pym/portage/tests/bin/test_dobin.py @@ -3,7 +3,7 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ -from portage.tests.bin.setup_env import * +from portage.tests.bin.setup_env import BinTestCase, dobin, xexists_in_D class DoBin(BinTestCase): def testDoBin(self): diff --git a/pym/portage/tests/bin/test_dodir.py b/pym/portage/tests/bin/test_dodir.py index eab681028..04e52077f 100644 --- a/pym/portage/tests/bin/test_dodir.py +++ b/pym/portage/tests/bin/test_dodir.py @@ -3,7 +3,7 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ -from portage.tests.bin.setup_env import * +from portage.tests.bin.setup_env import BinTestCase, dodir, exists_in_D class DoDir(BinTestCase): def testDoDir(self):