aboutsummaryrefslogtreecommitdiff
blob: c5a88dea2028de8f8b9dfe6a80b34359f28c9598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Copyright(c) 2004-2009, Gentoo Foundation
#
# Licensed under the GNU General Public License, v2 or later

"""Exception classes for gentoolkit"""

__all__ = (
	'GentoolkitException',
	'GentoolkitFatalError',
	'GentoolkitAmbiguousPackage',
	'GentoolkitInvalidAtom',
	'GentoolkitInvalidCategory',
	'GentoolkitInvalidPackage',
	'GentoolkitInvalidCPV',
	'GentoolkitInvalidRegex',
	'GentoolkitInvalidVersion',
	'GentoolkitNoMatches',
	'GentoolkitSetNotFound',
	'GentoolkitUnknownKeyword'
)

# ==========
# Exceptions
# ==========

class GentoolkitException(Exception):
	"""Base class for gentoolkit exceptions."""
	def __init__(self):
		pass


class GentoolkitFatalError(GentoolkitException):
	"""A fatal error occurred. Usually used to catch Portage exceptions."""
	def __init__(self, err):
		self.err = err

	def __str__(self):
		return "Fatal error: %s" % self.err


class GentoolkitAmbiguousPackage(GentoolkitException):
	"""Got an ambiguous package name."""
	def __init__(self, choices):
		self.choices = choices

	def __str__(self):
		choices = '\n'.join("  %s" % x for x in self.choices)
		return '\n'.join(("Ambiguous package name. Choose from:", choices))


class GentoolkitInvalidAtom(GentoolkitException):
	"""Got a malformed package atom."""
	def __init__(self, atom):
		self.atom = atom

	def __str__(self):
		return "Invalid atom: '%s'" % self.atom


class GentoolkitSetNotFound(GentoolkitException):
	"""Got unknown set."""
	def __init__(self, setname):
		self.setname = setname

	def __str__(self):
		return "Unknown set: '%s'" % self.setname


class GentoolkitInvalidCategory(GentoolkitException):
	"""The category was not listed in portage.settings.categories."""
	def __init__(self, category):
		self.category = category

	def __str__(self):
		return "Invalid category: '%s'" % self.category


class GentoolkitInvalidPackage(GentoolkitException):
	"""Got an unknown or invalid package."""
	def __init__(self, package):
		self.package = package

	def __str__(self):
		return "Invalid package: '%s'" % self.package


class GentoolkitInvalidCPV(GentoolkitException):
	"""Got an invalid category/package-ver string."""
	def __init__(self, cpv):
		self.cpv = cpv

	def __str__(self):
		return "Invalid CPV: '%s'" % self.cpv


class GentoolkitInvalidRegex(GentoolkitException):
	"""The regex could not be compiled."""
	def __init__(self, regex):
		self.regex = regex

	def __str__(self):
		return "Invalid regex: '%s'" % self.regex


class GentoolkitInvalidVersion(GentoolkitException):
	"""Got a malformed version."""
	def __init__(self, version):
		self.version = version

	def __str__(self):
		return "Malformed version: '%s'" % self.version


class GentoolkitNoMatches(GentoolkitException):
	"""No packages were found matching the search query."""
	def __init__(self, query, in_installed=False):
		self.query = query
		self.in_installed = in_installed

	def __str__(self):
		inst = 'installed ' if self.in_installed else ''
		return "No %spackages matching '%s'" % (inst, self.query)


class GentoolkitUnknownKeyword(GentoolkitException):
	"""No packages were found matching the search query."""
	def __init__(self, query, keywords, use):
		self.query = query
		self.keywords = keywords
		self.use = use

	def __str__(self):
		return ("Unable to determine the install keyword for:\n" +
			"'%s', KEYWORDS = '%s'\nUSE flags = '%s'"
			% (self.query, self.keywords, self.use))

# vim: set ts=4 sw=4 tw=79: