8d720f9080c2abd79a6a9a39bec41cff13a4729c
[tools/mic.git] / mic / utils / errors.py
1 #!/usr/bin/python -tt
2 #
3 # Copyright (c) 2007 Red Hat, Inc.
4 # Copyright (c) 2011 Intel, Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation; version 2 of the License
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc., 59
17 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 class CreatorError(Exception):
20     """An exception base class for all imgcreate errors."""
21     keyword = '<creator>'
22
23     def __init__(self, msg):
24         self.msg = msg
25
26     def __str__(self):
27         if isinstance(self.msg, unicode):
28             self.msg = self.msg.encode('utf-8', 'ignore')
29         else:
30             self.msg = str(self.msg)
31         return self.keyword + self.msg
32
33 class Usage(CreatorError):
34     keyword = '<usage>'
35
36     def __str__(self):
37         if isinstance(self.msg, unicode):
38             self.msg = self.msg.encode('utf-8', 'ignore')
39         else:
40             self.msg = str(self.msg)
41         return self.keyword + self.msg + ', please use "--help" for more info'
42
43 class Abort(CreatorError):
44     keyword = ''
45
46 class ConfigError(CreatorError):
47     keyword = '<config>'
48
49 class KsError(CreatorError):
50     keyword = '<kickstart>'
51
52 class RepoError(CreatorError):
53     keyword = '<repo>'
54
55 class RpmError(CreatorError):
56     keyword = '<rpm>'
57
58 class MountError(CreatorError):
59     keyword = '<mount>'
60
61 class SnapshotError(CreatorError):
62     keyword = '<snapshot>'
63
64 class SquashfsError(CreatorError):
65     keyword = '<squashfs>'
66
67 class BootstrapError(CreatorError):
68     keyword = '<bootstrap>'
69
70 class RuntimeError(CreatorError):
71     keyword = '<runtime>'