PluginMetricsRadon.py

changeset 9
7f6e04213998
parent 6
13e9698a9981
child 10
8b1920a22df3
equal deleted inserted replaced
8:d02708288a22 9:7f6e04213998
47 """ 47 """
48 Class implementing the radon code metrics plug-in. 48 Class implementing the radon code metrics plug-in.
49 49
50 @signal metricsDone(str, dict) emitted when the code metrics were 50 @signal metricsDone(str, dict) emitted when the code metrics were
51 determined for a file 51 determined for a file
52 @signal metricsError(str, str) emitted in case of an error 52 @signal maintainabilityIndexDone(str, dict) emitted when the
53 maintainability index was determined for a file
54 @signal complexityDone(str, dict) emitted when the
55 cyclomatic complexity was determined for a file
56 @signal error(str, str) emitted in case of an error
53 @signal batchFinished() emitted when a code metrics batch is done 57 @signal batchFinished() emitted when a code metrics batch is done
54 """ 58 """
55 metricsDone = pyqtSignal(str, dict) 59 metricsDone = pyqtSignal(str, dict)
56 metricsError = pyqtSignal(str, str) 60 maintainabilityIndexDone = pyqtSignal(str, dict)
61 complexityDone = pyqtSignal(str, dict)
62 error = pyqtSignal(str, str)
57 batchFinished = pyqtSignal() 63 batchFinished = pyqtSignal()
58 64
59 def __init__(self, ui): 65 def __init__(self, ui):
60 """ 66 """
61 Constructor 67 Constructor
71 77
72 path = os.path.join(os.path.dirname(__file__), packageName) 78 path = os.path.join(os.path.dirname(__file__), packageName)
73 try: 79 try:
74 self.backgroundService.serviceConnect( 80 self.backgroundService.serviceConnect(
75 'radon', 'Python2', path, 'CodeMetricsCalculator', 81 'radon', 'Python2', path, 'CodeMetricsCalculator',
76 lambda *args: self.metricsDone.emit(*args), 82 self.metricsCalculationDone,
77 onErrorCallback=self.serviceErrorPy2, 83 onErrorCallback=self.serviceErrorPy2,
78 onBatchDone=self.batchJobDone) 84 onBatchDone=self.batchJobDone)
79 self.backgroundService.serviceConnect( 85 self.backgroundService.serviceConnect(
80 'radon', 'Python3', path, 'CodeMetricsCalculator', 86 'radon', 'Python3', path, 'CodeMetricsCalculator',
81 lambda *args: self.metricsDone.emit(*args), 87 self.metricsCalculationDone,
82 onErrorCallback=self.serviceErrorPy3, 88 onErrorCallback=self.serviceErrorPy3,
83 onBatchDone=self.batchJobDone) 89 onBatchDone=self.batchJobDone)
84 self.hasBatch = True 90 self.hasBatch = True
85 except TypeError: 91 except TypeError:
86 self.backgroundService.serviceConnect( 92 self.backgroundService.serviceConnect(
87 'radon', 'Python2', path, 'CodeMetricsCalculator', 93 'radon', 'Python2', path, 'CodeMetricsCalculator',
88 lambda *args: self.metricsDone.emit(*args), 94 self.metricsCalculationDone,
89 onErrorCallback=self.serviceErrorPy2) 95 onErrorCallback=self.serviceErrorPy2)
90 self.backgroundService.serviceConnect( 96 self.backgroundService.serviceConnect(
91 'radon', 'Python3', path, 'CodeMetricsCalculator', 97 'radon', 'Python3', path, 'CodeMetricsCalculator',
92 lambda *args: self.metricsDone.emit(*args), 98 self.metricsCalculationDone,
93 onErrorCallback=self.serviceErrorPy3) 99 onErrorCallback=self.serviceErrorPy3)
94 self.hasBatch = False 100 self.hasBatch = False
95 101
96 self.queuedBatches = [] 102 self.queuedBatches = []
97 self.batchesFinished = True 103 self.batchesFinished = True
106 @param fn file name 112 @param fn file name
107 @type str 113 @type str
108 @param msg message text 114 @param msg message text
109 @type str 115 @type str
110 """ 116 """
111 self.metricsError.emit(fn, msg) 117 self.error.emit(fn, msg)
112 118
113 def serviceErrorPy2(self, fx, lang, fn, msg): 119 def serviceErrorPy2(self, fx, lang, fn, msg):
114 """ 120 """
115 Public slot handling service errors for Python 2. 121 Public slot handling service errors for Python 2.
116 122
164 self.queuedBatches.remove(lang) 170 self.queuedBatches.remove(lang)
165 # prevent sending the signal multiple times 171 # prevent sending the signal multiple times
166 if len(self.queuedBatches) == 0 and not self.batchesFinished: 172 if len(self.queuedBatches) == 0 and not self.batchesFinished:
167 self.batchFinished.emit() 173 self.batchFinished.emit()
168 self.batchesFinished = True 174 self.batchesFinished = True
175
176 def metricsCalculationDone(self, filename, metricsType, result):
177 """
178 Public slot to dispatch the result.
179
180 @param filename name of the file the results belong to
181 @type str
182 @param metricsType type of the calculated metrics
183 @type str, one of ["raw", "mi", "cc"]
184 @param result result dictionary
185 @type dict
186 """
187 if metricsType == "raw":
188 self.metricsDone.emit(filename, result)
189 elif metricsType == "mi":
190 self.maintainabilityIndexDone.emit(filename, result)
191 elif metricsType == "cc":
192 self.complexityDone.emit(filename, result)
193 else:
194 self.error.emit(
195 filename,
196 self.tr("Unknown metrics result received ({0}).").format(
197 metricsType)
198 )
169 199
170 def __initialize(self): 200 def __initialize(self):
171 """ 201 """
172 Private slot to (re)initialize the plugin. 202 Private slot to (re)initialize the plugin.
173 """ 203 """

eric ide

mercurial