|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the code assist client interface to rope. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import sys |
|
13 import os |
|
14 |
|
15 sys.path.insert(0, os.path.dirname(__file__)) |
|
16 if sys.version_info[0] >= 3: |
|
17 path = os.path.join(os.path.dirname(__file__), 'rope_py3') |
|
18 else: |
|
19 path = os.path.join(os.path.dirname(__file__), 'rope_py2') |
|
20 str = unicode # __IGNORE_WARNING__ |
|
21 sys.path.insert(0, path) |
|
22 |
|
23 import rope.base.libutils |
|
24 import rope.contrib.codeassist |
|
25 |
|
26 from JsonClient import JsonClient |
|
27 |
|
28 |
|
29 class CodeAssistClient(JsonClient): |
|
30 """ |
|
31 Class implementing the code assist client interface to rope. |
|
32 """ |
|
33 def __init__(self, host, port, idString, projectPath): |
|
34 """ |
|
35 Constructor |
|
36 |
|
37 @param host ip address the background service is listening |
|
38 @type str |
|
39 @param port port of the background service |
|
40 @type int |
|
41 @param idString assigned client id to be sent back to the server in |
|
42 order to identify the connection |
|
43 @param str |
|
44 @param projectPath path to the project |
|
45 @type str |
|
46 """ |
|
47 super(CodeAssistClient, self).__init__(host, port, idString) |
|
48 |
|
49 self.__methodMapping = { |
|
50 } |
|
51 |
|
52 self.__projectpath = projectPath |
|
53 self.__project = rope.base.project.Project(self.__projectpath) |
|
54 self.__project.validate(self.__project.root) |
|
55 |
|
56 def handleCall(self, method, params): |
|
57 """ |
|
58 Public method to handle a method call from the server. |
|
59 |
|
60 @param method requested method name |
|
61 @type str |
|
62 @param params dictionary with method specific parameters |
|
63 @type dict |
|
64 """ |
|
65 self.__methodMapping[method](params) |
|
66 |
|
67 |
|
68 if __name__ == '__main__': |
|
69 if len(sys.argv) != 5: |
|
70 print('Host, port, id and project path parameters are missing. Abort.') |
|
71 sys.exit(1) |
|
72 |
|
73 host, port, idString, projectPath = sys.argv[1:] |
|
74 |
|
75 # Create a Qt4/5 application object in order to allow the processing of |
|
76 # modules containing Qt stuff. |
|
77 try: |
|
78 from PyQt5.QtCore import QCoreApplication |
|
79 except ImportError: |
|
80 try: |
|
81 from PyQt4.QtCore import QCoreApplication |
|
82 except ImportError: |
|
83 QCoreApplication = None |
|
84 if QCoreApplication is not None: |
|
85 app = QCoreApplication(sys.argv) |
|
86 |
|
87 client = CodeAssistClient(host, int(port), idString, projectPath) |
|
88 # Start the main loop |
|
89 client.run() |
|
90 |
|
91 sys.exit(0) |
|
92 |
|
93 # |
|
94 # eflag: noqa = M801 |