f64b452c49bf0760294131138242715fe7f2c462
[tools/mic.git] / mic / utils / errors.py
1 #
2 # Copyright (c) 2011~2013 Intel, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the Free
6 # Software Foundation; version 2 of the License
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc., 59
15 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 """ Collection of all error class """
18
19 class CreatorError(Exception):
20     """ Based class for all mic creator errors """
21     keyword = None
22
23     def __init__(self, msg):
24         Exception.__init__(self)
25         self.msg = msg
26
27     def __str__(self):
28         if isinstance(self.msg, unicode):
29             self.msg = self.msg.encode('utf-8', 'ignore')
30         else:
31             self.msg = str(self.msg)
32         return self.msg
33
34     def __repr__(self):
35         if not hasattr(self, 'keyword') or not self.keyword:
36             self.keyword = self.__class__.__name__
37         return "<%s> %s" % (self.keyword, str(self))
38
39 class Usage(CreatorError):
40     """ Error class for Usage """
41     pass
42
43 class Abort(CreatorError):
44     """ Error class for Abort """
45     pass
46
47 class ConfigError(CreatorError):
48     """ Error class for Config file """
49     keyword = 'Config'
50
51 class KsError(CreatorError):
52     """ Error class for Kickstart module """
53     keyword = 'Kickstart'
54
55 class RepoError(CreatorError):
56     """ Error class for Repository related """
57     keyword = 'Repository'
58
59 class RpmError(CreatorError):
60     """ Error class for RPM related """
61     keyword = 'RPM'
62
63 class MountError(CreatorError):
64     """ Error class for Mount related """
65     keyword = 'Mount'
66
67 class SnapshotError(CreatorError):
68     """ Error class for Snapshot related """
69     keyword = 'Snapshot'
70
71 class SquashfsError(CreatorError):
72     """ Error class for Squashfs related """
73     keyword = 'Squashfs'
74
75 class BootstrapError(CreatorError):
76     """ Error class for Bootstrap related """
77     keyword = 'Bootstrap'
78