75 |
75 |
76 self.backgroundService = e5App().getObject("BackgroundService") |
76 self.backgroundService = e5App().getObject("BackgroundService") |
77 |
77 |
78 path = os.path.join(os.path.dirname(__file__), packageName) |
78 path = os.path.join(os.path.dirname(__file__), packageName) |
79 try: |
79 try: |
|
80 # raw code metrics calculation |
80 self.backgroundService.serviceConnect( |
81 self.backgroundService.serviceConnect( |
81 'radon', 'Python2', path, 'CodeMetricsCalculator', |
82 'radon_raw', 'Python2', path, 'CodeMetricsCalculator', |
82 self.metricsCalculationDone, |
83 lambda fn, res: self.metricsCalculationDone("raw", fn, res), |
83 onErrorCallback=self.serviceErrorPy2, |
84 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( |
84 onBatchDone=self.batchJobDone) |
85 "raw", fx, lang, fn, msg), |
|
86 onBatchDone=lambda fx, lang: self.batchJobDone( |
|
87 "raw", fx, lang)) |
85 self.backgroundService.serviceConnect( |
88 self.backgroundService.serviceConnect( |
86 'radon', 'Python3', path, 'CodeMetricsCalculator', |
89 'radon_raw', 'Python3', path, 'CodeMetricsCalculator', |
87 self.metricsCalculationDone, |
90 lambda fn, res: self.metricsCalculationDone("raw", fn, res), |
88 onErrorCallback=self.serviceErrorPy3, |
91 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( |
89 onBatchDone=self.batchJobDone) |
92 "raw", fx, lang, fn, msg), |
|
93 onBatchDone=lambda fx, lang: self.batchJobDone( |
|
94 "raw", fx, lang)) |
|
95 |
|
96 # maintainability index calculation |
|
97 self.backgroundService.serviceConnect( |
|
98 'radon_mi', 'Python2', path, 'MaintainabilityIndexCalculator', |
|
99 lambda fn, res: self.metricsCalculationDone("mi", fn, res), |
|
100 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( |
|
101 "mi", fx, lang, fn, msg), |
|
102 onBatchDone=lambda fx, lang: self.batchJobDone( |
|
103 "mi", fx, lang)) |
|
104 self.backgroundService.serviceConnect( |
|
105 'radon_mi', 'Python3', path, 'MaintainabilityIndexCalculator', |
|
106 lambda fn, res: self.metricsCalculationDone("mi", fn, res), |
|
107 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( |
|
108 "mi", fx, lang, fn, msg), |
|
109 onBatchDone=lambda fx, lang: self.batchJobDone( |
|
110 "mi", fx, lang)) |
|
111 |
90 self.hasBatch = True |
112 self.hasBatch = True |
91 except TypeError: |
113 except TypeError: |
|
114 # backward compatibility for eric 6.0 |
|
115 # raw code metrics calculation |
92 self.backgroundService.serviceConnect( |
116 self.backgroundService.serviceConnect( |
93 'radon', 'Python2', path, 'CodeMetricsCalculator', |
117 'radon_raw', 'Python2', path, 'CodeMetricsCalculator', |
94 self.metricsCalculationDone, |
118 lambda fn, res: self.metricsCalculationDone("raw", fn, res), |
95 onErrorCallback=self.serviceErrorPy2) |
119 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( |
|
120 "raw", fx, lang, fn, msg)) |
96 self.backgroundService.serviceConnect( |
121 self.backgroundService.serviceConnect( |
97 'radon', 'Python3', path, 'CodeMetricsCalculator', |
122 'radon_raw', 'Python3', path, 'CodeMetricsCalculator', |
98 self.metricsCalculationDone, |
123 lambda fn, res: self.metricsCalculationDone("raw", fn, res), |
99 onErrorCallback=self.serviceErrorPy3) |
124 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( |
|
125 "raw", fx, lang, fn, msg)) |
|
126 |
|
127 # maintainability index calculation |
|
128 self.backgroundService.serviceConnect( |
|
129 'radon_mi', 'Python2', path, 'MaintainabilityIndexCalculator', |
|
130 lambda fn, res: self.metricsCalculationDone("mi", fn, res), |
|
131 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( |
|
132 "mi", fx, lang, fn, msg)) |
|
133 self.backgroundService.serviceConnect( |
|
134 'radon_mi', 'Python3', path, 'MaintainabilityIndexCalculator', |
|
135 lambda fn, res: self.metricsCalculationDone("mi", fn, res), |
|
136 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( |
|
137 "mi", fx, lang, fn, msg)) |
|
138 |
100 self.hasBatch = False |
139 self.hasBatch = False |
101 |
140 |
102 self.queuedBatches = [] |
141 self.queuedBatches = { |
103 self.batchesFinished = True |
142 "raw": [], |
|
143 "mi": [], |
|
144 "cc": [], |
|
145 } |
|
146 self.batchesFinished = { |
|
147 "raw": True, |
|
148 "mi": True, |
|
149 "cc": True, |
|
150 } |
104 |
151 |
105 self.__translator = None |
152 self.__translator = None |
106 self.__loadTranslator() |
153 self.__loadTranslator() |
107 |
154 |
108 def __serviceError(self, fn, msg): |
155 def __serviceError(self, type_, fn, msg): |
109 """ |
156 """ |
110 Private slot handling service errors. |
157 Private slot handling service errors. |
111 |
158 |
|
159 @param type_ type of the calculated metrics |
|
160 @type str, one of ["raw", "mi", "cc"] |
112 @param fn file name |
161 @param fn file name |
113 @type str |
162 @type str |
114 @param msg message text |
163 @param msg message text |
115 @type str |
164 @type str |
116 """ |
165 """ |
117 self.error.emit(fn, msg) |
166 self.error.emit(type_, fn, msg) |
118 |
167 |
119 def serviceErrorPy2(self, fx, lang, fn, msg): |
168 def serviceErrorPy2(self, type_, fx, lang, fn, msg): |
120 """ |
169 """ |
121 Public slot handling service errors for Python 2. |
170 Public slot handling service errors for Python 2. |
122 |
171 |
|
172 @param type_ type of the calculated metrics |
|
173 @type str, one of ["raw", "mi", "cc"] |
123 @param fx service name |
174 @param fx service name |
124 @type str |
175 @type str |
125 @param lang language |
176 @param lang language |
126 @type str |
177 @type str |
127 @param fn file name |
178 @param fn file name |
128 @type str |
179 @type str |
129 @param msg message text |
180 @param msg message text |
130 @type str |
181 @type str |
131 """ |
182 """ |
132 if fx in ['radon', 'batch_radon'] and lang == 'Python2': |
183 if fx in ['radon_' + type_, 'batch_radon_' + type_] and \ |
133 if fx == 'radon': |
184 lang == 'Python2': |
134 self.__serviceError(fn, msg) |
185 if fx == 'radon_' + type_: |
|
186 self.__serviceError(type_, fn, msg) |
135 else: |
187 else: |
136 self.__serviceError(self.tr("Python 2 batch job"), msg) |
188 self.__serviceError(type_, self.tr("Python 2 batch job"), msg) |
137 self.batchJobDone(fx, lang) |
189 self.batchJobDone(type_, fx, lang) |
138 |
190 |
139 def serviceErrorPy3(self, fx, lang, fn, msg): |
191 def serviceErrorPy3(self, type_, fx, lang, fn, msg): |
140 """ |
192 """ |
141 Public slot handling service errors for Python 3. |
193 Public slot handling service errors for Python 3. |
142 |
194 |
|
195 @param type_ type of the calculated metrics |
|
196 @type str, one of ["raw", "mi", "cc"] |
143 @param fx service name |
197 @param fx service name |
144 @type str |
198 @type str |
145 @param lang language |
199 @param lang language |
146 @type str |
200 @type str |
147 @param fn file name |
201 @param fn file name |
148 @type str |
202 @type str |
149 @param msg message text |
203 @param msg message text |
150 @type str |
204 @type str |
151 """ |
205 """ |
152 if fx in ['radon', 'batch_radon'] and lang == 'Python3': |
206 if fx in ['radon_' + type_, 'batch_radon_' + type_] and \ |
153 if fx == 'radon': |
207 lang == 'Python3': |
154 self.__serviceError(fn, msg) |
208 if fx == 'radon_' + type_: |
|
209 self.__serviceError(type_, fn, msg) |
155 else: |
210 else: |
156 self.__serviceError(self.tr("Python 3 batch job"), msg) |
211 self.__serviceError(type_, self.tr("Python 3 batch job"), msg) |
157 self.batchJobDone(fx, lang) |
212 self.batchJobDone(type_, fx, lang) |
158 |
213 |
159 def batchJobDone(self, fx, lang): |
214 def batchJobDone(self, type_, fx, lang): |
160 """ |
215 """ |
161 Public slot handling the completion of a batch job. |
216 Public slot handling the completion of a batch job. |
162 |
217 |
|
218 @param type_ type of the calculated metrics |
|
219 @type str, one of ["raw", "mi", "cc"] |
163 @param fx service name |
220 @param fx service name |
164 @type str |
221 @type str |
165 @param lang language |
222 @param lang language |
166 @type str |
223 @type str |
167 """ |
224 """ |
168 if fx in ['radon', 'batch_radon']: |
225 if fx in ['radon_' + type_, 'batch_radon_' + type_]: |
169 if lang in self.queuedBatches: |
226 if lang in self.queuedBatches[type_]: |
170 self.queuedBatches.remove(lang) |
227 self.queuedBatches[type_].remove(lang) |
171 # prevent sending the signal multiple times |
228 # prevent sending the signal multiple times |
172 if len(self.queuedBatches) == 0 and not self.batchesFinished: |
229 if len(self.queuedBatches[type_]) == 0 and \ |
173 self.batchFinished.emit() |
230 not self.batchesFinished[type_]: |
174 self.batchesFinished = True |
231 self.batchFinished.emit(type_) |
175 |
232 self.batchesFinished[type_] = True |
176 def metricsCalculationDone(self, filename, metricsType, result): |
233 |
|
234 def metricsCalculationDone(self, type_, filename, result): |
177 """ |
235 """ |
178 Public slot to dispatch the result. |
236 Public slot to dispatch the result. |
179 |
237 |
|
238 @param type_ type of the calculated metrics |
|
239 @type str, one of ["raw", "mi", "cc"] |
180 @param filename name of the file the results belong to |
240 @param filename name of the file the results belong to |
181 @type str |
241 @type str |
182 @param metricsType type of the calculated metrics |
|
183 @type str, one of ["raw", "mi", "cc"] |
|
184 @param result result dictionary |
242 @param result result dictionary |
185 @type dict |
243 @type dict |
186 """ |
244 """ |
187 if metricsType == "raw": |
245 if type_ == "raw": |
188 self.metricsDone.emit(filename, result) |
246 self.metricsDone.emit(filename, result) |
189 elif metricsType == "mi": |
247 elif type_ == "mi": |
190 self.maintainabilityIndexDone.emit(filename, result) |
248 self.maintainabilityIndexDone.emit(filename, result) |
191 elif metricsType == "cc": |
249 elif type_ == "cc": |
192 self.complexityDone.emit(filename, result) |
250 self.complexityDone.emit(filename, result) |
193 else: |
251 else: |
194 self.error.emit( |
252 self.error.emit( |
|
253 type_, |
195 filename, |
254 filename, |
196 self.tr("Unknown metrics result received ({0}).").format( |
255 self.tr("Unknown metrics result received ({0}).").format( |
197 metricsType) |
256 type_) |
198 ) |
257 ) |
199 |
258 |
200 def __initialize(self): |
259 def __initialize(self): |
201 """ |
260 """ |
202 Private slot to (re)initialize the plugin. |
261 Private slot to (re)initialize the plugin. |