19 """ |
20 """ |
20 path = __file__ |
21 path = __file__ |
21 for i in range(4): |
22 for i in range(4): |
22 path = os.path.dirname(path) |
23 path = os.path.dirname(path) |
23 sys.path.insert(2, os.path.join(path, "ThirdParty", "Jasy")) |
24 sys.path.insert(2, os.path.join(path, "ThirdParty", "Jasy")) |
24 return jsCheckSyntax |
25 return jsSyntaxCheck |
|
26 |
|
27 |
|
28 def initBatchService(): |
|
29 """ |
|
30 Initialize the batch service and return the entry point. |
|
31 |
|
32 @return the entry point for the background client (function) |
|
33 """ |
|
34 return jsSyntaxBatchCheck |
25 |
35 |
26 |
36 |
27 def normalizeCode(codestring): |
37 def normalizeCode(codestring): |
28 """ |
38 """ |
29 Function to normalize the given code. |
39 Function to normalize the given code. |
44 # pass |
54 # pass |
45 |
55 |
46 return codestring |
56 return codestring |
47 |
57 |
48 |
58 |
49 def jsCheckSyntax(file, codestring): |
59 def jsSyntaxCheck(file, codestring): |
|
60 """ |
|
61 Function to check a Javascript source file for syntax errors. |
|
62 |
|
63 @param file source filename (string) |
|
64 @param codestring string containing the code to check (string) |
|
65 @return dictionary with the keys 'error' and 'warnings' which |
|
66 hold a list containing details about the error/ warnings |
|
67 (file name, line number, column, codestring (only at syntax |
|
68 errors), the message, a list with arguments for the message) |
|
69 """ |
|
70 return __jsSyntaxCheck(file, codestring) |
|
71 |
|
72 |
|
73 def jsSyntaxBatchCheck(argumentsList, send, fx, cancelled): |
|
74 """ |
|
75 Module function to check syntax for a batch of files. |
|
76 |
|
77 @param argumentsList list of arguments tuples as given for |
|
78 syntaxAndPyflakesCheck |
|
79 @param send reference to send function (function) |
|
80 @param fx registered service name (string) |
|
81 @param cancelled reference to function checking for a cancellation |
|
82 (function) |
|
83 """ |
|
84 try: |
|
85 NumberOfProcesses = multiprocessing.cpu_count() |
|
86 if NumberOfProcesses >= 1: |
|
87 NumberOfProcesses -= 1 |
|
88 except NotImplementedError: |
|
89 NumberOfProcesses = 1 |
|
90 |
|
91 # Create queues |
|
92 taskQueue = multiprocessing.Queue() |
|
93 doneQueue = multiprocessing.Queue() |
|
94 |
|
95 # Submit tasks (initially two time number of processes |
|
96 initialTasks = 2 * NumberOfProcesses |
|
97 for task in argumentsList[:initialTasks]: |
|
98 taskQueue.put(task) |
|
99 |
|
100 # Start worker processes |
|
101 for i in range(NumberOfProcesses): |
|
102 multiprocessing.Process(target=worker, args=(taskQueue, doneQueue))\ |
|
103 .start() |
|
104 |
|
105 # Get and send results |
|
106 endIndex = len(argumentsList) - initialTasks |
|
107 for i in range(len(argumentsList)): |
|
108 filename, result = doneQueue.get() |
|
109 send(fx, filename, result) |
|
110 if cancelled(): |
|
111 # just exit the loop ignoring the results of queued tasks |
|
112 break |
|
113 if i < endIndex: |
|
114 taskQueue.put(argumentsList[i + initialTasks]) |
|
115 |
|
116 # Tell child processes to stop |
|
117 for i in range(NumberOfProcesses): |
|
118 taskQueue.put('STOP') |
|
119 |
|
120 |
|
121 def worker(input, output): |
|
122 """ |
|
123 Module function acting as the parallel worker for the style check. |
|
124 |
|
125 @param input input queue (multiprocessing.Queue) |
|
126 @param output output queue (multiprocessing.Queue) |
|
127 """ |
|
128 for filename, args in iter(input.get, 'STOP'): |
|
129 source = args[0] |
|
130 result = __jsSyntaxCheck(filename, source) |
|
131 output.put((filename, result)) |
|
132 |
|
133 |
|
134 def __jsSyntaxCheck(file, codestring): |
50 """ |
135 """ |
51 Function to check a Javascript source file for syntax errors. |
136 Function to check a Javascript source file for syntax errors. |
52 |
137 |
53 @param file source filename (string) |
138 @param file source filename (string) |
54 @param codestring string containing the code to check (string) |
139 @param codestring string containing the code to check (string) |