public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: pym/portage/package/ebuild/, bin/, pym/portage/, pym/portage/util/
@ 2014-06-14 20:58 Alexander Berntsen
  0 siblings, 0 replies; only message in thread
From: Alexander Berntsen @ 2014-06-14 20:58 UTC (permalink / raw
  To: gentoo-commits

commit:     55b2e1c0a51d64a84e5649c135cdbc2c650ce6ca
Author:     Alexander Berntsen <bernalex <AT> gentoo <DOT> org>
AuthorDate: Fri May 16 14:06:31 2014 +0000
Commit:     Alexander Berntsen <bernalex <AT> gentoo <DOT> org>
CommitDate: Sat Jun 14 20:48:42 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=55b2e1c0

Turn a traceback into a graceful error

Prior to this patch, the following would traceback:

mkdir -p /etc/portage/make.profile/packages
emerge foo

This patch turns such a traceback into an error by implementing
IsADirectory error handling.

Signed-off-by: Alexander Berntsen <bernalex <AT> gentoo.org>

---
 bin/emerge                           |  9 ++++++++-
 pym/portage/exception.py             |  4 ++++
 pym/portage/package/ebuild/config.py | 13 ++++++++++---
 pym/portage/util/__init__.py         |  3 ++-
 4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/bin/emerge b/bin/emerge
index bb93d83..7773f7f 100755
--- a/bin/emerge
+++ b/bin/emerge
@@ -45,12 +45,19 @@ try:
 	from _emerge.main import emerge_main
 
 	if __name__ == "__main__":
-		from portage.exception import ParseError, PermissionDenied
+		from portage.exception import IsADirectory, ParseError, \
+				PermissionDenied
 		try:
 			retval = emerge_main()
 		except PermissionDenied as e:
 			sys.stderr.write("Permission denied: '%s'\n" % str(e))
 			sys.exit(e.errno)
+		except IsADirectory as e:
+			sys.stderr.write("'%s' is a directory, but should be a file!\n"
+					"See portage man page for information on "
+					"which files may be directories.\n" %
+					str(e))
+			sys.exit(e.errno)
 		except ParseError as e:
 			sys.stderr.write("%s\n" % str(e))
 			sys.exit(1)

diff --git a/pym/portage/exception.py b/pym/portage/exception.py
index 6fa5447..ef62e7a 100644
--- a/pym/portage/exception.py
+++ b/pym/portage/exception.py
@@ -84,6 +84,10 @@ class FileNotFound(InvalidLocation):
 class DirectoryNotFound(InvalidLocation):
 	"""A directory was not found when it was expected to exist"""
 
+class IsADirectory(PortageException):
+	"""A directory was found when it was expected to be a file"""
+	from errno import EISDIR as errno
+
 class OperationNotPermitted(PortageException):
 	"""An operation was not permitted operating system"""
 	from errno import EPERM as errno

diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py
index e104501..f639e14 100644
--- a/pym/portage/package/ebuild/config.py
+++ b/pym/portage/package/ebuild/config.py
@@ -37,7 +37,8 @@ from portage.dep import Atom, isvalidatom, match_from_list, use_reduce, _repo_se
 from portage.eapi import eapi_exports_AA, eapi_exports_merge_type, \
 	eapi_supports_prefix, eapi_exports_replace_vars, _get_eapi_attrs
 from portage.env.loaders import KeyValuePairFileLoader
-from portage.exception import InvalidDependString, PortageException
+from portage.exception import InvalidDependString, IsADirectory, \
+		PortageException
 from portage.localization import _
 from portage.output import colorize
 from portage.process import fakeroot_capable, sandbox_capable
@@ -556,8 +557,14 @@ class config(object):
 			self.profile_path = locations_manager.profile_path
 			self.user_profile_dir = locations_manager.user_profile_dir
 
-			packages_list = [grabfile_package(os.path.join(x, "packages"),
-				verify_eapi=True) for x in self.profiles]
+			try:
+				packages_list = [grabfile_package(os.path.join(x, "packages"),
+					verify_eapi=True) for x in self.profiles]
+			except IOError as e:
+				if e.errno == IsADirectory.errno:
+					raise IsADirectory(os.path.join(self.profile_path,
+									 "packages"))
+
 			self.packages = tuple(stack_lists(packages_list, incremental=1))
 
 			# revmaskdict

diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py
index 614b2b3..4105c19 100644
--- a/pym/portage/util/__init__.py
+++ b/pym/portage/util/__init__.py
@@ -43,7 +43,8 @@ from portage import _unicode_encode
 from portage import _unicode_decode
 from portage.const import VCS_DIRS
 from portage.exception import InvalidAtom, PortageException, FileNotFound, \
-       OperationNotPermitted, ParseError, PermissionDenied, ReadOnlyFileSystem
+       IsADirectory, OperationNotPermitted, ParseError, PermissionDenied, \
+	   ReadOnlyFileSystem
 from portage.localization import _
 from portage.proxy.objectproxy import ObjectProxy
 from portage.cache.mappings import UserDict


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-06-14 20:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-14 20:58 [gentoo-commits] proj/portage:master commit in: pym/portage/package/ebuild/, bin/, pym/portage/, pym/portage/util/ Alexander Berntsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox