|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2007 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the exceptions raised by the plugin system. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import QCoreApplication |
|
13 |
|
14 |
|
15 class PluginError(Exception): |
|
16 """ |
|
17 Class defining a special error for the plugin classes. |
|
18 """ |
|
19 def __init__(self): |
|
20 """ |
|
21 Constructor |
|
22 """ |
|
23 self._errorMessage = QCoreApplication.translate( |
|
24 "PluginError", "Unspecific plugin error.") |
|
25 |
|
26 def __repr__(self): |
|
27 """ |
|
28 Special method returning a representation of the exception. |
|
29 |
|
30 @return string representing the error message |
|
31 """ |
|
32 return str(self._errorMessage) |
|
33 |
|
34 def __str__(self): |
|
35 """ |
|
36 Special method returning a string representation of the exception. |
|
37 |
|
38 @return string representing the error message |
|
39 """ |
|
40 return str(self._errorMessage) |
|
41 |
|
42 |
|
43 class PluginPathError(PluginError): |
|
44 """ |
|
45 Class defining an error raised, when the plugin paths were not found and |
|
46 could not be created. |
|
47 """ |
|
48 def __init__(self, msg=None): |
|
49 """ |
|
50 Constructor |
|
51 |
|
52 @param msg message to be used by the exception (string) |
|
53 """ |
|
54 if msg: |
|
55 self._errorMessage = msg |
|
56 else: |
|
57 self._errorMessage = QCoreApplication.translate( |
|
58 "PluginError", |
|
59 "Plugin paths not found or not creatable.") |
|
60 |
|
61 |
|
62 class PluginModulesError(PluginError): |
|
63 """ |
|
64 Class defining an error raised, when no plugin modules were found. |
|
65 """ |
|
66 def __init__(self): |
|
67 """ |
|
68 Constructor |
|
69 """ |
|
70 self._errorMessage = QCoreApplication.translate( |
|
71 "PluginError", "No plugin modules found.") |
|
72 |
|
73 |
|
74 class PluginLoadError(PluginError): |
|
75 """ |
|
76 Class defining an error raised, when there was an error during plugin |
|
77 loading. |
|
78 """ |
|
79 def __init__(self, name): |
|
80 """ |
|
81 Constructor |
|
82 |
|
83 @param name name of the plugin module (string) |
|
84 """ |
|
85 self._errorMessage = \ |
|
86 QCoreApplication.translate( |
|
87 "PluginError", |
|
88 "Error loading plugin module: {0}")\ |
|
89 .format(name) |
|
90 |
|
91 |
|
92 class PluginActivationError(PluginError): |
|
93 """ |
|
94 Class defining an error raised, when there was an error during plugin |
|
95 activation. |
|
96 """ |
|
97 def __init__(self, name): |
|
98 """ |
|
99 Constructor |
|
100 |
|
101 @param name name of the plugin module (string) |
|
102 """ |
|
103 self._errorMessage = \ |
|
104 QCoreApplication.translate( |
|
105 "PluginError", |
|
106 "Error activating plugin module: {0}")\ |
|
107 .format(name) |
|
108 |
|
109 |
|
110 class PluginModuleFormatError(PluginError): |
|
111 """ |
|
112 Class defining an error raised, when the plugin module is invalid. |
|
113 """ |
|
114 def __init__(self, name, missing): |
|
115 """ |
|
116 Constructor |
|
117 |
|
118 @param name name of the plugin module (string) |
|
119 @param missing description of the missing element (string) |
|
120 """ |
|
121 self._errorMessage = \ |
|
122 QCoreApplication.translate( |
|
123 "PluginError", |
|
124 "The plugin module {0} is missing {1}.")\ |
|
125 .format(name, missing) |
|
126 |
|
127 |
|
128 class PluginClassFormatError(PluginError): |
|
129 """ |
|
130 Class defining an error raised, when the plugin module's class is invalid. |
|
131 """ |
|
132 def __init__(self, name, class_, missing): |
|
133 """ |
|
134 Constructor |
|
135 |
|
136 @param name name of the plugin module (string) |
|
137 @param class_ name of the class not satisfying the requirements |
|
138 (string) |
|
139 @param missing description of the missing element (string) |
|
140 """ |
|
141 self._errorMessage = \ |
|
142 QCoreApplication.translate( |
|
143 "PluginError", |
|
144 "The plugin class {0} of module {1} is missing {2}.")\ |
|
145 .format(class_, name, missing) |
|
146 |
|
147 |
|
148 class PluginPy2IncompatibleError(PluginError): |
|
149 """ |
|
150 Class defining an error raised, when the plugin is incompatible |
|
151 with Python2. |
|
152 """ |
|
153 def __init__(self, name): |
|
154 """ |
|
155 Constructor |
|
156 |
|
157 @param name name of the plugin module (string) |
|
158 """ |
|
159 self._errorMessage = \ |
|
160 QCoreApplication.translate( |
|
161 "PluginError", |
|
162 "The plugin module {0} is not compatible with Python2.")\ |
|
163 .format(name) |