6 """ |
6 """ |
7 Module implementing the PyInstaller interface plug-in. |
7 Module implementing the PyInstaller interface plug-in. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
|
11 try: |
|
12 str = unicode |
|
13 except NameError: |
|
14 pass |
11 |
15 |
12 import os |
16 import os |
13 import platform |
17 import platform |
14 import shutil |
18 import shutil |
15 |
19 |
16 from PyQt5.QtCore import pyqtSlot, QObject, QCoreApplication, QTranslator |
20 from PyQt5.QtCore import pyqtSlot, QObject, QCoreApplication, QTranslator, \ |
|
21 QProcess |
17 from PyQt5.QtWidgets import QDialog |
22 from PyQt5.QtWidgets import QDialog |
18 |
23 |
19 from E5Gui import E5MessageBox |
24 from E5Gui import E5MessageBox |
20 from E5Gui.E5Action import E5Action |
25 from E5Gui.E5Action import E5Action |
21 from E5Gui.E5Application import e5App |
26 from E5Gui.E5Application import e5App |
176 exe = os.path.join(directory, pyinstallerScript) |
181 exe = os.path.join(directory, pyinstallerScript) |
177 if os.access(exe, os.X_OK): |
182 if os.access(exe, os.X_OK): |
178 exes.append(exe) |
183 exes.append(exe) |
179 |
184 |
180 # step 2: determine the Python variant |
185 # step 2: determine the Python variant |
181 if Utilities.isMacPlatform(): |
|
182 checkStrings = ["Python.framework/Versions/3".lower(), |
|
183 "python3"] |
|
184 else: |
|
185 checkStrings = ["python3"] |
|
186 |
|
187 _exePy2 = set() |
186 _exePy2 = set() |
188 _exePy3 = set() |
187 _exePy3 = set() |
|
188 versionArgs = ["-c", "import sys; print(sys.version_info[0])"] |
189 for exe in exes: |
189 for exe in exes: |
190 try: |
190 try: |
191 f = open(exe, "r") |
191 f = open(exe, "r") |
192 line0 = f.readline() |
192 line0 = f.readline() |
193 for checkStr in checkStrings: |
193 program = line0.replace("#!", "").strip() |
194 if checkStr in line0.lower(): |
194 process = QProcess() |
195 _exePy3.add(exe) |
195 process.start(program, versionArgs) |
196 break |
196 process.waitForFinished(5000) |
|
197 # get a QByteArray of the output |
|
198 versionBytes = process.readAllStandardOutput() |
|
199 versionStr = str(versionBytes, encoding='utf-8').strip() |
|
200 if versionStr == "3": |
|
201 _exePy3.add(exe) |
197 else: |
202 else: |
198 _exePy2.add(exe) |
203 _exePy2.add(exe) |
199 finally: |
204 finally: |
200 f.close() |
205 f.close() |
201 |
206 |
202 executables = _exePy3 if majorVersion == 3 else _exePy2 |
207 executables = _exePy3 if majorVersion == 3 else _exePy2 |
203 |
208 |
454 |
459 |
455 # check if all files saved and errorfree before continue |
460 # check if all files saved and errorfree before continue |
456 if not project.checkAllScriptsDirty(reportSyntaxErrors=True): |
461 if not project.checkAllScriptsDirty(reportSyntaxErrors=True): |
457 return |
462 return |
458 |
463 |
459 # TODO: implement pyi-makespec |
464 from PyInstaller.PyInstallerConfigDialog import PyInstallerConfigDialog |
|
465 params = project.getData('PACKAGERSPARMS', "PYINSTALLER") |
|
466 dlg = PyInstallerConfigDialog(project, executables, params, |
|
467 mode="spec") |
|
468 if dlg.exec_() == QDialog.Accepted: |
|
469 args, params, script = dlg.generateParameters() |
|
470 project.setData('PACKAGERSPARMS', "PYINSTALLER", params) |
|
471 |
|
472 # now do the call |
|
473 from PyInstaller.PyInstallerExecDialog import PyInstallerExecDialog |
|
474 dia = PyInstallerExecDialog("pyinstaller") |
|
475 dia.show() |
|
476 res = dia.start(args, params, project, script) |
|
477 if res: |
|
478 dia.exec_() |
460 |
479 |
461 @pyqtSlot() |
480 @pyqtSlot() |
462 def __pyinstallerCleanup(self): |
481 def __pyinstallerCleanup(self): |
463 """ |
482 """ |
464 Private slot to remove the directories created by pyinstaller. |
483 Private slot to remove the directories created by pyinstaller. |