Sat, 22 Mar 2014 14:44:39 +0100
Exception handling for client side implemented.
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:
3159
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 Qt free version of a background client for the various |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
9 | checkers and other 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 | try: |
3209
c5432abceb25
CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3173
diff
changeset
|
14 | bytes = unicode |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
15 | import StringIO as io # __IGNORE_EXCEPTION__ |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
16 | except NameError: |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
17 | import io # __IGNORE_WARNING__ |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
18 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
19 | import json |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
20 | import socket |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
21 | import struct |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
22 | import sys |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
23 | import traceback |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
24 | from zlib import adler32 |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
25 | |
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 | class BackgroundClient(object): |
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 | Class implementing the main part of the background client. |
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 | def __init__(self, host, port): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
32 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
33 | Constructor of the BackgroundClient class. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
34 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
35 | @param host ip address the background service is listening |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
36 | @param port port of the background service |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
37 | """ |
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:
3159
diff
changeset
|
38 | self.services = {} |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
39 | |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
40 | self.connection = socket.create_connection((host, port)) |
3241
957673fc463a
Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3209
diff
changeset
|
41 | ver = b'Python2' if sys.version_info[0] == 2 else b'Python3' |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
42 | self.connection.sendall(ver) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
43 | |
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:
3159
diff
changeset
|
44 | def __initClientService(self, fn, path, module): |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
45 | """ |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
46 | Import the given module and register it as service. |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
47 | |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
48 | @param fn service name to register (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:
3159
diff
changeset
|
49 | @param path contains the 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:
3159
diff
changeset
|
50 | @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:
3159
diff
changeset
|
51 | @return text result of the import action (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:
3159
diff
changeset
|
52 | """ |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
53 | sys.path.append(path) |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
54 | try: |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
55 | importedModule = __import__(module, globals(), locals(), [], 0) |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
56 | self.services[fn] = importedModule.initService() |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
57 | return 'ok' |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
58 | except ImportError: |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
59 | return 'Import Error' |
1fb284abe46e
Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3159
diff
changeset
|
60 | |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
61 | def __send(self, fx, fn, data): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
62 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
63 | Private method to send a job response back to the BackgroundService. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
64 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
65 | @param fx remote function name to execute (str) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
66 | @param fn filename for identification (str) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
67 | @param data return value(s) (any basic datatype) |
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 | packedData = json.dumps([fx, fn, data]) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
70 | if sys.version_info[0] == 3: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
71 | packedData = bytes(packedData, 'utf-8') |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
72 | header = struct.pack( |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
73 | b'!II', len(packedData), adler32(packedData) & 0xffffffff) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
74 | self.connection.sendall(header) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
75 | self.connection.sendall(packedData) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
76 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
77 | def run(self): |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
78 | """ |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
79 | Implement the main loop of the client. |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
80 | """ |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
81 | try: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
82 | while True: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
83 | try: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
84 | header = b'' |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
85 | while len(header) < 8: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
86 | header += self.connection.recv(8 - len(header)) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
87 | except socket.error: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
88 | # Leave main loop if connection was closed. |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
89 | break |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
90 | # Leave main loop if connection was closed. |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
91 | if not header: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
92 | break |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
93 | |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
94 | length, datahash = struct.unpack(b'!II', header) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
95 | packedData = b'' |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
96 | while len(packedData) < length: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
97 | packedData += self.connection.recv( |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
98 | length - len(packedData)) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
99 | |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
100 | assert adler32(packedData) & 0xffffffff == datahash, \ |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
101 | 'Hashes not equal' |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
102 | if sys.version_info[0] == 3: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
103 | packedData = packedData.decode('utf-8') |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
104 | |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
105 | fx, fn, data = json.loads(packedData) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
106 | if fx == 'INIT': |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
107 | ret = self.__initClientService(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:
3159
diff
changeset
|
108 | else: |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
109 | callback = self.services.get(fx) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
110 | if callback: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
111 | ret = callback(fn, *data) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
112 | else: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
113 | ret = 'Unknown service.' |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
114 | |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
115 | self.__send(fx, fn, ret) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
116 | except: |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
117 | exctype, excval, exctb = sys.exc_info() |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
118 | tbinfofile = io.StringIO() |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
119 | traceback.print_tb(exctb, None, tbinfofile) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
120 | tbinfofile.seek(0) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
121 | tbinfo = tbinfofile.read() |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
122 | del exctb |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
123 | self.__send( |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
124 | 'EXCEPTION', '?', [str(exctype), str(excval), tbinfo]) |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
125 | |
3417
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
126 | self.connection.shutdown(socket.SHUT_RDWR) |
5a93c6cdc989
Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3241
diff
changeset
|
127 | self.connection.close() |
3159
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
128 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
129 | if __name__ == '__main__': |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
130 | if len(sys.argv) != 3: |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
131 | print('Host and port parameters are missing. Abort.') |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
132 | sys.exit(1) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
133 | |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
134 | host, port = sys.argv[1:] |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
135 | backgroundClient = BackgroundClient(host, int(port)) |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
136 | # Start the main loop |
02cb2adb4868
First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset
|
137 | backgroundClient.run() |