Merged from trunk -r14442:14455
authorFabian Groffen <grobian@gentoo.org>
Mon, 28 Sep 2009 18:31:35 +0000 (18:31 -0000)
committerFabian Groffen <grobian@gentoo.org>
Mon, 28 Sep 2009 18:31:35 +0000 (18:31 -0000)
   | 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                |
   |          | <marat@slonopotamus.org> 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

bin/dispatch-conf
pym/_emerge/actions.py
pym/_emerge/depgraph.py
pym/portage/__init__.py
pym/portage/dbapi/__init__.py
pym/portage/tests/bin/setup_env.py
pym/portage/tests/bin/test_dobin.py
pym/portage/tests/bin/test_dodir.py

index 4d2c1bc31e7ab19ba81659355be27fb044c0ba15..3fdee4078f77f41bc4ed9ce9e7adf1311355620d 100755 (executable)
@@ -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:
index 31d85dd407da051ff48254600dd45733f65a3421..99db6fbb84d71044aa121f86dbf6a55df37cc0e2 100644 (file)
@@ -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 \
index a5d6c9f609bb42157ea505082160df45d9aaac97..551022b561be3724389f9f782a2bb3fa68f85a97 100644 (file)
@@ -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 \
index a83eb5f0c38084bfbbf22057420424b7bf2039ce..7983d2f6f20d4667f2adaa70aff0a4261f684206 100644 (file)
@@ -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)
index c904d5d2cb43887a87e9eee1ce63b5e76cec21e2..53358c8295e987715f1a22f0d475d729b9d2d361 100644 (file)
@@ -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):
index aab210ee93916844f3e0d633985ef39ab5dd7530..fdc5cd21cefeec181ebd5cc25130999bb36e1faa 100644 (file)
@@ -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))
index 40854d0467d2bc0539aae95657a5a37f050a0672..7b22f14a66e9838faf29ce6bdefac4e2fb982265 100644 (file)
@@ -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):
index eab681028328a0c4de5983d92e79a0c2812c2a5f..04e52077fd484b07080bfa3e5c465a8daedb83cd 100644 (file)
@@ -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):