RadonMetrics/MaintainabilityIndexCalculator.py

Fri, 18 Sep 2015 19:46:57 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 18 Sep 2015 19:46:57 +0200
changeset 10
8b1920a22df3
child 13
22bc345844e7
permissions
-rw-r--r--

Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.

10
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2015 Detlev Offenbach <detlev@die-offenbachs.de>
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 from __future__ import unicode_literals
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 try:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 str = unicode # __IGNORE_EXCEPTION __IGNORE_WARNING__
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 except NameError:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 pass
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import multiprocessing
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import sys
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 def initService():
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Initialize the service and return the entry point.
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @return the entry point for the background client (function)
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 return maintainabilityIndex
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 def initBatchService():
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Initialize the batch service and return the entry point.
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @return the entry point for the background client (function)
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 return batchMaintainabilityIndex
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 def maintainabilityIndex(file, text=""):
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 Private function to calculate the maintainability index of one file.
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @param file source filename
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @type str
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 @param text source text
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 @param str
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 @return tuple containing the result dictionary
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @rtype (tuple of dict)
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 return __maintainabilityIndex(file, text)
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 def batchMaintainabilityIndex(argumentsList, send, fx, cancelled):
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 Module function to calculate the maintainability index for a batch of
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 files.
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @param argumentsList list of arguments tuples as given for check
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 @type list
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @param send reference to send function
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @type function
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @param fx registered service name
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 @type str
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @param cancelled reference to function checking for a cancellation
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 @type function
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 try:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 NumberOfProcesses = multiprocessing.cpu_count()
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 if NumberOfProcesses >= 1:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 NumberOfProcesses -= 1
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 except NotImplementedError:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 NumberOfProcesses = 1
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 # Create queues
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 taskQueue = multiprocessing.Queue()
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 doneQueue = multiprocessing.Queue()
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 # Submit tasks (initially two time number of processes
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 initialTasks = 2 * NumberOfProcesses
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 for task in argumentsList[:initialTasks]:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 taskQueue.put(task)
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 # Start worker processes
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 for i in range(NumberOfProcesses):
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 multiprocessing.Process(target=worker, args=(taskQueue, doneQueue))\
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 .start()
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 # Get and send results
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 endIndex = len(argumentsList) - initialTasks
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 for i in range(len(argumentsList)):
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 filename, result = doneQueue.get()
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 send(fx, filename, result)
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 if cancelled():
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 # just exit the loop ignoring the results of queued tasks
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 break
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 if i < endIndex:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 taskQueue.put(argumentsList[i + initialTasks])
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 # Tell child processes to stop
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 for i in range(NumberOfProcesses):
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 taskQueue.put('STOP')
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 def worker(input, output):
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 Module function acting as the parallel worker for the style check.
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 @param input input queue
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 @type multiprocessing.Queue
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 @param output output queue
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 @type multiprocessing.Queue
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 for filename, source in iter(input.get, 'STOP'):
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 result = __maintainabilityIndex(filename, source)
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 output.put((filename, result))
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 def __maintainabilityIndex(file, text=""):
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 Private function to calculate the maintainability index for one Python
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 file.
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 @param file source filename
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 @type str
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 @param text source text
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 @type str
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 @return tuple containing the result dictionary
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 @rtype (tuple of dict)
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 from radon.metrics import mi_visit, mi_rank
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 # Check type for py2: if not str it's unicode
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 if sys.version_info[0] == 2:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 try:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 text = text.encode('utf-8')
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 except UnicodeError:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 pass
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 try:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 mi = mi_visit(text, True)
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 rank = mi_rank(mi)
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 res = {"mi": mi, "rank": rank}
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 except Exception as err:
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 res = {"error": str(err)}
8b1920a22df3 Changed the logic for the various code metrics calculations to be separate services and fine tuned the dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 return (res, )

eric ide

mercurial