public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Fabian Groffen (grobian)" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
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:36 +0000	[thread overview]
Message-ID: <E1MsL0a-0004zw-CH@stork.gentoo.org> (raw)

Author: grobian
Date: 2009-09-28 18:31:35 +0000 (Mon, 28 Sep 2009)
New Revision: 14456

Modified:
   main/branches/prefix/bin/dispatch-conf
   main/branches/prefix/pym/_emerge/actions.py
   main/branches/prefix/pym/_emerge/depgraph.py
   main/branches/prefix/pym/portage/__init__.py
   main/branches/prefix/pym/portage/dbapi/__init__.py
   main/branches/prefix/pym/portage/tests/bin/setup_env.py
   main/branches/prefix/pym/portage/tests/bin/test_dobin.py
   main/branches/prefix/pym/portage/tests/bin/test_dodir.py
Log:
   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                |
   |          | <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  |                                                             |


Modified: main/branches/prefix/bin/dispatch-conf
===================================================================
--- main/branches/prefix/bin/dispatch-conf	2009-09-28 01:50:14 UTC (rev 14455)
+++ main/branches/prefix/bin/dispatch-conf	2009-09-28 18:31:35 UTC (rev 14456)
@@ -36,6 +36,7 @@
 
 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 @@
         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:

Modified: main/branches/prefix/pym/_emerge/actions.py
===================================================================
--- main/branches/prefix/pym/_emerge/actions.py	2009-09-28 01:50:14 UTC (rev 14455)
+++ main/branches/prefix/pym/_emerge/actions.py	2009-09-28 18:31:35 UTC (rev 14456)
@@ -2319,7 +2319,7 @@
 		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 \

Modified: main/branches/prefix/pym/_emerge/depgraph.py
===================================================================
--- main/branches/prefix/pym/_emerge/depgraph.py	2009-09-28 01:50:14 UTC (rev 14455)
+++ main/branches/prefix/pym/_emerge/depgraph.py	2009-09-28 18:31:35 UTC (rev 14456)
@@ -1578,7 +1578,7 @@
 			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 \

Modified: main/branches/prefix/pym/portage/__init__.py
===================================================================
--- main/branches/prefix/pym/portage/__init__.py	2009-09-28 01:50:14 UTC (rev 14455)
+++ main/branches/prefix/pym/portage/__init__.py	2009-09-28 18:31:35 UTC (rev 14456)
@@ -3762,7 +3762,7 @@
 	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 @@
 	# 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 @@
 	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 @@
 			data.append(_unicode_decode(buf.tostring(),
 				encoding='utf_8', errors='strict'))
 
+	os.waitpid(pids[0], 0)
 	master_file.close()
 
 	return test_string == ''.join(data)

Modified: main/branches/prefix/pym/portage/dbapi/__init__.py
===================================================================
--- main/branches/prefix/pym/portage/dbapi/__init__.py	2009-09-28 01:50:14 UTC (rev 14455)
+++ main/branches/prefix/pym/portage/dbapi/__init__.py	2009-09-28 18:31:35 UTC (rev 14456)
@@ -12,7 +12,7 @@
 	'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 @@
 		"""
 		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):

Modified: main/branches/prefix/pym/portage/tests/bin/setup_env.py
===================================================================
--- main/branches/prefix/pym/portage/tests/bin/setup_env.py	2009-09-28 01:50:14 UTC (rev 14455)
+++ main/branches/prefix/pym/portage/tests/bin/setup_env.py	2009-09-28 18:31:35 UTC (rev 14456)
@@ -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 @@
 
 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 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 @@
 		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))

Modified: main/branches/prefix/pym/portage/tests/bin/test_dobin.py
===================================================================
--- main/branches/prefix/pym/portage/tests/bin/test_dobin.py	2009-09-28 01:50:14 UTC (rev 14455)
+++ main/branches/prefix/pym/portage/tests/bin/test_dobin.py	2009-09-28 18:31:35 UTC (rev 14456)
@@ -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):

Modified: main/branches/prefix/pym/portage/tests/bin/test_dodir.py
===================================================================
--- main/branches/prefix/pym/portage/tests/bin/test_dodir.py	2009-09-28 01:50:14 UTC (rev 14455)
+++ main/branches/prefix/pym/portage/tests/bin/test_dodir.py	2009-09-28 18:31:35 UTC (rev 14456)
@@ -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):




                 reply	other threads:[~2009-09-28 18:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1MsL0a-0004zw-CH@stork.gentoo.org \
    --to=grobian@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox