--- a/RadonMetrics/CodeMetricsCalculator.py Thu Sep 17 19:57:14 2015 +0200 +++ b/RadonMetrics/CodeMetricsCalculator.py Fri Sep 18 19:46:57 2015 +0200 @@ -11,7 +11,6 @@ pass import multiprocessing -import sys def initService(): @@ -20,7 +19,7 @@ @return the entry point for the background client (function) """ - return codeMetrics + return rawCodeMetrics def initBatchService(): @@ -29,32 +28,26 @@ @return the entry point for the background client (function) """ - return batchCodeMetrics + return batchRawCodeMetrics -def codeMetrics(file, text="", type_=""): +def rawCodeMetrics(file, text=""): """ - Private function to calculate selected code metrics of one file. + Private function to calculate the raw code metrics of one file. @param file source filename @type str @param text source text @param str - @return tuple containing the filename and the result list - @rtype (str, list) + @return tuple containing the result dictionary + @rtype (tuple of dict) """ - if type_ == "raw": - return __rawCodeMetrics(file, text) - elif type_ == "mi": - return __maintainabilityIndex(file, text) - - res = {"error": "Unknown metrics '{0}'.".format(type_)} - return (res, ) + return __rawCodeMetrics(file, text) -def batchCodeMetrics(argumentsList, send, fx, cancelled): +def batchRawCodeMetrics(argumentsList, send, fx, cancelled): """ - Module function to calculate selected code metrics for a batch of files. + Module function to calculate the raw code metrics for a batch of files. @param argumentsList list of arguments tuples as given for check @type list @@ -111,13 +104,8 @@ @param output output queue @type multiprocessing.Queue """ - for filename, source, type_ in iter(input.get, 'STOP'): - if type_ == "raw": - result = __rawCodeMetrics(filename, source) - elif type_ == "mi": - result = __maintainabilityIndex(filename, source) - else: - result = {} + for filename, source in iter(input.get, 'STOP'): + result = __rawCodeMetrics(filename, source) output.put((filename, result)) @@ -137,7 +125,7 @@ res = __raw2Dict(analyze(text)) except Exception as err: res = {"error": str(err)} - return ("raw", res) + return (res, ) def __raw2Dict(obj): @@ -156,33 +144,3 @@ if v is not None: result[a] = v return result - - -def __maintainabilityIndex(file, text=""): - """ - Private function to calculate the maintainability index for one Python - file. - - @param file source filename - @type str - @param text source text - @type str - @return tuple containing the result dictionary - @rtype (tuple of dict) - """ - from radon.metrics import mi_visit, mi_rank - - # Check type for py2: if not str it's unicode - if sys.version_info[0] == 2: - try: - text = text.encode('utf-8') - except UnicodeError: - pass - - try: - mi = mi_visit(text, True) - rank = mi_rank(mi) - res = {"mi": mi, "rank": rank} - except Exception as err: - res = {"error": str(err)} - return ("mi", res)