552 @type bool |
552 @type bool |
553 @return tuple containing the working directory and a prepared |
553 @return tuple containing the working directory and a prepared |
554 environment object to be used with QProcess |
554 environment object to be used with QProcess |
555 @rtype tuple of (str, QProcessEnvironment) |
555 @rtype tuple of (str, QProcessEnvironment) |
556 """ |
556 """ |
|
557 workdir, app = self.getApplication() |
|
558 env = QProcessEnvironment.systemEnvironment() |
|
559 env.insert("FLASK_APP", app) |
|
560 if development: |
|
561 env.insert("FLASK_ENV", "development") |
|
562 |
|
563 return workdir, env |
|
564 |
|
565 def getApplication(self): |
|
566 """ |
|
567 Public method to determine the application name and the respective |
|
568 working directory. |
|
569 |
|
570 @return tuple containing the working directory and the application name |
|
571 @rtype tuple of (str, str) |
|
572 """ |
557 mainScript = self.__e5project.getMainScript(normalized=True) |
573 mainScript = self.__e5project.getMainScript(normalized=True) |
558 if not mainScript: |
574 if not mainScript: |
559 E5MessageBox.critical( |
575 E5MessageBox.critical( |
560 self.__ui, |
576 self.__ui, |
561 self.tr("Prepare Environment"), |
577 self.tr("Prepare Environment"), |
566 scriptPath, scriptName = os.path.split(mainScript) |
582 scriptPath, scriptName = os.path.split(mainScript) |
567 if scriptName == "__init__.py": |
583 if scriptName == "__init__.py": |
568 workdir, app = os.path.split(scriptPath) |
584 workdir, app = os.path.split(scriptPath) |
569 else: |
585 else: |
570 workdir, app = scriptPath, scriptName |
586 workdir, app = scriptPath, scriptName |
571 |
587 return workdir, app |
572 env = QProcessEnvironment.systemEnvironment() |
|
573 env.insert("FLASK_APP", app) |
|
574 if development: |
|
575 env.insert("FLASK_ENV", "development") |
|
576 |
|
577 return workdir, env |
|
578 |
588 |
579 def getData(self, category, key): |
589 def getData(self, category, key): |
580 """ |
590 """ |
581 Public method to get data stored in the project store. |
591 Public method to get data stored in the project store. |
582 |
592 |
796 dlg = PyBabelConfigDialog(config) |
806 dlg = PyBabelConfigDialog(config) |
797 if dlg.exec() == QDialog.Accepted: |
807 if dlg.exec() == QDialog.Accepted: |
798 config = dlg.getConfiguration() |
808 config = dlg.getConfiguration() |
799 self.setData("pybabel", "", config) |
809 self.setData("pybabel", "", config) |
800 |
810 |
801 if not os.path.exists(config["configFile"]): |
811 cfgFileName = self.__e5project.getAbsoluteUniversalPath( |
802 self.__createBabelCfg(config["configFile"]) |
812 config["configFile"]) |
|
813 if not os.path.exists(cfgFileName): |
|
814 self.__createBabelCfg(cfgFileName) |
|
815 |
|
816 def __ensurePybabelConfigured(self): |
|
817 """ |
|
818 Private method to ensure, that PyBabel has been configured. |
|
819 |
|
820 @return flag indicating successful configuration |
|
821 @rtype bool |
|
822 """ |
|
823 config = self.getData("pybabel", "") |
|
824 if not config: |
|
825 self.__configurePybabel() |
|
826 return True |
|
827 |
|
828 configFileName = self.getData("pybabel", "configFile") |
|
829 if configFileName: |
|
830 cfgFileName = self.__e5project.getAbsoluteUniversalPath( |
|
831 configFileName) |
|
832 if os.path.exists(cfgFileName): |
|
833 return True |
|
834 else: |
|
835 return self.__createBabelCfg(cfgFileName) |
|
836 |
|
837 return False |
803 |
838 |
804 def __createBabelCfg(self, configFile): |
839 def __createBabelCfg(self, configFile): |
805 """ |
840 """ |
806 Private method to create a template pybabel configuration file. |
841 Private method to create a template pybabel configuration file. |
807 """ |
842 |
808 template = ( |
843 @return flag indicating successful configuration file creation |
809 "[python: {0}/**.py]\n" |
844 @rtype bool |
810 "[jinja2: {0}/templates/**.html]\n" |
845 """ |
811 "extensions=jinja2.ext.autoescape,jinja2.ext.with_\n" |
846 _, app = self.getApplication() |
812 ) |
847 if app.endswith(".py"): |
813 # TODO: determine app name and write file |
848 template = ( |
|
849 "[python: {0}]\n" |
|
850 "[jinja2: templates/**.html]\n" |
|
851 "extensions=jinja2.ext.autoescape,jinja2.ext.with_\n" |
|
852 ) |
|
853 else: |
|
854 template = ( |
|
855 "[python: {0}/**.py]\n" |
|
856 "[jinja2: {0}/templates/**.html]\n" |
|
857 "extensions=jinja2.ext.autoescape,jinja2.ext.with_\n" |
|
858 ) |
|
859 try: |
|
860 with open(configFile, "w") as f: |
|
861 f.write(template.format(app)) |
|
862 self.__e5project.appendFile(configFile) |
|
863 E5MessageBox.information( |
|
864 None, |
|
865 self.tr("Generate PyBabel Configuration File"), |
|
866 self.tr("""The PyBabel configuration file was created.""" |
|
867 """ Please edit it to adjust the entries as""" |
|
868 """ required.""") |
|
869 ) |
|
870 return True |
|
871 except EnvironmentError as err: |
|
872 E5MessageBox.warning( |
|
873 None, |
|
874 self.tr("Generate PyBabel Configuration File"), |
|
875 self.tr("""<p>The PyBabel Configuration File could not be""" |
|
876 """ generated.</p><p>Reason: {0}</p>""") |
|
877 .format(str(err)) |
|
878 ) |
|
879 return False |
814 |
880 |
815 def __projectLanguageAdded(self, code): |
881 def __projectLanguageAdded(self, code): |
816 # TODO: implement this with pybabel ... |
882 # TODO: implement this with pybabel ... |
817 pass |
883 pass |
818 |
884 |