Sat, 26 Apr 2014 10:06:49 +0200
Change a comment in the background service to avoid a clash with a NOTE task marker.
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
2 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
3 | # Copyright (c) 2013 - 2014 Detlev Offenbach <detlev@die-offenbachs.de> |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
4 | # |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
5 | # pylint: disable=C0103 |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
6 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
7 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
8 | Module implementing a background service for the various checkers and other |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
9 | python interpreter dependent functions. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
10 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
11 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
12 | from __future__ import unicode_literals |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
13 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
14 | import json |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
15 | import os |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
16 | import struct |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
17 | import sys |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
18 | from zlib import adler32 |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
19 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
20 | from PyQt4.QtCore import QProcess, pyqtSignal |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
21 | from PyQt4.QtGui import QApplication |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
22 | from PyQt4.QtNetwork import QTcpServer, QHostAddress |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
23 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
24 | import Preferences |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
25 | import Utilities |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
26 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
27 | from eric5config import getConfig |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
28 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
29 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
30 | class BackgroundService(QTcpServer): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
31 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
32 | Class implementing the main part of the background service. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
33 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
34 | serviceNotAvailable = pyqtSignal(str, str, str, str) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
35 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
36 | def __init__(self): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
37 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
38 | Constructor of the BackgroundService class. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
39 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
40 | self.processes = [] |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
41 | self.connections = {} |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
42 | self.isWorking = None |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
43 | self.__queue = [] |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
44 | self.services = {} |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
45 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
46 | super(BackgroundService, self).__init__() |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
47 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
48 | networkInterface = Preferences.getDebugger("NetworkInterface") |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
49 | if networkInterface == "all" or '.' in networkInterface: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
50 | self.hostAddress = '127.0.0.1' |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
51 | else: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
52 | self.hostAddress = '::1' |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
53 | self.listen(QHostAddress(self.hostAddress)) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
54 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
55 | self.newConnection.connect(self.on_newConnection) |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
56 | |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
57 | port = self.serverPort() |
3538
33a75660df08
Change a comment in the background service to avoid a clash with a NOTE task marker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3505
diff
changeset
|
58 | ## Note: Need the port if started external in debugger: |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
59 | print('BackgroundService listening on: %i' % port) |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
60 | for pyName in ['Python', 'Python3']: |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
61 | interpreter = Preferences.getDebugger( |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
62 | pyName + "Interpreter") |
3505
84e7cee47d10
Start the background client always as external process.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3484
diff
changeset
|
63 | process = self.__startExternalClient(interpreter, port) |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
64 | if process: |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
65 | self.processes.append(process) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
66 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
67 | def __startExternalClient(self, interpreter, port): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
68 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
69 | Private method to start the background client as external process. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
70 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
71 | @param interpreter path and name of the executable to start (string) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
72 | @param port socket port to which the interpreter should connect (int) |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
73 | @return the process object (QProcess or None) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
74 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
75 | if interpreter == "" or not Utilities.isinpath(interpreter): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
76 | return None |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
77 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
78 | backgroundClient = os.path.join( |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
79 | getConfig('ericDir'), |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
80 | "Utilities", "BackgroundClient.py") |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
81 | proc = QProcess() |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
82 | args = [backgroundClient, self.hostAddress, str(port)] |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
83 | proc.start(interpreter, args) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
84 | if not proc.waitForStarted(10000): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
85 | proc = None |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
86 | return proc |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
87 | |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
88 | def __processQueue(self): |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
89 | """ |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
90 | Private method to take the next service request and send it to the |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
91 | client. |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
92 | """ |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
93 | if self.__queue and self.isWorking is None: |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
94 | fx, lang, fn, data = self.__queue.pop(0) |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
95 | self.isWorking = lang |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
96 | self.__send(fx, lang, fn, data) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
97 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
98 | def __send(self, fx, lang, fn, data): |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
99 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
100 | Private method to send a job request to one of the clients. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
101 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
102 | @param fx remote function name to execute (str) |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
103 | @param lang language to connect to (str) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
104 | @param fn filename for identification (str) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
105 | @param data function argument(s) (any basic datatype) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
106 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
107 | connection = self.connections.get(lang) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
108 | if connection is None: |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
109 | if fx != 'INIT': |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
110 | self.serviceNotAvailable.emit( |
3484
645c12de6b0c
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3422
diff
changeset
|
111 | fx, lang, fn, self.tr( |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
112 | '{0} not configured.').format(lang)) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
113 | # Reset flag and continue processing queue |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
114 | self.isWorking = None |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
115 | self.__processQueue() |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
116 | else: |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
117 | packedData = json.dumps([fx, fn, data]) |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
118 | if sys.version_info[0] == 3: |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
119 | packedData = bytes(packedData, 'utf-8') |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
120 | header = struct.pack( |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
121 | b'!II', len(packedData), adler32(packedData) & 0xffffffff) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
122 | connection.write(header) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
123 | connection.write(packedData) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
124 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
125 | def __receive(self, lang): |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
126 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
127 | Private method to receive the response from the clients. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
128 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
129 | @param lang language of the incomming connection (str) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
130 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
131 | connection = self.connections[lang] |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
132 | header = connection.read(8) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
133 | length, datahash = struct.unpack(b'!II', header) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
134 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
135 | packedData = b'' |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
136 | while len(packedData) < length: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
137 | connection.waitForReadyRead(50) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
138 | packedData += connection.read(length - len(packedData)) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
139 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
140 | assert adler32(packedData) & 0xffffffff == datahash, 'Hashes not equal' |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
141 | if sys.version_info[0] == 3: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
142 | packedData = packedData.decode('utf-8') |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
143 | # "check" if is's a tuple of 3 values |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
144 | fx, fn, data = json.loads(packedData) |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
145 | |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
146 | if fx == 'INIT': |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
147 | pass |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
148 | elif fx == 'EXCEPTION': |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
149 | # Call sys.excepthook(type, value, traceback) to emulate the |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
150 | # exception which was caught on the client |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
151 | sys.excepthook(*data) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
152 | QApplication.processEvents() |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
153 | elif data == 'Unknown service.': |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
154 | callback = self.services.get((fx, lang)) |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
155 | if callback: |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
156 | callback[3](fx, lang, fn, data) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
157 | else: |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
158 | callback = self.services.get((fx, lang)) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
159 | if callback: |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
160 | callback[2](fn, *data) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
161 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
162 | self.isWorking = None |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
163 | self.__processQueue() |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
164 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
165 | def enqueueRequest(self, fx, lang, fn, data): |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
166 | """ |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
167 | Implement a queued processing of incomming events. |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
168 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
169 | Dublicate service requests updates an older request to avoid overrun or |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
170 | starving of the services. |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
171 | @param fx function name of the service (str) |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
172 | @param lang language to connect to (str) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
173 | @param fn filename for identification (str) |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
174 | @param data function argument(s) (any basic datatype(s)) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
175 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
176 | args = [fx, lang, fn, data] |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
177 | if fx == 'INIT': |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
178 | self.__queue.insert(0, args) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
179 | else: |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
180 | for pendingArg in self.__queue: |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
181 | # Check if it's the same service request (fx, lang, fn equal) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
182 | if pendingArg[:3] == args[:3]: |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
183 | # Update the data |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
184 | pendingArg[3] = args[3] |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
185 | break |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
186 | else: |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
187 | self.__queue.append(args) |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
188 | self.__processQueue() |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
189 | |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
190 | def serviceConnect( |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
191 | self, fx, lang, modulepath, module, callback, |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
192 | onErrorCallback=None): |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
193 | """ |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
194 | Announce a new service to the background service/ client. |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
195 | |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
196 | @param fx function name of the service (str) |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
197 | @param lang language of the new service (str) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
198 | @param modulepath full path to the module (str) |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
199 | @param module name to import (str) |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
200 | @param callback function on service response (function) |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
201 | @param onErrorCallback function if client isn't available (function) |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
202 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
203 | self.services[(fx, lang)] = \ |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
204 | modulepath, module, callback, onErrorCallback |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
205 | self.enqueueRequest('INIT', lang, fx, [modulepath, module]) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
206 | if onErrorCallback: |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
207 | self.serviceNotAvailable.connect(onErrorCallback) |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
208 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
209 | def serviceDisconnect(self, fx, lang): |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
210 | """ |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
211 | Remove the service from the service list. |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
212 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
213 | @param fx function name of the service (function) |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
214 | @param lang language of the service (str) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
215 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
216 | serviceArgs = self.services.pop((fx, lang), None) |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
217 | if serviceArgs and serviceArgs[3]: |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
218 | self.serviceNotAvailable.disconnect(serviceArgs[3]) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
219 | |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
220 | def on_newConnection(self): |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
221 | """ |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
222 | Slot for new incomming connections from the clients. |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
223 | """ |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
224 | connection = self.nextPendingConnection() |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
225 | if not connection.waitForReadyRead(1000): |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
226 | return |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
227 | lang = connection.read(64) |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
228 | if sys.version_info[0] == 3: |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
229 | lang = lang.decode('utf-8') |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
230 | # Avoid hanging of eric on shutdown |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
231 | if self.connections.get(lang): |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
232 | self.connections[lang].close() |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
233 | if self.isWorking == lang: |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
234 | self.isWorking = None |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
235 | self.connections[lang] = connection |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
236 | connection.readyRead.connect( |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
237 | lambda x=lang: self.__receive(x)) |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
238 | connection.disconnected.connect( |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
239 | lambda x=lang: self.on_disconnectSocket(x)) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
240 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
241 | for (fx, lng), args in self.services.items(): |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
242 | if lng == lang: |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
243 | # Register service with modulepath and module |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
244 | self.enqueueRequest('INIT', lng, fx, args[:2]) |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
245 | |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
246 | def on_disconnectSocket(self, lang): |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
247 | """ |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
248 | Slot when connection to a client is lost. |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
249 | |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
250 | @param lang client language which connection is lost (str) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
251 | """ |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
252 | self.connections.pop(lang) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
253 | # Maybe the task is killed while ideling |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
254 | if self.isWorking == lang: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
255 | self.isWorking = None |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
256 | # Remove pending jobs and send warning to the waiting caller |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
257 | # Make a copy of the list because it's modified in the loop |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
258 | for args in self.__queue[:]: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
259 | fx, lng, fn, data = args |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
260 | if lng == lang: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
261 | # Call onErrorCallback with error message |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
262 | self.__queue.remove(args) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
263 | self.services[(fx, lng)][3](fx, fn, lng, self.tr( |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
264 | 'Error in Erics background service stopped service.')) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
265 | |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
266 | def shutdown(self): |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
267 | """ |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
268 | Cleanup the connections and processes when Eric is shuting down. |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
269 | """ |
3422
ecfe8271cc73
Bugfix to avoid an error on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3417
diff
changeset
|
270 | # Make copy of dictionary values because the list is changed by |
ecfe8271cc73
Bugfix to avoid an error on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3417
diff
changeset
|
271 | # on_disconnectSocket |
ecfe8271cc73
Bugfix to avoid an error on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3417
diff
changeset
|
272 | for connection in list(self.connections.values()): |
3173
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
273 | if connection: |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
274 | connection.close() |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
275 | |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3172
diff
changeset
|
276 | for process in self.processes: |
3505
84e7cee47d10
Start the background client always as external process.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3484
diff
changeset
|
277 | process.close() |
84e7cee47d10
Start the background client always as external process.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3484
diff
changeset
|
278 | process = None |