825 """ |
825 """ |
826 if self.__serverProc is not None: |
826 if self.__serverProc is not None: |
827 self.__serverProcFinished() |
827 self.__serverProcFinished() |
828 self.__setCurrentSite(None) |
828 self.__setCurrentSite(None) |
829 |
829 |
830 def __getVirtualEnvironment(self): |
830 def __getExecutablePaths(self, file): |
|
831 """ |
|
832 Private method to build all full path of an executable file from |
|
833 the environment. |
|
834 |
|
835 @param file filename of the executable (string) |
|
836 @return list of full executable names, if the executable file is accessible |
|
837 via the searchpath defined by the PATH environment variable, or an |
|
838 empty list otherwise. |
|
839 """ |
|
840 paths = [] |
|
841 |
|
842 if os.path.isabs(file): |
|
843 if os.access(file, os.X_OK): |
|
844 return [file] |
|
845 else: |
|
846 return [] |
|
847 |
|
848 cur_path = os.path.join(os.curdir, file) |
|
849 if os.path.exists(cur_path): |
|
850 if os.access(cur_path, os.X_OK): |
|
851 paths.append(cur_path) |
|
852 |
|
853 path = os.getenv('PATH') |
|
854 |
|
855 # environment variable not defined |
|
856 if path is not None: |
|
857 dirs = path.split(os.pathsep) |
|
858 for dir in dirs: |
|
859 exe = os.path.join(dir, file) |
|
860 if os.access(exe, os.X_OK) and exe not in paths: |
|
861 paths.append(exe) |
|
862 |
|
863 return paths |
|
864 |
|
865 def supportedPythonVariants(self): |
|
866 """ |
|
867 Public method to get the supported Python variants. |
|
868 |
|
869 @return list of supported Python variants (list of strings) |
|
870 """ |
|
871 variants = [] |
|
872 for variant in 'Python2', 'Python3': |
|
873 virtEnv = self.__getVirtualEnvironment(variant) |
|
874 if virtEnv: |
|
875 if self.__getDjangoAdminCommand(variant): |
|
876 variants.append(variant) |
|
877 else: |
|
878 cmd = self.__getDjangoAdminCommand() |
|
879 if isWindowsPlatform(): |
|
880 if variant.lower() in cmd.lower(): |
|
881 variants.append(variant) |
|
882 else: |
|
883 try: |
|
884 fullCmds = Utilities.getExecutablePaths(cmd) |
|
885 except AttributeError: |
|
886 fullCmds = self.__getExecutablePaths(cmd) |
|
887 for fullCmd in fullCmds: |
|
888 try: |
|
889 f = open(fullCmd, 'r', encoding='utf-8') |
|
890 l0 = f.readline() |
|
891 f.close() |
|
892 except (IOError, OSError): |
|
893 l0 = "" |
|
894 if variant.lower() in l0.lower() or \ |
|
895 "{0}.".format(variant[-1]) in l0 or \ |
|
896 (variant == "Python2" and \ |
|
897 "python3" not in l0.lower() and \ |
|
898 "python" in l0.lower()): |
|
899 variants.append(variant) |
|
900 break |
|
901 |
|
902 return variants |
|
903 |
|
904 def __getVirtualEnvironment(self, language=""): |
831 """ |
905 """ |
832 Private method to get the path of the virtual environment. |
906 Private method to get the path of the virtual environment. |
833 |
907 |
|
908 @param language Python variant to get the virtual environment |
|
909 for (string, one of '', 'Python2' or 'Python3') |
834 @return path of the virtual environment (string) |
910 @return path of the virtual environment (string) |
835 """ |
911 """ |
836 language = self.__e5project.getProjectLanguage() |
912 if not language: |
|
913 language = self.__e5project.getProjectLanguage() |
837 if language == "Python3": |
914 if language == "Python3": |
838 virtEnv = self.__plugin.getPreferences("VirtualEnvironmentPy3") |
915 virtEnv = self.__plugin.getPreferences("VirtualEnvironmentPy3") |
839 elif language == "Python2": |
916 elif language == "Python2": |
840 virtEnv = self.__plugin.getPreferences("VirtualEnvironmentPy2") |
917 virtEnv = self.__plugin.getPreferences("VirtualEnvironmentPy2") |
841 else: |
918 else: |
842 virtEnv = "" |
919 virtEnv = "" |
843 if virtEnv and not os.path.exists(virtEnv): |
920 if virtEnv and not os.path.exists(virtEnv): |
844 virtEnv = "" |
921 virtEnv = "" |
845 return virtEnv |
922 return virtEnv |
846 |
923 |
847 def __getDjangoAdminCommand(self): |
924 def __getDjangoAdminCommand(self, language=""): |
848 """ |
925 """ |
849 Public method to build a django-admin.py command. |
926 Private method to build a django-admin.py command. |
850 |
927 |
851 @param cmd command (string) |
928 @param language Python variant to get the django-admin.py |
|
929 command for (string, one of '', 'Python2' or 'Python3') |
852 @return full django-admin.py command (string) |
930 @return full django-admin.py command (string) |
853 """ |
931 """ |
854 virtualEnv = self.__getVirtualEnvironment() |
932 virtualEnv = self.__getVirtualEnvironment(language) |
855 if virtualEnv: |
933 if virtualEnv: |
856 if isWindowsPlatform(): |
934 if isWindowsPlatform(): |
857 cmd = os.path.join(virtualEnv, "Scripts", "django-admin.py") |
935 cmd = os.path.join(virtualEnv, "Scripts", "django-admin.py") |
858 else: |
936 else: |
859 cmds = [ |
937 cmds = [ |