man page updates thanks to Francesco Turco. Update analyze and rebuild modules...
[gentoolkit.git] / pym / gentoolkit / errors.py
1 # Copyright(c) 2004-2009, Gentoo Foundation
2 #
3 # Licensed under the GNU General Public License, v2 or later
4
5 """Exception classes for gentoolkit"""
6
7 __all__ = (
8         'GentoolkitException',
9         'GentoolkitFatalError',
10         'GentoolkitAmbiguousPackage',
11         'GentoolkitInvalidAtom',
12         'GentoolkitInvalidCategory',
13         'GentoolkitInvalidPackage',
14         'GentoolkitInvalidCPV',
15         'GentoolkitInvalidRegex',
16         'GentoolkitInvalidVersion',
17         'GentoolkitNoMatches',
18         'GentoolkitSetNotFound',
19         'GentoolkitUnknownKeyword',
20         'GentoolkitNonZeroExit'
21 )
22
23 # ==========
24 # Exceptions
25 # ==========
26
27 class GentoolkitException(Exception):
28         """Base class for gentoolkit exceptions."""
29         def __init__(self, is_serious=True):
30                 self.is_serious = is_serious
31
32
33 class GentoolkitFatalError(GentoolkitException):
34         """A fatal error occurred. Usually used to catch Portage exceptions."""
35         def __init__(self, err, is_serious=True):
36                 GentoolkitException.__init__(self, is_serious=is_serious)
37                 self.err = err
38
39         def __str__(self):
40                 return "Fatal error: %s" % self.err
41
42
43 class GentoolkitAmbiguousPackage(GentoolkitException):
44         """Got an ambiguous package name."""
45         def __init__(self, choices, is_serious=False):
46                 GentoolkitException.__init__(self, is_serious=is_serious)
47                 self.choices = choices
48
49         def __str__(self):
50                 choices = '\n'.join("  %s" % x for x in self.choices)
51                 return '\n'.join(("Ambiguous package name. Choose from:", choices))
52
53
54 class GentoolkitInvalidAtom(GentoolkitException):
55         """Got a malformed package atom."""
56         def __init__(self, atom, is_serious=False):
57                 GentoolkitException.__init__(self, is_serious=is_serious)
58                 self.atom = atom
59
60         def __str__(self):
61                 return "Invalid atom: '%s'" % self.atom
62
63
64 class GentoolkitSetNotFound(GentoolkitException):
65         """Got unknown set."""
66         def __init__(self, setname, is_serious=False):
67                 GentoolkitException.__init__(self, is_serious=is_serious)
68                 self.setname = setname
69
70         def __str__(self):
71                 return "Unknown set: '%s'" % self.setname
72
73
74 class GentoolkitInvalidCategory(GentoolkitException):
75         """The category was not listed in portage.settings.categories."""
76         def __init__(self, category, is_serious=False):
77                 GentoolkitException.__init__(self, is_serious=is_serious)
78                 self.category = category
79
80         def __str__(self):
81                 return "Invalid category: '%s'" % self.category
82
83
84 class GentoolkitInvalidPackage(GentoolkitException):
85         """Got an unknown or invalid package."""
86         def __init__(self, package, is_serious=False):
87                 GentoolkitException.__init__(self, is_serious=is_serious)
88                 self.package = package
89
90         def __str__(self):
91                 return "Invalid package: '%s'" % self.package
92
93
94 class GentoolkitInvalidCPV(GentoolkitException):
95         """Got an invalid category/package-ver string."""
96         def __init__(self, cpv, is_serious=False):
97                 GentoolkitException.__init__(self, is_serious=is_serious)
98                 self.cpv = cpv
99
100         def __str__(self):
101                 return "Invalid CPV: '%s'" % self.cpv
102
103
104 class GentoolkitInvalidRegex(GentoolkitException):
105         """The regex could not be compiled."""
106         def __init__(self, regex, is_serious=False):
107                 GentoolkitException.__init__(self, is_serious=is_serious)
108                 self.regex = regex
109
110         def __str__(self):
111                 return "Invalid regex: '%s'" % self.regex
112
113
114 class GentoolkitInvalidVersion(GentoolkitException):
115         """Got a malformed version."""
116         def __init__(self, version, is_serious=False):
117                 GentoolkitException.__init__(self, is_serious=is_serious)
118                 self.version = version
119
120         def __str__(self):
121                 return "Malformed version: '%s'" % self.version
122
123
124 class GentoolkitNoMatches(GentoolkitException):
125         """No packages were found matching the search query."""
126         def __init__(self, query, in_installed=False, is_serious=False):
127                 GentoolkitException.__init__(self, is_serious=is_serious)
128                 self.query = query
129                 self.in_installed = in_installed
130
131         def __str__(self):
132                 inst = 'installed ' if self.in_installed else ''
133                 return "No %spackages matching '%s'" % (inst, self.query)
134
135
136 class GentoolkitUnknownKeyword(GentoolkitException):
137         """No packages were found matching the search query."""
138         def __init__(self, query, keywords, use, is_serious=True):
139                 GentoolkitException.__init__(self, is_serious=is_serious)
140                 self.query = query
141                 self.keywords = keywords
142                 self.use = use
143
144         def __str__(self):
145                 return ("Unable to determine the install keyword for:\n" +
146                         "'%s', KEYWORDS = '%s'\nUSE flags = '%s'"
147                         % (self.query, self.keywords, self.use))
148
149
150 class GentoolkitNonZeroExit(GentoolkitException):
151         """Used to signal, that a non-fatal, no warning error occurred.
152            The primary use case is for not returning any data."""
153         def __init__(self, return_code=1, is_serious=False):
154                 GentoolkitException.__init__(self, is_serious=is_serious)
155                 self.return_code = return_code
156
157 # vim: set ts=4 sw=4 tw=79: