ProjectFlask/Project.py

changeset 12
68ee221cd0cb
parent 11
da6ef8ab8268
child 13
ed33cdfca13d
--- a/ProjectFlask/Project.py	Sun Nov 15 19:53:56 2020 +0100
+++ b/ProjectFlask/Project.py	Tue Nov 17 19:49:24 2020 +0100
@@ -59,6 +59,11 @@
         self.__routesDialog = None
         self.__shellProcess = None
         
+        self.__projectData = {
+            "flask": {},
+            "pybabel": {},
+        }
+        
         self.__flaskVersions = {
             "python": "",
             "flask": "",
@@ -432,29 +437,44 @@
         @return full flask command
         @rtype str
         """
-        cmd = "flask"
+        return self.__getFullCommand("flask")
+    
+    def getBabelCommand(self):
+        """
+        Public method to build the Babel command.
         
+        @return full pybabel command
+        @rtype str
+        """
+        return self.__getFullCommand("pybabel")
+    
+    def __getFullCommand(self, command):
+        """
+        Private method to get the full command for a given command name.
+        
+        @param command command name
+        @type str
+        @return full command
+        @rtype str
+        """
         virtualEnv = self.__getVirtualEnvironment()
         if isWindowsPlatform():
             fullCmds = [
-                os.path.join(virtualEnv, "Scripts", cmd + '.exe'),
-                os.path.join(virtualEnv, "bin", cmd + '.exe'),
-                cmd     # fall back to just cmd
+                os.path.join(virtualEnv, "Scripts", command + '.exe'),
+                os.path.join(virtualEnv, "bin", command + '.exe'),
+                command     # fall back to just cmd
             ]
-            for cmd in fullCmds:
-                if os.path.exists(cmd):
-                    break
         else:
             fullCmds = [
-                os.path.join(virtualEnv, "bin", cmd),
-                os.path.join(virtualEnv, "local", "bin", cmd),
-                Utilities.getExecutablePath(cmd),
-                cmd     # fall back to just cmd
+                os.path.join(virtualEnv, "bin", command),
+                os.path.join(virtualEnv, "local", "bin", command),
+                Utilities.getExecutablePath(command),
+                command     # fall back to just cmd
             ]
-            for cmd in fullCmds:
-                if os.path.exists(cmd):
-                    break
-        return cmd
+        for command in fullCmds:
+            if os.path.exists(command):
+                break
+        return command
     
     @pyqtSlot()
     def __flaskInfo(self):
@@ -540,6 +560,57 @@
         
         return workdir, env
     
+    def getData(self, category, key):
+        """
+        Public method to get data stored in the project store.
+        
+        @param category data category
+        @type str
+        @param key data key
+        @type str
+        @return referenced data
+        @rtype any
+        """
+        if category not in self.__projectData:
+            self.__projectData[category] = {}
+        
+        if not self.__projectData[category]:
+            data = self.__e5project.getData(
+                "PROJECTTYPESPECIFICDATA", category)
+            if data is not None:
+                self.__projectData[category] = data
+        
+        data = self.__projectData[category]
+        if key in data:
+            return data[key]
+        else:
+            return None
+    
+    def setData(self, category, key, value):
+        """
+        Public method to store data in the project store.
+        
+        @param category data category
+        @type str
+        @param key data key
+        @type str
+        @param value data to be stored
+        @type any (serializable type)
+        """
+        if category not in self.__projectData:
+            self.__projectData[category] = {}
+        
+        if not self.__projectData[category]:
+            data = self.__e5project.getData(
+                "PROJECTTYPESPECIFICDATA", category)
+            if data is not None:
+                self.__projectData[category] = data
+        
+        self.__projectData[category][key] = value
+        
+        self.__e5project.setData(
+            "PROJECTTYPESPECIFICDATA", category, self.__projectData[category])
+    
     ##################################################################
     ## slots below implement documentation functions
     ##################################################################

eric ide

mercurial