Sat, 27 Sep 2014 12:34:27 +0200
Fixed an issue in the coding style checker service. Empty files should not be ignored because they could show issues.
(grafted from c00bdab507ef01893022727b0845897a21e05ca5)
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 | |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3591
diff
changeset
|
20 | from PyQt5.QtCore import QProcess, pyqtSignal, QTimer |
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3591
diff
changeset
|
21 | from PyQt5.QtWidgets import QApplication |
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3591
diff
changeset
|
22 | from PyQt5.QtNetwork import QTcpServer, QHostAddress |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
23 | |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
24 | from E5Gui import E5MessageBox |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
25 | from E5Gui.E5Application import e5App |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
26 | import Preferences |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
27 | import Utilities |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
28 | |
3670
f0cb7579c0b4
Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3656
diff
changeset
|
29 | from eric6config import getConfig |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
30 | |
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 BackgroundService(QTcpServer): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
33 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
34 | Class implementing the main part of the background service. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
35 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
36 | serviceNotAvailable = pyqtSignal(str, str, str, str) |
3159
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 | def __init__(self): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
39 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
40 | Constructor of the BackgroundService class. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
41 | """ |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
42 | self.processes = {} |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
43 | self.connections = {} |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
44 | self.isWorking = None |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
45 | self.runningJob = [None, None, None, 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
|
46 | 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
|
47 | self.services = {} |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
48 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
49 | super(BackgroundService, self).__init__() |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
50 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
51 | networkInterface = Preferences.getDebugger("NetworkInterface") |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
52 | if networkInterface == "all" or '.' in networkInterface: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
53 | self.hostAddress = '127.0.0.1' |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
54 | else: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
55 | self.hostAddress = '::1' |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
56 | self.listen(QHostAddress(self.hostAddress)) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
57 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
58 | self.newConnection.connect(self.on_newConnection) |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
59 | |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
60 | 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
|
61 | ## 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
|
62 | 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
|
63 | for pyName in ['Python', 'Python3']: |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
64 | interpreter = Preferences.getDebugger( |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
65 | pyName + "Interpreter") |
3505
84e7cee47d10
Start the background client always as external process.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3484
diff
changeset
|
66 | 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
|
67 | if process: |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
68 | if pyName == 'Python': |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
69 | pyName = 'Python2' |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
70 | self.processes[pyName] = process, interpreter |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
71 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
72 | def __startExternalClient(self, interpreter, port): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
73 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
74 | 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
|
75 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
76 | @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
|
77 | @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
|
78 | @return the process object (QProcess or None) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
79 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
80 | if interpreter == "" or not Utilities.isinpath(interpreter): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
81 | return None |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
82 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
83 | backgroundClient = os.path.join( |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
84 | getConfig('ericDir'), |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
85 | "Utilities", "BackgroundClient.py") |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
86 | proc = QProcess() |
3821
8731f4bf0704
Fixed an issue in the coding style checker service. Empty files should not be ignored because they could show issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3670
diff
changeset
|
87 | proc.setProcessChannelMode(QProcess.ForwardedChannels) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
88 | args = [backgroundClient, self.hostAddress, str(port)] |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
89 | proc.start(interpreter, args) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
90 | if not proc.waitForStarted(10000): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
91 | proc = None |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
92 | 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
|
93 | |
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
|
94 | 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
|
95 | """ |
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
|
96 | 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
|
97 | 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
|
98 | """ |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
99 | 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
|
100 | 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
|
101 | self.isWorking = lang |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
102 | self.runningJob = fx, lang, fn, data |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
103 | 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
|
104 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
105 | def __send(self, fx, lang, fn, data): |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
106 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
107 | 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
|
108 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
109 | @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
|
110 | @param lang language to connect to (str) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
111 | @param fn filename for identification (str) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
112 | @param data function argument(s) (any basic datatype) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
113 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
114 | connection = self.connections.get(lang) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
115 | 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
|
116 | if fx != 'INIT': |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
117 | # Avoid growing recursion deep which could itself result in an |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
118 | # exception |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
119 | QTimer.singleShot( |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
120 | 0, |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
121 | lambda: self.serviceNotAvailable.emit( |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
122 | fx, lang, fn, self.tr( |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
123 | '{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
|
124 | # 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
|
125 | 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
|
126 | self.__processQueue() |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
127 | else: |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
128 | 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
|
129 | 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
|
130 | packedData = bytes(packedData, 'utf-8') |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
131 | header = struct.pack( |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
132 | b'!II', len(packedData), adler32(packedData) & 0xffffffff) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
133 | connection.write(header) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
134 | connection.write(packedData) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
135 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
136 | def __receive(self, lang): |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
137 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
138 | Private method to receive the response from the clients. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
139 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
140 | @param lang language of the incomming connection (str) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
141 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
142 | connection = self.connections[lang] |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
143 | header = connection.read(8) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
144 | length, datahash = struct.unpack(b'!II', header) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
145 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
146 | packedData = b'' |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
147 | while len(packedData) < length: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
148 | connection.waitForReadyRead(50) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
149 | packedData += connection.read(length - len(packedData)) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
150 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
151 | assert adler32(packedData) & 0xffffffff == datahash, 'Hashes not equal' |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
152 | if sys.version_info[0] == 3: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
153 | packedData = packedData.decode('utf-8') |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
154 | # "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
|
155 | 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
|
156 | |
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 | if fx == 'INIT': |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
158 | pass |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
159 | elif fx == 'EXCEPTION': |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
160 | # Remove connection because it'll close anyway |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
161 | self.connections.pop(lang, None) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
162 | # Call sys.excepthook(type, value, traceback) to emulate the |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
163 | # 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
|
164 | sys.excepthook(*data) |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
165 | res = E5MessageBox.question( |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
166 | None, |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
167 | self.tr("Restart background client?"), |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
168 | self.tr( |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
169 | "<p>The background client for <b>{0}</b> has stopped" |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
170 | " due to an exception. It's used by various plug-ins like" |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
171 | " the different checkers.</p>" |
3581
03b351be4436
Einige kleinere Korrekturen.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3579
diff
changeset
|
172 | "<p>Select" |
03b351be4436
Einige kleinere Korrekturen.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3579
diff
changeset
|
173 | "<ul>" |
03b351be4436
Einige kleinere Korrekturen.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3579
diff
changeset
|
174 | "<li><b>'Yes'</b> to restart the client, but abort the" |
03b351be4436
Einige kleinere Korrekturen.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3579
diff
changeset
|
175 | " last job</li>" |
03b351be4436
Einige kleinere Korrekturen.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3579
diff
changeset
|
176 | "<li><b>'Retry'</b> to restart the client and the last" |
03b351be4436
Einige kleinere Korrekturen.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3579
diff
changeset
|
177 | " job</li>" |
03b351be4436
Einige kleinere Korrekturen.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3579
diff
changeset
|
178 | "<li><b>'No'</b> to leave the client off.</li>" |
03b351be4436
Einige kleinere Korrekturen.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3579
diff
changeset
|
179 | "</ul></p>" |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
180 | "<p>Note: The client can be restarted by opening and" |
3581
03b351be4436
Einige kleinere Korrekturen.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3579
diff
changeset
|
181 | " accepting the preferences dialog or reloading/changing" |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
182 | " the project.</p>").format(lang), |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
183 | E5MessageBox.Yes | E5MessageBox.No | E5MessageBox.Retry, |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
184 | E5MessageBox.Yes) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
185 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
186 | if res == E5MessageBox.Retry: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
187 | self.enqueueRequest(*self.runningJob) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
188 | else: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
189 | fx, lng, fn, data = self.runningJob |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
190 | self.services[(fx, lng)][3](fx, lng, fn, self.tr( |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
191 | 'An error in Erics background client stopped the service.') |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
192 | ) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
193 | if res != E5MessageBox.No: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
194 | self.isWorking = None |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
195 | self.restartService(lang, True) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
196 | return |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
197 | 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
|
198 | 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
|
199 | if callback: |
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
200 | 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
|
201 | else: |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
202 | 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
|
203 | 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
|
204 | callback[2](fn, *data) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
205 | |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
206 | 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
|
207 | 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
|
208 | |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
209 | def preferencesOrProjectChanged(self): |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
210 | """ |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
211 | Public slot to restart the built in languages. |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
212 | """ |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
213 | for pyName in ['Python', 'Python3']: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
214 | interpreter = Preferences.getDebugger( |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
215 | pyName + "Interpreter") |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
216 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
217 | if pyName == 'Python': |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
218 | pyName = 'Python2' |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
219 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
220 | # Tweak the processes list to reflect the changed interpreter |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
221 | proc, inter = self.processes.pop(pyName, [None, None]) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
222 | self.processes[pyName] = proc, interpreter |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
223 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
224 | self.restartService(pyName) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
225 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
226 | def restartService(self, language, forceKill=False): |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
227 | """ |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
228 | Public method to restart a given lanuage. |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
229 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
230 | @param language to restart (str) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
231 | @keyparam forceKill flag to kill a running task (bool) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
232 | """ |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
233 | try: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
234 | proc, interpreter = self.processes.pop(language) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
235 | except KeyError: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
236 | return |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
237 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
238 | # Don't kill a process if it's still working |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
239 | if not forceKill: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
240 | while self.isWorking is not None: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
241 | QApplication.processEvents() |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
242 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
243 | conn = self.connections.pop(language, None) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
244 | if conn: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
245 | conn.blockSignals(True) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
246 | conn.close() |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
247 | if proc: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
248 | proc.close() |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
249 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
250 | port = self.serverPort() |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
251 | process = self.__startExternalClient(interpreter, port) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
252 | if process: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
253 | self.processes[language] = process, interpreter |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
254 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
255 | def enqueueRequest(self, fx, lang, fn, data): |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
256 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3581
diff
changeset
|
257 | Public method implementing a queued processing of incomming events. |
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
|
258 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
259 | 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
|
260 | 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
|
261 | @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
|
262 | @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
|
263 | @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
|
264 | @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
|
265 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
266 | 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
|
267 | 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
|
268 | self.__queue.insert(0, args) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
269 | 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
|
270 | 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
|
271 | # 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
|
272 | 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
|
273 | # 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
|
274 | 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
|
275 | 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
|
276 | 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
|
277 | 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
|
278 | 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
|
279 | |
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
|
280 | 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
|
281 | 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
|
282 | onErrorCallback=None): |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
283 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3581
diff
changeset
|
284 | Public method to announce a new service to the background |
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3581
diff
changeset
|
285 | service/client. |
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
|
286 | |
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
|
287 | @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
|
288 | @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
|
289 | @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
|
290 | @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
|
291 | @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
|
292 | @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
|
293 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
294 | 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
|
295 | 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
|
296 | 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
|
297 | 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
|
298 | 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
|
299 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
300 | 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
|
301 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3581
diff
changeset
|
302 | Public method to remove the service from the service list. |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
303 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
304 | @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
|
305 | @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
|
306 | """ |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
307 | 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
|
308 | 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
|
309 | 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
|
310 | |
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
|
311 | 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
|
312 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3581
diff
changeset
|
313 | Private slot for new incomming connections from the clients. |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
314 | """ |
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
|
315 | 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
|
316 | 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
|
317 | return |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
318 | 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
|
319 | 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
|
320 | 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
|
321 | # 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
|
322 | 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
|
323 | 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
|
324 | 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
|
325 | 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
|
326 | 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
|
327 | 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
|
328 | lambda x=lang: self.__receive(x)) |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
329 | connection.disconnected.connect( |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
330 | lambda x=lang: self.on_disconnectSocket(x)) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
331 | |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
332 | 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
|
333 | 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
|
334 | # 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
|
335 | self.enqueueRequest('INIT', lng, fx, args[:2]) |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
336 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
337 | # Syntax check the open editors again |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
338 | try: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
339 | vm = e5App().getObject("ViewManager") |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
340 | except KeyError: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
341 | return |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
342 | for editor in vm.getOpenEditors(): |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
343 | if editor.getLanguage() == lang: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
344 | QTimer.singleShot(0, editor.checkSyntax) |
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
|
345 | |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
346 | def on_disconnectSocket(self, lang): |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
347 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3581
diff
changeset
|
348 | Private slot called when connection to a client is lost. |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
349 | |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
350 | @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
|
351 | """ |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
352 | conn = self.connections.pop(lang, None) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
353 | if conn: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
354 | conn.close() |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
355 | fx, lng, fn, data = self.runningJob |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
356 | if fx != 'INIT' and lng == lang: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
357 | self.services[(fx, lng)][3](fx, lng, fn, self.tr( |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
358 | 'Erics background client disconnected because of an' |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
359 | ' unknown reason.') |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
360 | ) |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
361 | self.isWorking = None |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
362 | |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
363 | res = E5MessageBox.yesNo( |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
364 | None, |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
365 | self.tr('Background client disconnected.'), |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
366 | self.tr( |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
367 | 'The background client for <b>{0}</b> disconnect because' |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
368 | ' of an unknown reason.<br>Should it be restarted?' |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
369 | ).format(lang), |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
370 | yesDefault=True) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
371 | if res: |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
372 | self.restartService(lang) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
373 | |
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
|
374 | 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
|
375 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3581
diff
changeset
|
376 | Public method to cleanup the connections and processes when eric is |
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3581
diff
changeset
|
377 | shuting down. |
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
|
378 | """ |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
379 | for connection in self.connections.values(): |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
380 | # Prevent calling of on_disconnectSocket |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
381 | connection.blockSignals(True) |
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
382 | connection.close() |
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
|
383 | |
3579
eccd12461319
BackgroundService: Restart of the client in different situations handled.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3538
diff
changeset
|
384 | for process, interpreter in self.processes.values(): |
3505
84e7cee47d10
Start the background client always as external process.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3484
diff
changeset
|
385 | process.close() |
84e7cee47d10
Start the background client always as external process.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3484
diff
changeset
|
386 | process = None |