--- a/ProjectDjango/Project.py Sat May 29 15:03:26 2021 +0200 +++ b/ProjectDjango/Project.py Sat May 29 18:33:03 2021 +0200 @@ -12,14 +12,14 @@ import shutil import contextlib -from PyQt5.QtCore import QObject, QTimer, QUrl, QFileInfo -from PyQt5.QtGui import QDesktopServices -from PyQt5.QtWidgets import QMenu, QInputDialog, QLineEdit, QDialog -from PyQt5.QtCore import QProcess as QProcessPyQt +from PyQt6.QtCore import QObject, QTimer, QUrl, QFileInfo, QIODeviceBase +from PyQt6.QtGui import QDesktopServices +from PyQt6.QtWidgets import QMenu, QInputDialog, QLineEdit, QDialog +from PyQt6.QtCore import QProcess as QProcessPyQt -from E5Gui.E5Application import e5App -from E5Gui import E5MessageBox, E5FileDialog -from E5Gui.E5Action import E5Action +from EricWidgets.EricApplication import ericApp +from EricWidgets import EricMessageBox, EricFileDialog +from EricGui.EricAction import EricAction from Globals import isWindowsPlatform @@ -41,14 +41,17 @@ """ Class transforming the call arguments in case of gnome-terminal. """ - def start(self, cmd, args=None, mode=QProcessPyQt.ReadWrite): + def start(self, cmd, args=None, mode=QIODeviceBase.OpenModeFlag.ReadWrite): """ Public method to start the given program (cmd) in a new process, if none is already running, passing the command line arguments in args. - @param cmd start the given program cmd (string) - @keyparam args list of parameters (list of strings) - @keyparam mode access mode (QIODevice.OpenMode) + @param cmd start the given program cmd + @type str + @param args list of parameters + @type list of str + @param mode access mode + @type QIODeviceBase.OpenMode """ if args is None: args = [] @@ -70,10 +73,14 @@ Public static method to start the given program (cmd) in a new process, if none is already running, passing the command line arguments in args. - @param cmd start the given program cmd (string) - @keyparam args list of parameters (list of strings) - @keyparam path new working directory (string) - @return tuple of successful start and process id (boolean, integer) + @param cmd start the given program cmd + @type str + @param args list of parameters + @type list of str + @param path new working directory + @type str + @return tuple of successful start and process id + @rtype tuple of (bool, int) """ if args is None: args = [] @@ -114,8 +121,8 @@ self.__iconSuffix = iconSuffix self.__ui = parent - self.__e5project = e5App().getObject("Project") - self.__virtualEnvManager = e5App().getObject("VirtualEnvManager") + self.__ericProject = ericApp().getObject("Project") + self.__virtualEnvManager = ericApp().getObject("VirtualEnvManager") self.__hooksInstalled = False self.__menus = {} # dictionary with references to menus @@ -142,7 +149,7 @@ """ self.actions = [] - self.selectSiteAct = E5Action( + self.selectSiteAct = EricAction( self.tr('Current Project'), "", 0, 0, @@ -162,7 +169,7 @@ ## start actions below ## ############################## - self.startProjectAct = E5Action( + self.startProjectAct = EricAction( self.tr('Start Project'), self.tr('Start &Project'), 0, 0, @@ -177,7 +184,7 @@ self.startProjectAct.triggered.connect(self.__startProject) self.actions.append(self.startProjectAct) - self.startGlobalApplicationAct = E5Action( + self.startGlobalApplicationAct = EricAction( self.tr('Start Application (global)'), self.tr('Start Application (&global)'), 0, 0, @@ -193,7 +200,7 @@ self.__startGlobalApplication) self.actions.append(self.startGlobalApplicationAct) - self.startLocalApplicationAct = E5Action( + self.startLocalApplicationAct = EricAction( self.tr('Start Application (local)'), self.tr('Start Application (&local)'), 0, 0, @@ -213,7 +220,7 @@ ## run actions below ## ############################## - self.runServerAct = E5Action( + self.runServerAct = EricAction( self.tr('Run Server'), self.tr('Run &Server'), 0, 0, @@ -228,7 +235,7 @@ self.runServerAct.triggered.connect(self.__runServer) self.actions.append(self.runServerAct) - self.runBrowserAct = E5Action( + self.runBrowserAct = EricAction( self.tr('Run Web-Browser'), self.tr('Run &Web-Browser'), 0, 0, @@ -248,7 +255,7 @@ ## caching actions below ## ############################## - self.createCacheTableAct = E5Action( + self.createCacheTableAct = EricAction( self.tr('Create Cache Tables'), self.tr('C&reate Cache Tables'), 0, 0, @@ -268,7 +275,7 @@ ## help action below ## ############################## - self.helpAct = E5Action( + self.helpAct = EricAction( self.tr('Help'), self.tr('&Help'), 0, 0, @@ -286,7 +293,7 @@ ## about action below ## ############################## - self.aboutDjangoAct = E5Action( + self.aboutDjangoAct = EricAction( self.tr('About Django'), self.tr('About D&jango'), 0, 0, @@ -304,7 +311,7 @@ ## check action below ## ############################## - self.checkAct = E5Action( + self.checkAct = EricAction( self.tr('Check Project'), self.tr('Check Project'), 0, 0, @@ -330,7 +337,7 @@ """ Private method to define the database related actions. """ - self.selectDatabaseNameAct = E5Action( + self.selectDatabaseNameAct = EricAction( self.tr('Current Database'), "", 0, 0, @@ -347,7 +354,7 @@ self.actions.append(self.selectDatabaseNameAct) self.__setCurrentDatabase(None) - self.inspectDatabaseAct = E5Action( + self.inspectDatabaseAct = EricAction( self.tr('Introspect'), self.tr('&Introspect'), 0, 0, @@ -363,7 +370,7 @@ self.inspectDatabaseAct.triggered.connect(self.__databaseInspect) self.actions.append(self.inspectDatabaseAct) - self.flushDatabaseAct = E5Action( + self.flushDatabaseAct = EricAction( self.tr('Flush'), self.tr('&Flush'), 0, 0, @@ -379,7 +386,7 @@ self.flushDatabaseAct.triggered.connect(self.__databaseFlush) self.actions.append(self.flushDatabaseAct) - self.databaseClientAct = E5Action( + self.databaseClientAct = EricAction( self.tr('Start Client Console'), self.tr('Start &Client Console'), 0, 0, @@ -397,7 +404,7 @@ """ Private method to define the database SQL related actions. """ - self.databaseSqlFlushAct = E5Action( + self.databaseSqlFlushAct = EricAction( self.tr('Flush Database'), self.tr('&Flush Database'), 0, 0, @@ -414,7 +421,7 @@ self.__databaseSqlFlushDatabase) self.actions.append(self.databaseSqlFlushAct) - self.databaseSqlResetSeqAct = E5Action( + self.databaseSqlResetSeqAct = EricAction( self.tr('Reset Sequences'), self.tr('Reset &Sequences'), 0, 0, @@ -431,7 +438,7 @@ self.__databaseSqlResetSequences) self.actions.append(self.databaseSqlResetSeqAct) - self.databaseSqlMigrateAct = E5Action( + self.databaseSqlMigrateAct = EricAction( self.tr('Apply Migration'), self.tr('&Apply Migration'), 0, 0, @@ -448,7 +455,7 @@ self.__databaseSqlMigrate) self.actions.append(self.databaseSqlMigrateAct) - self.databaseSqlMigrateBackwardsAct = E5Action( + self.databaseSqlMigrateBackwardsAct = EricAction( self.tr('Unapply Migration'), self.tr('&Unapply Migration'), 0, 0, @@ -469,7 +476,7 @@ """ Private method to define the tool actions. """ - self.diffSettingsAct = E5Action( + self.diffSettingsAct = EricAction( self.tr('Diff Settings'), self.tr('&Diff Settings'), 0, 0, @@ -483,7 +490,7 @@ self.diffSettingsAct.triggered.connect(self.__diffSettings) self.actions.append(self.diffSettingsAct) - self.runPythonShellAct = E5Action( + self.runPythonShellAct = EricAction( self.tr('Start Python Console'), self.tr('Start &Python Console'), 0, 0, @@ -497,7 +504,7 @@ self.runPythonShellAct.triggered.connect(self.__runPythonShell) self.actions.append(self.runPythonShellAct) - self.testEmailAct = E5Action( + self.testEmailAct = EricAction( self.tr('Send Test Email'), self.tr('Send Test &Email'), 0, 0, @@ -516,7 +523,7 @@ """ Private method to define the testing actions. """ - self.dumpDataAct = E5Action( + self.dumpDataAct = EricAction( self.tr('Dump Data'), self.tr('&Dump Data'), 0, 0, @@ -530,7 +537,7 @@ self.dumpDataAct.triggered.connect(self.__dumpData) self.actions.append(self.dumpDataAct) - self.loadDataAct = E5Action( + self.loadDataAct = EricAction( self.tr('Load Data'), self.tr('&Load Data'), 0, 0, @@ -544,7 +551,7 @@ self.loadDataAct.triggered.connect(self.__loadData) self.actions.append(self.loadDataAct) - self.runTestAct = E5Action( + self.runTestAct = EricAction( self.tr('Run Testsuite'), self.tr('Run &Testsuite'), 0, 0, @@ -558,7 +565,7 @@ self.runTestAct.triggered.connect(self.__runTestSuite) self.actions.append(self.runTestAct) - self.runDeprecationTestAct = E5Action( + self.runDeprecationTestAct = EricAction( self.tr('Run Testsuite (-Wall)'), self.tr('Run Testsuite (-Wall)'), 0, 0, @@ -575,7 +582,7 @@ lambda: self.__runTestSuite(deprecation=True)) self.actions.append(self.runDeprecationTestAct) - self.runTestServerAct = E5Action( + self.runTestServerAct = EricAction( self.tr('Run Testserver'), self.tr('Run Test&server'), 0, 0, @@ -594,7 +601,7 @@ """ Private method to define the authorization actions. """ - self.changePasswordAct = E5Action( + self.changePasswordAct = EricAction( self.tr('Change Password'), self.tr('Change &Password'), 0, 0, @@ -608,7 +615,7 @@ self.changePasswordAct.triggered.connect(self.__changePassword) self.actions.append(self.changePasswordAct) - self.createSuperUserAct = E5Action( + self.createSuperUserAct = EricAction( self.tr('Create Superuser'), self.tr('Create &Superuser'), 0, 0, @@ -626,7 +633,7 @@ """ Private method to define the session actions. """ - self.clearSessionsAct = E5Action( + self.clearSessionsAct = EricAction( self.tr('Clear Sessions'), self.tr('Clear &Sessions'), 0, 0, @@ -644,7 +651,7 @@ """ Private method to define the migration actions. """ - self.showMigrationsAct = E5Action( + self.showMigrationsAct = EricAction( self.tr('Show Migrations'), self.tr('&Show Migrations'), 0, 0, @@ -659,7 +666,7 @@ self.showMigrationsAct.triggered.connect(self.__showMigrationsList) self.actions.append(self.showMigrationsAct) - self.showMigrationsPlanAct = E5Action( + self.showMigrationsPlanAct = EricAction( self.tr('Show Migrations Plan'), self.tr('Show Migrations &Plan'), 0, 0, @@ -674,7 +681,7 @@ self.showMigrationsPlanAct.triggered.connect(self.__showMigrationsPlan) self.actions.append(self.showMigrationsPlanAct) - self.migrateAllAct = E5Action( + self.migrateAllAct = EricAction( self.tr('Apply All Migrations'), self.tr('&Apply All Migrations'), 0, 0, @@ -688,7 +695,7 @@ self.migrateAllAct.triggered.connect(self.__applyAllMigrations) self.actions.append(self.migrateAllAct) - self.migrateSelectedAct = E5Action( + self.migrateSelectedAct = EricAction( self.tr('Apply Selected Migrations'), self.tr('Apply Selected Migrations'), 0, 0, @@ -704,7 +711,7 @@ self.__applySelectedMigrations) self.actions.append(self.migrateSelectedAct) - self.unmigrateAct = E5Action( + self.unmigrateAct = EricAction( self.tr('Unapply Migrations'), self.tr('&Unapply Migrations'), 0, 0, @@ -719,7 +726,7 @@ self.unmigrateAct.triggered.connect(self.__unapplyMigrations) self.actions.append(self.unmigrateAct) - self.makeMigrationsAct = E5Action( + self.makeMigrationsAct = EricAction( self.tr('Make Migrations'), self.tr('&Make Migrations'), 0, 0, @@ -733,7 +740,7 @@ self.makeMigrationsAct.triggered.connect(self.__makeMigrations) self.actions.append(self.makeMigrationsAct) - self.squashMigrationsAct = E5Action( + self.squashMigrationsAct = EricAction( self.tr('Squash Migrations'), self.tr('S&quash Migrations'), 0, 0, @@ -939,9 +946,11 @@ """ Public method to get a reference to the requested menu. - @param name name of the menu (string) - @return reference to the menu (QMenu) or None, if no - menu with the given name exists + @param name name of the menu + @type str + @return reference to the menu or None, if no menu with the given + name exists + @rtype QMenu """ if name in self.__menus: return self.__menus[name] @@ -952,7 +961,8 @@ """ Public method to get the names of all menus. - @return menu names (list of string) + @return menu names + @rtype list of str """ return list(self.__menus.keys()) @@ -980,18 +990,19 @@ """ Public method to add our hook methods. """ - if self.__e5project.getProjectType() == "Django": + if self.__ericProject.getProjectType() == "Django": self.__formsBrowser = ( - e5App().getObject("ProjectBrowser").getProjectBrowser("forms") + ericApp().getObject("ProjectBrowser") + .getProjectBrowser("forms") ) self.__formsBrowser.addHookMethodAndMenuEntry( "newForm", self.newForm, self.tr("New template...")) - self.__e5project.projectLanguageAddedByCode.connect( + self.__ericProject.projectLanguageAddedByCode.connect( self.__projectLanguageAdded) self.__translationsBrowser = ( - e5App().getObject("ProjectBrowser") + ericApp().getObject("ProjectBrowser") .getProjectBrowser("translations")) self.__translationsBrowser.addHookMethodAndMenuEntry( "generateAll", @@ -1027,7 +1038,7 @@ self.__formsBrowser.removeHookMethod("newForm") self.__formsBrowser = None - self.__e5project.projectLanguageAddedByCode.disconnect( + self.__ericProject.projectLanguageAddedByCode.disconnect( self.__projectLanguageAdded) self.__translationsBrowser.removeHookMethod( "generateAll") @@ -1050,15 +1061,16 @@ """ Public method to create a new form. - @param path full directory path for the new form file (string) + @param path full directory path for the new form file + @type str """ - fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( + fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( self.__ui, self.tr("New Form"), path, filter, None, - E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) + EricFileDialog.DontConfirmOverwrite) if not fname: # user aborted or didn't enter a filename @@ -1071,11 +1083,11 @@ fname += ex if os.path.exists(fname): - res = E5MessageBox.yesNo( + res = EricMessageBox.yesNo( self.__ui, self.tr("New Form"), self.tr("The file already exists! Overwrite it?"), - icon=E5MessageBox.Warning) + icon=EricMessageBox.Warning) if not res: # user selected to not overwrite @@ -1103,7 +1115,7 @@ f.close() f.write('</html>\n') except OSError as e: - E5MessageBox.critical( + EricMessageBox.critical( self.__ui, self.tr("New Form"), self.tr("<p>The new form file <b>{0}</b> could not be" @@ -1111,7 +1123,7 @@ .format(fname, str(e))) return - self.__e5project.appendFile(fname) + self.__ericProject.appendFile(fname) self.__formsBrowser.sourceFile.emit(fname) ################################################################## @@ -1131,10 +1143,12 @@ Private method to build all full paths of an executable file from the environment. - @param file filename of the executable (string) + @param file filename of the executable + @type str @return list of full executable names, if the executable file is accessible via the searchpath defined by the PATH environment variable, or an empty list otherwise. + @rtype list of str """ paths = [] @@ -1164,7 +1178,8 @@ """ Public method to get the supported Python variants. - @return list of supported Python variants (list of strings) + @return list of supported Python variants + @rtype list of str """ variants = [] for variant in ['Python3']: @@ -1219,11 +1234,13 @@ Private method to get the path of the virtual environment. @param language Python variant to get the virtual environment - for (string, one of '' or 'Python3') - @return path of the virtual environment (string) + for (one of '' or 'Python3') + @type str + @return path of the virtual environment + @rtype str """ if not language: - language = self.__e5project.getProjectLanguage() + language = self.__ericProject.getProjectLanguage() venvName = ( self.__plugin.getPreferences("VirtualEnvironmentNamePy3") if language == "Python3" else @@ -1249,11 +1266,13 @@ Private method to get the path of the debugger environment. @param language Python variant to get the debugger environment - for (string, one of '' or 'Python3') - @return path of the debugger environment (string) + for (one of '' or 'Python3') + @type str + @return path of the debugger environment + @rtype str """ if not language: - language = self.__e5project.getProjectLanguage() + language = self.__ericProject.getProjectLanguage() debugEnv = self.__getVirtualEnvironment(language) if not debugEnv: if language == "Python3": @@ -1273,11 +1292,13 @@ Private method to build a django-admin.py command. @param language Python variant to get the django-admin.py - command for (string, one of '' or 'Python3') - @return full django-admin.py command (string) + command for (one of '' or 'Python3') + @type str + @return full django-admin.py command + @rtype str """ if not language: - language = self.__e5project.getProjectLanguage() + language = self.__ericProject.getProjectLanguage() virtualEnv = self.__getVirtualEnvironment(language) if virtualEnv: @@ -1321,9 +1342,9 @@ else: if language == "Python3": cmds = ["django-admin3.py", "django-admin3", + "django-admin.py-3.10", + "django-admin.py-3.9", "django-admin.py-3.8", "django-admin.py-3.7", "django-admin.py-3.6", - "django-admin.py-3.5", "django-admin.py-3.4", - "django-admin.py-3.3", "django-admin.py-3.2", ] else: cmds = [] @@ -1340,9 +1361,10 @@ """ Private method to build the Python command. - @return python command (string) + @return python command + @rtype str """ - language = self.__e5project.getProjectLanguage() + language = self.__ericProject.getProjectLanguage() if language == "Python3": venvName = self.__plugin.getPreferences( "VirtualEnvironmentNamePy3") @@ -1366,8 +1388,8 @@ version = self.getDjangoVersionString() url = "https://www.djangoproject.com" - msgBox = E5MessageBox.E5MessageBox( - E5MessageBox.Question, + msgBox = EricMessageBox.EricMessageBox( + EricMessageBox.Question, self.tr("About Django"), self.tr( "<p>Django is a high-level Python Web framework that" @@ -1380,7 +1402,7 @@ "</table></p>" ).format(version, url), modal=True, - buttons=E5MessageBox.Ok) + buttons=EricMessageBox.Ok) msgBox.setIconPixmap(UI.PixmapCache.getPixmap( os.path.join("ProjectDjango", "icons", "django64-{0}".format(self.__iconSuffix)))) @@ -1390,7 +1412,8 @@ """ Public method to get the Django version as a string. - @return Django version (string) + @return Django version + @rtype str """ djangoVersion = "" @@ -1436,7 +1459,8 @@ """ Private method to ask the user for a list of application names. - @return list of application names (list of strings) + @return list of application names + @rtype list of str """ applStr, ok = QInputDialog.getItem( self.__ui, @@ -1482,7 +1506,8 @@ """ Public method to set the most recently used applications entry. - @param applStr applications entry (string) + @param applStr applications entry + @type str """ if applStr in self.__recentApplications: self.__recentApplications.remove(applStr) @@ -1554,11 +1579,12 @@ def getProjectPath(self): """ - Public method to get the path of the eric6 project. + Public method to get the path of the eric7 project. - @return path of the eric6 project (string) + @return path of the eric7 project + @rtype str """ - return self.__e5project.getProjectPath() + return self.__ericProject.getProjectPath() def __showHelpIndex(self): """ @@ -1572,10 +1598,11 @@ """ Private method to check, if the given console is a spawning console. - @param consoleCmd console command (string) + @param consoleCmd console command + @type str @return tuple of two entries giving an indication, if the console - is spawning (boolean) and the (possibly) cleaned console command - (string) + is spawning and the (possibly) cleaned console command + @rtype tuple of (bool, str) """ if consoleCmd and consoleCmd[0] == '@': return (True, consoleCmd[1:]) @@ -1608,20 +1635,20 @@ """ Public slot to finish up the newly generated project. """ - if self.__e5project.getProjectType() == "Django": - ppath = self.__e5project.getProjectPath() + if self.__ericProject.getProjectType() == "Django": + ppath = self.__ericProject.getProjectPath() # get rid of an __init__.py file because it would be in our way initModule = os.path.join(ppath, "__init__.py") if os.path.exists(initModule): - self.__e5project.deleteFile("__init__.py") - self.__e5project.saveProject() + self.__ericProject.deleteFile("__init__.py") + self.__ericProject.saveProject() def startProjectOrApplication(self): """ Public slot to start a new Django project or application. """ - if self.__e5project.getProjectType() == "Django": + if self.__ericProject.getProjectType() == "Django": projectStr = self.tr("Project") applStr = self.tr("Application") selections = ["", projectStr, applStr] @@ -1636,35 +1663,37 @@ if ok and bool(selection): if selection == projectStr: path, projectName = os.path.split( - self.__e5project.getProjectPath()) + self.__ericProject.getProjectPath()) self.__createProject(projectName, path) elif selection == applStr: path, applName = os.path.split( - self.__e5project.getProjectPath()) + self.__ericProject.getProjectPath()) self.__createApplication(applName, path) def __createProject(self, projectName, path): """ Private slot to create a new Django project. - @param projectName name of the new project (string) + @param projectName name of the new project + @type str @param path the directory where the project should be created - (string) - @return flag indicating a successful creation (boolean) + @type str + @return flag indicating a successful creation + @rtype bool """ title = self.tr("Start Django Project") # remove the project directory if it exists already ppath = os.path.join(path, projectName) if os.path.exists(ppath): - okToRemove = E5MessageBox.yesNo( + okToRemove = EricMessageBox.yesNo( self.__ui, title, self.tr("""<p>The Django project path <b>{0}</b> exists""" """ already. Shall it be removed and recreated?""" """</p>""").format(ppath)) if not okToRemove: - E5MessageBox.information( + EricMessageBox.information( self.__ui, title, self.tr("""<p>Please add the files to the eric project""" @@ -1680,7 +1709,7 @@ args.append(self.__getPythonExecutable()) args.append(cmd) else: - E5MessageBox.critical( + EricMessageBox.critical( self.__ui, title, self.tr("""<p>The <b>django-admin.py</b> script is""" @@ -1704,7 +1733,7 @@ if ( os.path.join(path, projectName) == - self.__e5project.getProjectPath() + self.__ericProject.getProjectPath() ): self.__setCurrentSite("") else: @@ -1720,29 +1749,31 @@ self.__ui, self.tr("Start Django Project"), self.tr("Enter the name of the new Django project."), - QLineEdit.Normal) + QLineEdit.EchoMode.Normal) if ok and projectName != "": res = self.__createProject(projectName, - self.__e5project.getProjectPath()) + self.__ericProject.getProjectPath()) if res: # search for new files and add them to the project - sitePath = os.path.join(self.__e5project.getProjectPath(), + sitePath = os.path.join(self.__ericProject.getProjectPath(), projectName) for entry in os.walk(sitePath): for fileName in entry[2]: fullName = os.path.join(entry[0], fileName) - self.__e5project.appendFile(fullName) + self.__ericProject.appendFile(fullName) def __createApplication(self, applName, path, isGlobal=True): """ Private slot to create a new Django application. - @param applName name of the new application (string) + @param applName name of the new application + @type str @param path the directory where the application should be created - (string) + @type str @param isGlobal flag indicating a standalone Django application - (boolean) - @return flag indicating a successful creation (boolean) + @type bool + @return flag indicating a successful creation + @rtype bool """ title = self.tr("Start Django Application") @@ -1759,7 +1790,7 @@ args.append(self.__getPythonExecutable()) args.append(cmd) else: - E5MessageBox.critical( + EricMessageBox.critical( self.__ui, title, self.tr("""<p>The <b>django-admin.py</b> script""" @@ -1793,18 +1824,18 @@ self.tr("Start Global Django Application"), self.tr("Enter the name of the new global Django" " application."), - QLineEdit.Normal) + QLineEdit.EchoMode.Normal) if ok and applName != "": res = self.__createApplication(applName, - self.__e5project.getProjectPath()) + self.__ericProject.getProjectPath()) if res: # search for new files and add them to the project - appPath = os.path.join(self.__e5project.getProjectPath(), + appPath = os.path.join(self.__ericProject.getProjectPath(), applName) for entry in os.walk(appPath): for fileName in entry[2]: fullName = os.path.join(entry[0], fileName) - self.__e5project.appendFile(fullName) + self.__ericProject.appendFile(fullName) def __startLocalApplication(self): """ @@ -1814,7 +1845,7 @@ self.__ui, self.tr("Start Local Django Application"), self.tr("Enter the name of the new local Django application."), - QLineEdit.Normal) + QLineEdit.EchoMode.Normal) if ok and applName != "": res = self.__createApplication(applName, "", False) if res: @@ -1824,7 +1855,7 @@ for entry in os.walk(appPath): for fileName in entry[2]: fullName = os.path.join(entry[0], fileName) - self.__e5project.appendFile(fullName) + self.__ericProject.appendFile(fullName) except DjangoNoSiteSelectedException: return @@ -1836,10 +1867,11 @@ """ Private method to determine the relative path to all manage.py scripts. - @return list of sites (list of strings) + @return list of sites + @rtype list of str """ sites = [] - for file in sorted(self.__e5project.getSources()): + for file in sorted(self.__ericProject.getSources()): if os.path.basename(file) == "manage.py": sites.append(os.path.dirname(file)) return sites @@ -1873,8 +1905,9 @@ """ Private method to calculate the full path of the Django site. + @return path of the site + @rtype str @exception DjangoNoSiteSelectedException raised, if no site is selected - @return path of the site (string) """ if self.__currentSite is None: self.__selectSite() @@ -1882,7 +1915,7 @@ if self.__currentSite is None: raise DjangoNoSiteSelectedException else: - path = os.path.join(self.__e5project.getProjectPath(), + path = os.path.join(self.__ericProject.getProjectPath(), self.__currentSite) return path @@ -1890,7 +1923,8 @@ """ Private slot to set the current site. - @param site name of the site (string) + @param site name of the site + @type str """ self.__currentSite = site if self.__currentSite is None: @@ -1903,9 +1937,9 @@ self.tr('&Current Django project ({0})').format(curSite)) if self.__currentSite is None: - self.__e5project.setTranslationPattern("") + self.__ericProject.setTranslationPattern("") else: - self.__e5project.setTranslationPattern( + self.__ericProject.setTranslationPattern( os.path.join(site, "locale", "%language%", "LC_MESSAGES", "django.po") ) @@ -1914,8 +1948,9 @@ """ Private method to get the name of the current site. + @return name of the site + @rtype str @exception DjangoNoSiteSelectedException raised, if no site is selected - @return name of the site (string) """ if self.__currentSite is None: self.__selectSite() @@ -1964,7 +1999,7 @@ self.__serverProc.start(args[0], args[1:]) serverProcStarted = self.__serverProc.waitForStarted() if not serverProcStarted: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr('Process Generation Error'), self.tr('The Django server could not be started.')) @@ -1975,7 +2010,7 @@ """ if ( self.__serverProc is not None and - self.__serverProc.state() != QProcess.NotRunning + self.__serverProc.state() != QProcess.ProcessState.NotRunning ): self.__serverProc.terminate() QTimer.singleShot(2000, self.__serverProc.kill) @@ -2010,7 +2045,7 @@ if self.__plugin.getPreferences("UseExternalBrowser"): res = QDesktopServices.openUrl(QUrl(url)) if not res: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr('Run Web-Browser'), self.tr('Could not start the web-browser for the' @@ -2154,7 +2189,7 @@ title = self.tr("Flush Database") - res = E5MessageBox.yesNo( + res = EricMessageBox.yesNo( self.__ui, title, self.tr("""Flushing the database will destroy all data.""" @@ -2195,7 +2230,7 @@ self.__adjustWorkingDirectory(args, wd) started, pid = QProcess.startDetached(args[0], args[1:], wd) if not started: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr('Process Generation Error'), self.tr('The Django process could not be started.')) @@ -2208,10 +2243,13 @@ """ Private method to perform an SQL creation function. - @param title dialog title (string) - @param command Django sql... command (string) + @param title dialog title + @type str + @param command Django sql... command + @type str @param requestApps flag indicating to request a list of applications - to work on (boolean) + to work on + @type bool """ try: path = self.__sitePath() @@ -2260,7 +2298,7 @@ Private slot to print the SQL statements for a migration of an application. - @param backwards flag indicating to generate the SQL code to unapply + @param backwards flag indicating to generate the SQL code to revert a migration @type bool """ @@ -2271,7 +2309,7 @@ migrations = self.__getMigrations() if not migrations: - E5MessageBox.information( + EricMessageBox.information( None, self.tr("SQL Migrate"), self.tr("""No migrations available.""")) @@ -2285,7 +2323,7 @@ dlg = DjangoMigrationSelectionDialog(migrations, migrationRequired=True, suffix=self.__iconSuffix) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: app, migration = dlg.getData() args = [] @@ -2355,7 +2393,7 @@ """ migrations = self.__getMigrations() if not migrations: - E5MessageBox.information( + EricMessageBox.information( None, self.tr("Apply Selected Migrations"), self.tr("""No migrations available.""")) @@ -2366,7 +2404,7 @@ ) dlg = DjangoMigrationSelectionDialog(migrations, suffix=self.__iconSuffix) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: app, migration = dlg.getData() self.applyMigrations(app=app, migration=migration) @@ -2407,11 +2445,11 @@ def __unapplyMigrations(self): """ - Private slot to un-apply all migrations of an application. + Private slot to revert all migrations of an application. """ apps = list(sorted(self.__getMigrations().keys())) if not apps: - E5MessageBox.information( + EricMessageBox.information( None, self.tr("Unapply Migrations"), self.tr("""No migrations available.""")) @@ -2476,7 +2514,7 @@ """ from .DjangoMakeMigrationsDialog import DjangoMakeMigrationsDialog dlg = DjangoMakeMigrationsDialog(self.getRecentApplications()) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: apps, migration, dryRun, empty, merge = dlg.getData() if apps: self.setMostRecentApplication(apps) @@ -2533,7 +2571,7 @@ """ migrations = self.__getMigrations() if not migrations: - E5MessageBox.information( + EricMessageBox.information( None, self.tr("Squash Migrations"), self.tr("""No migrations available.""")) @@ -2544,7 +2582,7 @@ ) dlg = DjangoSquashMigrationSelectionDialog( migrations, self, self.__iconSuffix) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: app, start, end, noOptimize, name = dlg.getData() title = self.tr("Squash Migrations") @@ -2585,7 +2623,7 @@ from .DjangoDiffsettingsDataDialog import DjangoDiffsettingsDataDialog dlg = DjangoDiffsettingsDataDialog(self, self.__ui) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: showAll, defaultModule, outputFormat = dlg.getData() args = [] @@ -2628,7 +2666,7 @@ self.__adjustWorkingDirectory(args, wd) started, pid = QProcess.startDetached(args[0], args[1:], wd) if not started: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr('Process Generation Error'), self.tr('The Django process could not be started.')) @@ -2643,7 +2681,7 @@ DjangoSendTestEmailDataDialog ) dlg = DjangoSendTestEmailDataDialog(self.__ui) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: managers, admins, recipients = dlg.getData() args = [] @@ -2717,7 +2755,7 @@ from .DjangoDumpdataDataDialog import DjangoDumpdataDataDialog dlg = DjangoDumpdataDataDialog(self, self.__ui) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: appls, excls, dumpFormat, indent = dlg.getData() args = [] @@ -2758,7 +2796,7 @@ from .DjangoLoaddataDataDialog import DjangoLoaddataDataDialog dlg = DjangoLoaddataDataDialog(self, self.__ui) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: fixtures, excludes, appLabel, ignore = dlg.getData() args = [] @@ -2799,7 +2837,7 @@ dlg = DjangoTestDataDialog( self, self.__plugin.getPreferences("KeepTestDatabase"), self.__ui) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: labels, pattern, tags, excludeTags, keep, reverse = ( dlg.getData()) @@ -2827,7 +2865,7 @@ self.__adjustWorkingDirectory(args, wd) started, pid = QProcess.startDetached(args[0], args[1:], wd) if not started: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr('Process Generation Error'), self.tr('The Django process could not be started.')) @@ -2844,7 +2882,7 @@ DjangoRunTestServerDataDialog ) dlg = DjangoRunTestServerDataDialog(self, self.__ui) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: fixtures = dlg.getData() args = Utilities.parseOptionString(consoleCmd) @@ -2876,7 +2914,7 @@ serverProcStarted = ( self.__testServerProc.waitForStarted()) if not serverProcStarted: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr('Process Generation Error'), self.tr('The Django test server could not be' @@ -2888,7 +2926,7 @@ """ if ( self.__testServerProc is not None and - self.__testServerProc.state() != QProcess.NotRunning + self.__testServerProc.state() != QProcess.ProcessState.NotRunning ): self.__testServerProc.terminate() QTimer.singleShot(2000, self.__testServerProc.kill) @@ -2910,7 +2948,7 @@ self.__ui, self.tr("Change Password"), self.tr("Enter the name of the user:"), - QLineEdit.Normal) + QLineEdit.EchoMode.Normal) if ok and userName != "": args = Utilities.parseOptionString(consoleCmd) args[0] = Utilities.getExecutablePath(args[0]) @@ -2924,7 +2962,7 @@ started, pid = QProcess.startDetached( args[0], args[1:], wd) if not started: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr('Process Generation Error'), self.tr('The Django process could not be' @@ -2947,7 +2985,7 @@ self.__adjustWorkingDirectory(args, wd) started, pid = QProcess.startDetached(args[0], args[1:], wd) if not started: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr('Process Generation Error'), self.tr('The Django process could not be started.')) @@ -2987,12 +3025,14 @@ """ Private method to extract the locale out of a file name. - @param filename name of the file used for extraction (string) - @return extracted locale (string) or None + @param filename name of the file used for extraction + @type str + @return extracted locale or None + @rtype str """ - if self.__e5project.getTranslationPattern(): + if self.__ericProject.getTranslationPattern(): pattern = ( - self.__e5project.getTranslationPattern() + self.__ericProject.getTranslationPattern() .replace("%language%", "(.*?)") ) match = re.search(pattern, filename) @@ -3010,8 +3050,10 @@ """ Private method to normalize a list of file names. - @param filenames list of file names to normalize (list of strings) - @return normalized file names (list of strings) + @param filenames list of file names to normalize + @type list of str + @return normalized file names + @rtype list of str """ nfilenames = [] for filename in filenames: @@ -3026,8 +3068,10 @@ """ Private method to filter a list of file names by site. - @param filenames list of file names to be filtered (list of strings) - @return file names belonging to the current site (list of strings) + @param filenames list of file names to be filtered + @type list of str + @return file names belonging to the current site + @rtype list of str """ site = self.__site() nfilenames = [] @@ -3041,7 +3085,8 @@ """ Private slot handling the addition of a new language. - @param code language code of the new language (string) + @param code language code of the new language + @type str """ title = ( self.tr("Initializing message catalog for '{0}'") @@ -3057,7 +3102,7 @@ try: wd = self.__sitePath() except DjangoNoSiteSelectedException: - E5MessageBox.warning( + EricMessageBox.warning( None, title, self.tr('No current site selected or no site created yet.' @@ -3073,23 +3118,24 @@ dia.exec() langFile = ( - self.__e5project.getTranslationPattern() + self.__ericProject.getTranslationPattern() .replace("%language%", code) ) - self.__e5project.appendFile(langFile) + self.__ericProject.appendFile(langFile) def updateSelectedCatalogs(self, filenames): """ Public method to update the message catalogs. - @param filenames list of file names (list of strings) + @param filenames list of file names + @type list of str """ title = self.tr("Updating message catalogs") try: wd = self.__sitePath() except DjangoNoSiteSelectedException: - E5MessageBox.warning( + EricMessageBox.warning( None, title, self.tr('No current site selected or no site created yet.' @@ -3111,7 +3157,7 @@ argsLists.append(args) if len(argsLists) == 0: - E5MessageBox.warning( + EricMessageBox.warning( None, title, self.tr('No locales detected. Aborting...')) @@ -3129,6 +3175,7 @@ Public method to update the message catalogs keeping obsolete messages. @param filenames list of filenames + @type list of str """ title = self.tr("Updating message catalogs (keeping obsolete" " messages)") @@ -3136,7 +3183,7 @@ try: wd = self.__sitePath() except DjangoNoSiteSelectedException: - E5MessageBox.warning( + EricMessageBox.warning( None, title, self.tr('No current site selected or no site created yet.' @@ -3157,7 +3204,7 @@ argsLists.append(args) if len(argsLists) == 0: - E5MessageBox.warning( + EricMessageBox.warning( None, title, self.tr('No locales detected. Aborting...')) @@ -3175,6 +3222,7 @@ Public method to update the message catalogs. @param filenames list of filenames (not used) + @type list of str """ title = self.tr("Updating message catalogs") @@ -3188,7 +3236,7 @@ try: wd = self.__sitePath() except DjangoNoSiteSelectedException: - E5MessageBox.warning( + EricMessageBox.warning( None, title, self.tr('No current site selected or no site created yet.' @@ -3207,6 +3255,7 @@ Public method to update the message catalogs keeping obsolete messages. @param filenames list of filenames (not used) + @type list of str """ title = self.tr("Updating message catalogs (keeping obsolete" " messages)") @@ -3220,7 +3269,7 @@ try: wd = self.__sitePath() except DjangoNoSiteSelectedException: - E5MessageBox.warning( + EricMessageBox.warning( None, title, self.tr('No current site selected or no site created yet.' @@ -3239,13 +3288,14 @@ Public method to update the message catalogs. @param filenames list of filenames + @type list of str """ title = self.tr("Compiling message catalogs") try: wd = self.__sitePath() except DjangoNoSiteSelectedException: - E5MessageBox.warning( + EricMessageBox.warning( None, title, self.tr('No current site selected or no site created yet.' @@ -3268,7 +3318,7 @@ argsLists.append(args) if len(argsLists) == 0: - E5MessageBox.warning( + EricMessageBox.warning( None, title, self.tr('No locales detected. Aborting...')) @@ -3286,13 +3336,14 @@ for fileName in entry[2]: fullName = os.path.join(entry[0], fileName) if fullName.endswith('.mo'): - self.__e5project.appendFile(fullName) + self.__ericProject.appendFile(fullName) def compileCatalogs(self, filenames): """ Public method to compile the message catalogs. @param filenames list of filenames (not used) + @type list of str """ title = self.tr("Compiling message catalogs") @@ -3306,7 +3357,7 @@ try: wd = self.__sitePath() except DjangoNoSiteSelectedException: - E5MessageBox.warning( + EricMessageBox.warning( None, title, self.tr('No current site selected or no site created yet.' @@ -3325,13 +3376,14 @@ for fileName in entry[2]: fullName = os.path.join(entry[0], fileName) if fullName.endswith('.mo'): - self.__e5project.appendFile(fullName) + self.__ericProject.appendFile(fullName) def openPOEditor(self, poFile): """ Public method to edit the given file in an external .po editor. - @param poFile name of the .po file (string) + @param poFile name of the .po file + @type str """ editor = self.__plugin.getPreferences("TranslationsEditor") if poFile.endswith(".po") and editor: @@ -3341,7 +3393,7 @@ wd = "" started, pid = QProcess.startDetached(editor, [poFile], wd) if not started: - E5MessageBox.critical( + EricMessageBox.critical( None, self.tr('Process Generation Error'), self.tr('The translations editor process ({0}) could' @@ -3366,7 +3418,7 @@ self.__getPythonExecutable(), path, self.getRecentApplications(), self.__plugin.getPreferences("CheckDeployMode"), ) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: deploy, tags, appsStr, settingsFile = dlg.getData() self.__plugin.setPreferences("CheckDeployMode", deploy) if appsStr != "":