RadonMetrics/CodeMetricsCalculator.py

changeset 4
9ac53bf21182
parent 3
7150ed890fd5
child 5
db25d1d5cc3a
equal deleted inserted replaced
3:7150ed890fd5 4:9ac53bf21182
2 2
3 # Copyright (c) 2015 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2015 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 from __future__ import unicode_literals 6 from __future__ import unicode_literals
7
8 try:
9 str = unicode # __IGNORE_EXCEPTION __IGNORE_WARNING__
10 except NameError:
11 pass
7 12
8 import multiprocessing 13 import multiprocessing
9 14
10 15
11 def initService(): 16 def initService():
120 @type str 125 @type str
121 @return tuple containing the result list 126 @return tuple containing the result list
122 @rtype (list) 127 @rtype (list)
123 """ 128 """
124 from radon.raw import analyze 129 from radon.raw import analyze
125 res = analyze(text) 130 try:
131 res = __raw2Dict(analyze(text))
132 except Exception as err:
133 res = {"error": str(err)}
126 return (res, ) 134 return (res, )
135
136
137 def __raw2Dict(obj):
138 """
139 Private function to convert an object holding raw analysis results into a
140 dictionary.
141
142 @param obj object as returned from analyze()
143 @type radon.raw.Module
144 @return conversion result
145 @rtype dict
146 """
147 result = {}
148 for a in obj._fields:
149 v = getattr(obj, a, None)
150 if v is not None:
151 result[a] = v
152 return result

eric ide

mercurial