Tue, 16 Jan 2018 14:53:10 +0100
Implemented support for the programs dialog.
1
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

1  # * coding: utf8 * 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

2  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

3  # Copyright (c) 2018 Detlev Offenbach <detlev@dieoffenbachs.de> 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

4  # 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

5  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

6  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

7  Module implementing the PyInstaller interface plugin. 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

8  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

9  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

10  from __future__ import unicode_literals 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

11  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

12  import os 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

13  import platform 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

14  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

15  from PyQt5.QtCore import QObject, QCoreApplication 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

16  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

17  import Utilities 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

18  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

19  # StartOfHeader 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

20  name = "PyInstaller Plugin" 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

21  author = "Detlev Offenbach <detlev@dieoffenbachs.de>" 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

22  autoactivate = True 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

23  deactivateable = True 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

24  version = "0.1.0" 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

25  className = "PyInstallerPlugin" 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

26  packageName = "PyInstaller" 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

27  shortDescription = "Show dialogs to configure and execute PyInstaller." 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

28  longDescription = ( 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

29  """This plugin implements dialogs to configure and execute PyInstaller""" 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

30  """ for an eric project. PyInstaller must be available or must be""" 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

31  """ installed via 'pip install PyInstaller'.""" 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

32  ) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

33  needsRestart = False 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

34  pyqtApi = 2 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

35  python2Compatible = True 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

36  # EndOfHeader 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

37  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

38  error = "" 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

39  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

40  exePy2 = [] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

41  exePy3 = [] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

42  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

43  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

44  def exeDisplayDataList(): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

45  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

46  Module function to support the display of some executable info. 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

47  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

48  @return list of dictionaries containing the data to query the presence of 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

49  the executable 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

50  @rtype list of dict 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

51  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

52  dataList = [] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

53  data = { 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

54  "programEntry": True, 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

55  "header": QCoreApplication.translate( 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

56  "PyInstallerPlugin", "Packagers  PyInstaller"), 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

57  "exe": "dummyExe", 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

58  "versionCommand": "version", 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

59  "versionStartsWith": "dummyExe", 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

60  "versionPosition": 1, 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

61  "version": "", 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

62  "versionCleanup": None, 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

63  "versionRe": "^\d", 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

64  } 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

65  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

66  if _checkProgram(): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

67  for exePath in (exePy2 + exePy3): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

68  data["exe"] = exePath 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

69  data["versionStartsWith"] = "" 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

70  dataList.append(data.copy()) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

71  else: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

72  dataList.append(data) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

73  return dataList 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

74  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

75  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

76  def _findExecutable(majorVersion): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

77  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

78  Restricted function to determine the names of the executables. 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

79  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

80  @param majorVersion major python version 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

81  @type int 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

82  @return names of the executables 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

83  @rtype list of str 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

84  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

85  # Determine Python Version 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

86  if majorVersion == 3: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

87  minorVersions = range(10) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

88  elif majorVersion == 2: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

89  minorVersions = [7] # PyInstaller supports just Python 2.7 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

90  else: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

91  return [] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

92  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

93  executables = set() 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

94  if Utilities.isWindowsPlatform(): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

95  # 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

96  # Windows 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

97  # 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

98  try: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

99  import winreg 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

100  except ImportError: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

101  import _winreg as winreg # __IGNORE_WARNING__ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

102  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

103  def getExePath(branch, access, versionStr): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

104  exes = [] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

105  try: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

106  software = winreg.OpenKey(branch, 'Software', 0, access) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

107  python = winreg.OpenKey(software, 'Python', 0, access) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

108  pcore = winreg.OpenKey(python, 'PythonCore', 0, access) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

109  version = winreg.OpenKey(pcore, versionStr, 0, access) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

110  installpath = winreg.QueryValue(version, 'InstallPath') 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

111  # Look for pyinstaller.exe 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

112  exe = os.path.join(installpath, 'Scripts', 'pyinstaller.exe') 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

113  if os.access(exe, os.X_OK): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

114  exes.append(exe) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

115  # Look for pyimakespec.exe 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

116  exe = os.path.join(installpath, 'Scripts', 'pyimakespec.exe') 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

117  if os.access(exe, os.X_OK): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

118  exes.append(exe) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

119  except (WindowsError, OSError): # __IGNORE_WARNING__ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

120  pass 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

121  return exes 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

122  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

123  for minorVersion in minorVersions: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

124  versionStr = '{0}.{1}'.format(majorVersion, minorVersion) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

125  exePath = getExePath( 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

126  winreg.HKEY_CURRENT_USER, 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

127  winreg.KEY_WOW64_32KEY  winreg.KEY_READ, versionStr) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

128  if exePath is not None: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

129  executables.add(exePath) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

130  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

131  exePath = getExePath( 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

132  winreg.HKEY_LOCAL_MACHINE, 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

133  winreg.KEY_WOW64_32KEY  winreg.KEY_READ, versionStr) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

134  if exePath is not None: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

135  executables.add(exePath) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

136  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

137  # Even on Intel 64bit machines it's 'AMD64' 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

138  if platform.machine() == 'AMD64': 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

139  exePath = getExePath( 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

140  winreg.HKEY_CURRENT_USER, 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

141  winreg.KEY_WOW64_64KEY  winreg.KEY_READ, versionStr) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

142  if exePath is not None: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

143  executables.add(exePath) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

144  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

145  exePath = getExePath( 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

146  winreg.HKEY_LOCAL_MACHINE, 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

147  winreg.KEY_WOW64_64KEY  winreg.KEY_READ, versionStr) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

148  if exePath is not None: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

149  executables.add(exePath) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

150  else: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

151  # 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

152  # Linux, Unix ... 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

153  pyinstallerScripts = ['pyinstaller', 'pyimakespec'] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

154  ## scriptSuffixes = [""] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

155  ## for minorVersion in minorVersions: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

156  ## scriptSuffixes.append( 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

157  ## "python{0}.{1}".format(majorVersion, minorVersion)) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

158  # There could be multiple pyinstaller executables in the path 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

159  # e.g. for different python variants 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

160  path = Utilities.getEnvironmentEntry('PATH') 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

161  # environment variable not defined 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

162  if path is None: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

163  return [] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

164  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

165  # step 1: determine possible candidates 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

166  exes = [] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

167  dirs = path.split(os.pathsep) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

168  for directory in dirs: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

169  for pyinstallerScript in pyinstallerScripts: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

170  exe = os.path.join(directory, pyinstallerScript) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

171  if os.access(exe, os.X_OK): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

172  exes.append(exe) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

173  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

174  # step 2: determine the Python variant 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

175  if Utilities.isMacPlatform(): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

176  checkStrings = ["Python.framework/Versions/3".lower(), 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

177  "python3"] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

178  else: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

179  checkStrings = ["python3"] 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

180  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

181  _exePy2 = set() 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

182  _exePy3 = set() 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

183  for exe in exes: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

184  try: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

185  f = open(exe, "r") 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

186  line0 = f.readline() 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

187  for checkStr in checkStrings: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

188  if checkStr in line0.lower(): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

189  _exePy3.add(exe) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

190  break 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

191  else: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

192  _exePy2.add(exe) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

193  finally: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

194  f.close() 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

195  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

196  executables = _exePy3 if majorVersion == 3 else _exePy2 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

197  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

198  # sort items, the probably newest topmost 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

199  executables = list(executables) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

200  executables.sort(reverse=True) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

201  return executables 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

202  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

203  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

204  def _checkProgram(): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

205  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

206  Restricted function to check the availability of pyinstaller. 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

207  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

208  @return flag indicating availability (boolean) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

209  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

210  global error, exePy2, exePy3 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

211  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

212  exePy2 = _findExecutable(2) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

213  exePy3 = _findExecutable(3) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

214  if (exePy2 + exePy3) == []: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

215  if Utilities.isWindowsPlatform(): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

216  error = QCoreApplication.translate( 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

217  "PyInstallerPlugin", 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

218  "The pyinstaller.exe executable could not be found." 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

219  ) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

220  else: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

221  error = QCoreApplication.translate( 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

222  "PyInstallerPlugin", 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

223  "The pyinstaller executable could not be found." 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

224  ) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

225  return False 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

226  else: 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

227  return True 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

228  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

229  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

230  class PyInstallerPlugin(QObject): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

231  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

232  Class documentation goes here. 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

233  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

234  def __init__(self, ui): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

235  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

236  Constructor 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

237  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

238  @param ui reference to the user interface object (UI.UserInterface) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

239  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

240  super(PyInstallerPlugin, self).__init__(ui) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

241  self.__ui = ui 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

242  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

243  def activate(self): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

244  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

245  Public method to activate this plugin. 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

246  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

247  @return tuple of None and activation status (boolean) 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

248  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

249  global error 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

250  error = "" # clear previous error 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

251  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

252  return None, True 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

253  
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

254  def deactivate(self): 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

255  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

256  Public method to deactivate this plugin. 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

257  """ 
f7788bc8c08d
Implemented support for the programs dialog.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
0
diff
changeset

258  pass 