AssistantEric/APIsManager.py

changeset 163
842fce9b31ce
parent 156
3e185204e9ec
child 165
c918fe25c97f
equal deleted inserted replaced
162:db992524e3f5 163:842fce9b31ce
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import os 12 import os
13 13
14 from PyQt5.QtCore import QTimer, QThread, QFileInfo, pyqtSignal, QDateTime, \ 14 from PyQt5.QtCore import (
15 QObject, Qt 15 QTimer, QThread, QFileInfo, pyqtSignal, QDateTime, QObject, Qt
16 )
16 try: 17 try:
17 from PyQt5.QtSql import QSqlDatabase, QSqlQuery 18 from PyQt5.QtSql import QSqlDatabase, QSqlQuery
18 except ImportError: 19 except ImportError:
19 # just ignore it because the main plug-in file will deal with it 20 # just ignore it because the main plug-in file will deal with it
20 pass 21 pass
172 query.finish() 173 query.finish()
173 del query 174 del query
174 finally: 175 finally:
175 db.commit() 176 db.commit()
176 if self.__projectPath: 177 if self.__projectPath:
177 modTime = QFileInfo(os.path.join(self.__projectPath, apiFile))\ 178 modTime = (
179 QFileInfo(os.path.join(self.__projectPath, apiFile))
178 .lastModified() 180 .lastModified()
181 )
179 else: 182 else:
180 modTime = QFileInfo(apiFile).lastModified() 183 modTime = QFileInfo(apiFile).lastModified()
181 basesFile = os.path.splitext(apiFile)[0] + ".bas" 184 basesFile = os.path.splitext(apiFile)[0] + ".bas"
182 if os.path.exists(basesFile): 185 if os.path.exists(basesFile):
183 modTimeBases = QFileInfo(basesFile).lastModified() 186 modTimeBases = QFileInfo(basesFile).lastModified()
253 except (IOError, UnicodeError): 256 except (IOError, UnicodeError):
254 pass 257 pass
255 try: 258 try:
256 basesFile = os.path.splitext(apiFile)[0] + ".bas" 259 basesFile = os.path.splitext(apiFile)[0] + ".bas"
257 if os.path.exists(basesFile): 260 if os.path.exists(basesFile):
258 bases = Utilities.readEncodedFile(basesFile)[0]\ 261 bases = (
262 Utilities.readEncodedFile(basesFile)[0]
259 .splitlines(True) 263 .splitlines(True)
264 )
260 except (IOError, UnicodeError): 265 except (IOError, UnicodeError):
261 pass 266 pass
262 language = None 267 language = None
263 268
264 if len(apis) > 0: 269 if len(apis) > 0:
576 drop_acWord_idx = """DROP INDEX IF EXISTS acWord_idx""" 581 drop_acWord_idx = """DROP INDEX IF EXISTS acWord_idx"""
577 582
578 create_context_idx = """CREATE INDEX context_idx on api (context)""" 583 create_context_idx = """CREATE INDEX context_idx on api (context)"""
579 drop_context_idx = """DROP INDEX IF EXISTS context_idx""" 584 drop_context_idx = """DROP INDEX IF EXISTS context_idx"""
580 585
581 create_fullContext_idx = \ 586 create_fullContext_idx = (
582 """CREATE INDEX fullContext_idx on api (fullContext)""" 587 """CREATE INDEX fullContext_idx on api (fullContext)"""
588 )
583 drop_fullContext_idx = """DROP INDEX IF EXISTS fullContext_idx""" 589 drop_fullContext_idx = """DROP INDEX IF EXISTS fullContext_idx"""
584 590
585 create_bases_idx = """CREATE INDEX base_idx on bases (class)""" 591 create_bases_idx = """CREATE INDEX base_idx on bases (class)"""
586 drop_bases_idx = """DROP INDEX IF EXISTS base_idx""" 592 drop_bases_idx = """DROP INDEX IF EXISTS base_idx"""
587 593
686 692
687 def __initAsLanguage(self): 693 def __initAsLanguage(self):
688 """ 694 """
689 Private method to initialize as a language API object. 695 Private method to initialize as a language API object.
690 """ 696 """
691 if self.__language in ["Python", "Python2", "Python3"]: 697 if self.__language == "Python3":
692 self.__discardFirst = ["self", "cls"] 698 self.__discardFirst = ["self", "cls"]
693 else: 699 else:
694 self.__discardFirst = [] 700 self.__discardFirst = []
695 self.__lexer = QScintilla.Lexers.getLexer(self.__language) 701 self.__lexer = QScintilla.Lexers.getLexer(self.__language)
696 try: 702 try:
730 self.__workerQueue = [] 736 self.__workerQueue = []
731 if self.__worker is not None: 737 if self.__worker is not None:
732 self.__worker.abort() 738 self.__worker.abort()
733 if self.__worker is not None: 739 if self.__worker is not None:
734 self.__worker.wait(5000) 740 self.__worker.wait(5000)
735 if self.__worker is not None and \ 741 if (
736 not self.__worker.isFinished(): 742 self.__worker is not None and
743 not self.__worker.isFinished()
744 ):
737 self.__worker.terminate() 745 self.__worker.terminate()
738 if self.__worker is not None: 746 if self.__worker is not None:
739 self.__worker.wait(5000) 747 self.__worker.wait(5000)
740 748
741 if QSqlDatabase and QSqlDatabase.database( 749 if QSqlDatabase and QSqlDatabase.database(
753 db = QSqlDatabase.database(self.__connectionName, False) 761 db = QSqlDatabase.database(self.__connectionName, False)
754 if not db.isValid(): 762 if not db.isValid():
755 # the database connection is a new one 763 # the database connection is a new one
756 db = QSqlDatabase.addDatabase("QSQLITE", self.__connectionName) 764 db = QSqlDatabase.addDatabase("QSQLITE", self.__connectionName)
757 dbName = self._apiDbName() 765 dbName = self._apiDbName()
758 if self.__language == ApisNameProject and \ 766 if (
759 not os.path.exists( 767 self.__language == ApisNameProject and
760 self.__project.getProjectManagementDir()): 768 not os.path.exists(self.__project.getProjectManagementDir())
769 ):
761 opened = False 770 opened = False
762 else: 771 else:
763 db.setDatabaseName(dbName) 772 db.setDatabaseName(dbName)
764 opened = db.open() 773 opened = db.open()
765 if not opened: 774 if not opened:
1034 1043
1035 @keyparam normalized flag indicating a normalized filename is wanted 1044 @keyparam normalized flag indicating a normalized filename is wanted
1036 (boolean) 1045 (boolean)
1037 @return list of project form sources (list of strings) 1046 @return list of project form sources (list of strings)
1038 """ 1047 """
1039 if self.__project.getProjectLanguage() in ["Python", "Python2", 1048 if self.__project.getProjectLanguage() == "Python3":
1040 "Python3"]:
1041 sourceExt = ".py" 1049 sourceExt = ".py"
1042 elif self.__project.getProjectLanguage() == "Ruby": 1050 elif self.__project.getProjectLanguage() == "Ruby":
1043 sourceExt = ".rb" 1051 sourceExt = ".rb"
1044 else: 1052 else:
1045 return [] 1053 return []
1168 1176
1169 def __projectOpened(self): 1177 def __projectOpened(self):
1170 """ 1178 """
1171 Private slot to perform actions after a project has been opened. 1179 Private slot to perform actions after a project has been opened.
1172 """ 1180 """
1173 if self.__project.getProjectLanguage() in ["Python", "Python2", 1181 if self.__project.getProjectLanguage() == "Python3":
1174 "Python3"]:
1175 self.__discardFirst = ["self", "cls"] 1182 self.__discardFirst = ["self", "cls"]
1176 else: 1183 else:
1177 self.__discardFirst = [] 1184 self.__discardFirst = []
1178 self.__lexer = QScintilla.Lexers.getLexer( 1185 self.__lexer = QScintilla.Lexers.getLexer(
1179 self.__project.getProjectLanguage()) 1186 self.__project.getProjectLanguage())
1256 @rtype APIs 1263 @rtype APIs
1257 """ 1264 """
1258 try: 1265 try:
1259 return self.__apis[(language, projectType)] 1266 return self.__apis[(language, projectType)]
1260 except KeyError: 1267 except KeyError:
1261 if language in self.__supportedApiLanguages() or \ 1268 if (
1262 language == ApisNameProject: 1269 language in self.__supportedApiLanguages() or
1270 language == ApisNameProject
1271 ):
1263 # create the api object 1272 # create the api object
1264 api = DbAPIs(language, projectType=projectType) 1273 api = DbAPIs(language, projectType=projectType)
1265 api.apiPreparationStatus.connect(self.__apiPreparationStatus) 1274 api.apiPreparationStatus.connect(self.__apiPreparationStatus)
1266 self.__apis[(language, projectType)] = api 1275 self.__apis[(language, projectType)] = api
1267 return self.__apis[(language, projectType)] 1276 return self.__apis[(language, projectType)]
1326 self.__showMessage(self.tr( 1335 self.__showMessage(self.tr(
1327 "Preparation of '{0}' APIs finished.").format(language)) 1336 "Preparation of '{0}' APIs finished.").format(language))
1328 elif status == WorkerStatusAborted: 1337 elif status == WorkerStatusAborted:
1329 self.__showMessage(self.tr( 1338 self.__showMessage(self.tr(
1330 "Preparation of '{0}' APIs cancelled.").format(language)) 1339 "Preparation of '{0}' APIs cancelled.").format(language))
1340
1341 #
1342 # eflag: noqa = M523, M834, S608

eric ide

mercurial