5 |
5 |
6 """ |
6 """ |
7 Module implementing the APIsManager. |
7 Module implementing the APIsManager. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 import contextlib |
11 |
|
12 import os |
11 import os |
13 |
12 |
14 from PyQt5.QtCore import ( |
13 from PyQt5.QtCore import ( |
15 QTimer, QThread, QFileInfo, pyqtSignal, QDateTime, QObject, Qt |
14 QTimer, QThread, QFileInfo, pyqtSignal, QDateTime, QObject, Qt |
16 ) |
15 ) |
17 try: |
16 with contextlib.suppress(ImportError): |
18 from PyQt5.QtSql import QSqlDatabase, QSqlQuery |
17 from PyQt5.QtSql import QSqlDatabase, QSqlQuery |
19 except ImportError: |
|
20 # just ignore it because the main plug-in file will deal with it |
|
21 pass |
|
22 |
18 |
23 from E5Gui.E5Application import e5App |
19 from E5Gui.E5Application import e5App |
24 |
20 |
25 import QScintilla.Lexers |
21 import QScintilla.Lexers |
26 |
22 |
164 try: |
160 try: |
165 query = QSqlQuery(db) |
161 query = QSqlQuery(db) |
166 query.prepare(self.file_loaded_stmt) |
162 query.prepare(self.file_loaded_stmt) |
167 query.bindValue(":file", apiFile) |
163 query.bindValue(":file", apiFile) |
168 query.exec() |
164 query.exec() |
169 if query.next() and query.isValid(): # __IGNORE_WARNING_M513__ |
165 loadTime = ( |
170 loadTime = QDateTime.fromString( |
166 QDateTime.fromString(query.value(0), Qt.DateFormat.ISODate) |
171 query.value(0), Qt.DateFormat.ISODate) |
167 if query.next() and query.isValid() else |
172 else: |
168 # __IGNORE_WARNING_M513__ |
173 loadTime = QDateTime(1970, 1, 1, 0, 0) |
169 QDateTime(1970, 1, 1, 0, 0) |
|
170 ) |
174 query.finish() |
171 query.finish() |
175 del query |
172 del query |
176 finally: |
173 finally: |
177 db.commit() |
174 db.commit() |
178 if self.__projectPath: |
175 if self.__projectPath: |
226 """ |
223 """ |
227 apis = [] |
224 apis = [] |
228 bases = [] |
225 bases = [] |
229 |
226 |
230 if self.__language == ApisNameProject: |
227 if self.__language == ApisNameProject: |
231 try: |
228 with contextlib.suppress(OSError, ImportError): |
232 module = Utilities.ModuleParser.readModule( |
229 module = Utilities.ModuleParser.readModule( |
233 os.path.join(self.__projectPath, apiFile), |
230 os.path.join(self.__projectPath, apiFile), |
234 basename=self.__projectPath + os.sep, |
231 basename=self.__projectPath + os.sep, |
235 caching=False) |
232 caching=False) |
236 language = module.getType() |
233 language = module.getType() |
247 for baseEntry in basesDict: |
244 for baseEntry in basesDict: |
248 if basesDict[baseEntry]: |
245 if basesDict[baseEntry]: |
249 bases.append("{0} {1}\n".format( |
246 bases.append("{0} {1}\n".format( |
250 baseEntry, " ".join( |
247 baseEntry, " ".join( |
251 sorted(basesDict[baseEntry])))) |
248 sorted(basesDict[baseEntry])))) |
252 except (OSError, ImportError): |
249 else: |
253 pass |
250 with contextlib.suppress(OSError, UnicodeError): |
254 else: |
|
255 try: |
|
256 apis = Utilities.readEncodedFile(apiFile)[0].splitlines(True) |
251 apis = Utilities.readEncodedFile(apiFile)[0].splitlines(True) |
257 except (OSError, UnicodeError): |
252 with contextlib.suppress(OSError, UnicodeError): |
258 pass |
|
259 try: |
|
260 basesFile = os.path.splitext(apiFile)[0] + ".bas" |
253 basesFile = os.path.splitext(apiFile)[0] + ".bas" |
261 if os.path.exists(basesFile): |
254 if os.path.exists(basesFile): |
262 bases = ( |
255 bases = ( |
263 Utilities.readEncodedFile(basesFile)[0] |
256 Utilities.readEncodedFile(basesFile)[0] |
264 .splitlines(True) |
257 .splitlines(True) |
265 ) |
258 ) |
266 except (OSError, UnicodeError): |
|
267 pass |
|
268 language = None |
259 language = None |
269 |
260 |
270 if len(apis) > 0: |
261 if len(apis) > 0: |
271 self.__storeApis(apis, bases, apiFile, language) |
262 self.__storeApis(apis, bases, apiFile, language) |
272 else: |
263 else: |
382 acWord = path[index:] |
373 acWord = path[index:] |
383 path = path[:(index - len(wsep))] |
374 path = path[:(index - len(wsep))] |
384 index = len(path) |
375 index = len(path) |
385 fullContext = path |
376 fullContext = path |
386 context = path |
377 context = path |
387 try: |
378 with contextlib.suppress(ValueError): |
388 acWord, pictureId = acWord.split("?", 1) |
379 acWord, pictureId = acWord.split("?", 1) |
389 except ValueError: |
|
390 pass |
|
391 else: |
380 else: |
392 context = path[index:] |
381 context = path[index:] |
393 break |
382 break |
394 # none found? |
383 # none found? |
395 if acWord == "": |
384 if acWord == "": |
1053 sourceExt = ".rb" |
1042 sourceExt = ".rb" |
1054 else: |
1043 else: |
1055 return [] |
1044 return [] |
1056 |
1045 |
1057 formsSources = [] |
1046 formsSources = [] |
1058 try: |
1047 forms = self.__project.getProjectFiles("FORMS") |
1059 forms = self.__project.getProjectFiles("FORMS") |
|
1060 except AttributeError: |
|
1061 # backward compatibility < 16.12 |
|
1062 forms = self.__project.pdata["FORMS"] |
|
1063 for fn in forms: |
1048 for fn in forms: |
1064 ofn = os.path.splitext(fn)[0] |
1049 ofn = os.path.splitext(fn)[0] |
1065 dirname, filename = os.path.split(ofn) |
1050 dirname, filename = os.path.split(ofn) |
1066 formSource = os.path.join(dirname, "Ui_" + filename + sourceExt) |
1051 formSource = os.path.join(dirname, "Ui_" + filename + sourceExt) |
1067 if normalized: |
1052 if normalized: |
1266 """ |
1251 """ |
1267 try: |
1252 try: |
1268 return self.__apis[(language, projectType)] |
1253 return self.__apis[(language, projectType)] |
1269 except KeyError: |
1254 except KeyError: |
1270 if ( |
1255 if ( |
1271 language in self.__supportedApiLanguages() or |
1256 language in QScintilla.Lexers.getSupportedApiLanguages() or |
1272 language == ApisNameProject |
1257 language == ApisNameProject |
1273 ): |
1258 ): |
1274 # create the api object |
1259 # create the api object |
1275 api = DbAPIs(language, projectType=projectType) |
1260 api = DbAPIs(language, projectType=projectType) |
1276 api.apiPreparationStatus.connect(self.__apiPreparationStatus) |
1261 api.apiPreparationStatus.connect(self.__apiPreparationStatus) |
1277 self.__apis[(language, projectType)] = api |
1262 self.__apis[(language, projectType)] = api |
1278 return self.__apis[(language, projectType)] |
1263 return self.__apis[(language, projectType)] |
1279 else: |
1264 else: |
1280 return None |
1265 return None |
1281 |
|
1282 def __supportedApiLanguages(self): |
|
1283 """ |
|
1284 Private method to build a list of supported API languages. |
|
1285 |
|
1286 Note: This is a compatibility method to make this code work with |
|
1287 older eric versions. |
|
1288 |
|
1289 @return list of supported API languages |
|
1290 @rtype list of str |
|
1291 """ |
|
1292 try: |
|
1293 return QScintilla.Lexers.getSupportedApiLanguages() |
|
1294 except AttributeError: |
|
1295 # backward compatibility < 16.12 |
|
1296 return [lang for lang in |
|
1297 QScintilla.Lexers.getSupportedLanguages().keys() |
|
1298 if lang != "Guessed" and not lang.startswith("Pygments|")] |
|
1299 |
1266 |
1300 def deactivate(self): |
1267 def deactivate(self): |
1301 """ |
1268 """ |
1302 Public method to perform actions upon deactivation. |
1269 Public method to perform actions upon deactivation. |
1303 """ |
1270 """ |