RadonMetrics/MaintainabilityIndexCalculator.py

Fri, 01 Jan 2016 12:18:55 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 01 Jan 2016 12:18:55 +0100
changeset 37
7fd806094f0f
parent 13
22bc345844e7
child 42
04457b4ceda5
permissions
-rw-r--r--

Updated copyright for 2016.

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
37
7fd806094f0f Updated copyright for 2016.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
3 # Copyright (c) 2015 - 2016 Detlev Offenbach <detlev@die-offenbachs.de>
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
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
13
22bc345844e7 Implemented the cyclomatic complexity stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
6 """
22bc345844e7 Implemented the cyclomatic complexity stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
7 Module implementing the maintainability index service.
22bc345844e7 Implemented the cyclomatic complexity stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
8 """
22bc345844e7 Implemented the cyclomatic complexity stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
9
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
10 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
11
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 try:
13
22bc345844e7 Implemented the cyclomatic complexity stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
13 str = unicode # __IGNORE_EXCEPTION__ __IGNORE_WARNING__
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
14 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
15 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
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 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
18 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
19
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 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
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 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
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 @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
26 """
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 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
28
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 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
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 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
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 @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
35 """
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 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
37
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 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
40 """
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 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
42
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 @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
44 @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
45 @param text source text
13
22bc345844e7 Implemented the cyclomatic complexity stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
46 @type str
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
47 @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
48 @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
49 """
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 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
51
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
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 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
54 """
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 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
56 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
57
13
22bc345844e7 Implemented the cyclomatic complexity stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
58 @param argumentsList list of arguments tuples as given for
22bc345844e7 Implemented the cyclomatic complexity stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
59 maintainabilityIndex
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
60 @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
61 @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
62 @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
63 @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
64 @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
65 @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
66 @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
67 """
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 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
69 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
70 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
71 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
72 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
73 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
74
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 # 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
76 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
77 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
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 # 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
80 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
81 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
82 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
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 # 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
85 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
86 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
87 .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
88
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 # 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
90 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
91 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
92 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
93 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
94 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
95 # 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
96 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
97 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
98 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
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 # 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
101 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
102 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
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
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 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
106 """
13
22bc345844e7 Implemented the cyclomatic complexity stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
107 Module function acting as the parallel worker for the maintainability
22bc345844e7 Implemented the cyclomatic complexity stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10
diff changeset
108 index calculation.
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
109
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 @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
111 @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
112 @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
113 @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
114 """
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 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
116 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
117 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
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
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 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
121 """
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 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
123 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
124
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 @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
126 @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
127 @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
128 @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
129 @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
130 @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
131 """
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 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
133
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 # 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
135 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
136 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
137 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
138 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
139 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
140
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 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
142 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
143 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
144 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
145 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
146 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
147 return (res, )

eric ide

mercurial