Cleanup of EXE Maker. Biggest potential impact is the --clean flag when calling pyinstaller
This commit is contained in:
parent
1c74af8d5d
commit
cb38f818e1
|
@ -1,14 +1,13 @@
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
import subprocess
|
import subprocess
|
||||||
from shutil import copyfile
|
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
'''
|
'''
|
||||||
Make a "Windows os" executable with PyInstaller
|
Make a "Windows os" executable with PyInstaller
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def Launcher():
|
def main():
|
||||||
sg.theme('LightGreen')
|
sg.theme('LightGreen')
|
||||||
|
|
||||||
layout = [[sg.Text('PyInstaller EXE Creator', font='Any 15')],
|
layout = [[sg.Text('PyInstaller EXE Creator', font='Any 15')],
|
||||||
|
@ -18,16 +17,11 @@ def Launcher():
|
||||||
sg.FileBrowse(file_types=(("Icon Files", "*.ico"),))],
|
sg.FileBrowse(file_types=(("Icon Files", "*.ico"),))],
|
||||||
[sg.Frame('Output', font='Any 15', layout=[
|
[sg.Frame('Output', font='Any 15', layout=[
|
||||||
[sg.Output(size=(65, 15), font='Courier 10')]])],
|
[sg.Output(size=(65, 15), font='Courier 10')]])],
|
||||||
[sg.ReadFormButton('Make EXE', bind_return_key=True),
|
[sg.Button('Make EXE', bind_return_key=True),
|
||||||
sg.SimpleButton('Quit', button_color=('white', 'firebrick3')), ]]
|
sg.Button('Quit', button_color=('white', 'firebrick3')) ],
|
||||||
|
[sg.Text('Made with PySimpleGUI (www.PySimpleGUI.org)', auto_size_text=True, font='Courier 8')]]
|
||||||
window = sg.Window('PySimpleGUI EXE Maker',
|
|
||||||
layout,
|
|
||||||
auto_size_text=False,
|
|
||||||
auto_size_buttons=False,
|
|
||||||
default_element_size=(20, 1,),
|
|
||||||
text_justification='right')
|
|
||||||
|
|
||||||
|
window = sg.Window('PySimpleGUI EXE Maker', layout, auto_size_text=False, auto_size_buttons=False, default_element_size=(20,1), text_justification='right')
|
||||||
# ---===--- Loop taking in user input --- #
|
# ---===--- Loop taking in user input --- #
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
@ -44,39 +38,47 @@ def Launcher():
|
||||||
dispath_option = '--distpath "{}"'.format(source_path)
|
dispath_option = '--distpath "{}"'.format(source_path)
|
||||||
specpath_option = '--specpath "{}"'.format(source_path)
|
specpath_option = '--specpath "{}"'.format(source_path)
|
||||||
folder_to_remove = os.path.join(source_path, source_filename[:-3])
|
folder_to_remove = os.path.join(source_path, source_filename[:-3])
|
||||||
file_to_remove = os.path.join(
|
file_to_remove = os.path.join(source_path, source_filename[:-3]+'.spec')
|
||||||
source_path, source_filename[:-3]+'.spec')
|
command_line = 'pyinstaller -wF --clean "{}" {} {} {} {}'.format(source_file, icon_option, workpath_option, dispath_option, specpath_option)
|
||||||
command_line = 'pyinstaller -wF --clean "{}" {} {} {} {}'.format(
|
|
||||||
source_file, icon_option, workpath_option, dispath_option, specpath_option)
|
|
||||||
|
|
||||||
if event == 'Make EXE':
|
if event == 'Make EXE':
|
||||||
try:
|
try:
|
||||||
print(command_line)
|
print(command_line)
|
||||||
print(
|
print('Making EXE...the program has NOT locked up...')
|
||||||
'Making EXE...the program has NOT locked up...')
|
|
||||||
window.refresh()
|
window.refresh()
|
||||||
# print('Running command {}'.format(command_line))
|
# print('Running command {}'.format(command_line))
|
||||||
runCommand(command_line)
|
out, err = runCommand(command_line, window=window)
|
||||||
shutil.rmtree(folder_to_remove)
|
shutil.rmtree(folder_to_remove)
|
||||||
os.remove(file_to_remove)
|
os.remove(file_to_remove)
|
||||||
print('**** DONE ****')
|
print('**** DONE ****')
|
||||||
except:
|
except:
|
||||||
sg.popup_error('Something went wrong')
|
sg.PopupError('Something went wrong', 'close this window and copy command line from text printed out in main window','Here is the output from the run', out)
|
||||||
|
print('Copy and paste this line into the command prompt to manually run PyInstaller:\n\n', command_line)
|
||||||
|
|
||||||
|
|
||||||
def runCommand(cmd, timeout=None):
|
def runCommand(cmd, timeout=None, window=None):
|
||||||
"""
|
""" run shell command
|
||||||
run shell command
|
|
||||||
|
|
||||||
@param cmd: command to execute
|
@param cmd: command to execute
|
||||||
@param timeout: timeout for command execution
|
@param timeout: timeout for command execution
|
||||||
|
|
||||||
@return: (return code from command, command output)
|
@return: (return code from command, command output)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
out, err = p.communicate()
|
output = ''
|
||||||
p.wait(timeout)
|
for line in p.stdout:
|
||||||
return (out, err)
|
line = line.decode(errors='replace' if (sys.version_info) < (3, 5)
|
||||||
|
else 'backslashreplace').rstrip()
|
||||||
|
output += line
|
||||||
|
print(line)
|
||||||
|
if window:
|
||||||
|
window.Refresh()
|
||||||
|
|
||||||
|
retval = p.wait(timeout)
|
||||||
|
|
||||||
|
return (retval, output)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
Launcher()
|
main()
|
||||||
|
|
|
@ -1,35 +1,36 @@
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
import subprocess
|
import subprocess
|
||||||
from shutil import copyfile
|
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
'''
|
||||||
|
Make a "Windows os" executable with PyInstaller
|
||||||
|
'''
|
||||||
|
|
||||||
def Launcher():
|
def main():
|
||||||
sg.ChangeLookAndFeel('LightGreen')
|
sg.theme('LightGreen')
|
||||||
|
|
||||||
layout = [[sg.T('PyInstaller EXE Creator', font='Any 15')],
|
layout = [[sg.Text('PyInstaller EXE Creator', font='Any 15')],
|
||||||
[sg.T('Source Python File'), sg.In(key='_sourcefile_', size=(45,1)), sg.FileBrowse(file_types=(("Python Files", "*.py"),))],
|
[sg.Text('Source Python File'), sg.Input(key='-sourcefile-', size=(45, 1)),
|
||||||
[sg.T('Icon File'), sg.In(key='_iconfile_', size=(45,1)), sg.FileBrowse(file_types=(("Icon Files", "*.ico"),))],
|
sg.FileBrowse(file_types=(("Python Files", "*.py"),))],
|
||||||
[sg.Frame('Output', font='Any 15',layout= [[sg.Output(size=(85, 15), font='Courier 10')]])],
|
[sg.Text('Icon File'), sg.Input(key='-iconfile-', size=(45, 1)),
|
||||||
[sg.ReadFormButton('Make EXE',bind_return_key=True),
|
sg.FileBrowse(file_types=(("Icon Files", "*.ico"),))],
|
||||||
sg.SimpleButton('Quit', button_color=('white','firebrick3')),]]
|
[sg.Frame('Output', font='Any 15', layout=[
|
||||||
|
[sg.Output(size=(65, 15), font='Courier 10')]])],
|
||||||
window = sg.Window('PySimpleGUI EXE Maker',
|
[sg.Button('Make EXE', bind_return_key=True),
|
||||||
auto_size_text=False,
|
sg.Button('Quit', button_color=('white', 'firebrick3')) ],
|
||||||
auto_size_buttons=False,
|
[sg.Text('Made with PySimpleGUI (www.PySimpleGUI.org)', auto_size_text=True, font='Courier 8')]]
|
||||||
default_element_size=(20,1),
|
|
||||||
text_justification='right')
|
|
||||||
|
|
||||||
window.Layout(layout)
|
|
||||||
|
|
||||||
|
window = sg.Window('PySimpleGUI EXE Maker', layout, auto_size_text=False, auto_size_buttons=False, default_element_size=(20,1), text_justification='right')
|
||||||
# ---===--- Loop taking in user input --- #
|
# ---===--- Loop taking in user input --- #
|
||||||
while True:
|
while True:
|
||||||
(button, values) = window.Read()
|
|
||||||
if button in ('Quit', None):
|
|
||||||
break # exit button clicked
|
|
||||||
|
|
||||||
source_file = values['_sourcefile_']
|
event, values = window.read()
|
||||||
icon_file = values['_iconfile_']
|
if event in ('Exit', 'Quit', None):
|
||||||
|
break
|
||||||
|
|
||||||
|
source_file = values['-sourcefile-']
|
||||||
|
icon_file = values['-iconfile-']
|
||||||
|
|
||||||
icon_option = '-i "{}"'.format(icon_file) if icon_file else ''
|
icon_option = '-i "{}"'.format(icon_file) if icon_file else ''
|
||||||
source_path, source_filename = os.path.split(source_file)
|
source_path, source_filename = os.path.split(source_file)
|
||||||
|
@ -38,16 +39,15 @@ def Launcher():
|
||||||
specpath_option = '--specpath "{}"'.format(source_path)
|
specpath_option = '--specpath "{}"'.format(source_path)
|
||||||
folder_to_remove = os.path.join(source_path, source_filename[:-3])
|
folder_to_remove = os.path.join(source_path, source_filename[:-3])
|
||||||
file_to_remove = os.path.join(source_path, source_filename[:-3]+'.spec')
|
file_to_remove = os.path.join(source_path, source_filename[:-3]+'.spec')
|
||||||
command_line = 'pyinstaller -wF "{}" {} {} {} {}'.format(source_file, icon_option, workpath_option, dispath_option, specpath_option)
|
command_line = 'pyinstaller -wF --clean "{}" {} {} {} {}'.format(source_file, icon_option, workpath_option, dispath_option, specpath_option)
|
||||||
|
|
||||||
if button == 'Make EXE':
|
if event == 'Make EXE':
|
||||||
out=''
|
|
||||||
try:
|
try:
|
||||||
print(command_line)
|
print(command_line)
|
||||||
print('Making EXE... this will take a while.. the program has NOT locked up...')
|
print('Making EXE...the program has NOT locked up...')
|
||||||
window.Refresh()
|
window.refresh()
|
||||||
# print('Running command {}'.format(command_line))
|
# print('Running command {}'.format(command_line))
|
||||||
out, err = runCommand(command_line)
|
out, err = runCommand(command_line, window=window)
|
||||||
shutil.rmtree(folder_to_remove)
|
shutil.rmtree(folder_to_remove)
|
||||||
os.remove(file_to_remove)
|
os.remove(file_to_remove)
|
||||||
print('**** DONE ****')
|
print('**** DONE ****')
|
||||||
|
@ -56,7 +56,7 @@ def Launcher():
|
||||||
print('Copy and paste this line into the command prompt to manually run PyInstaller:\n\n', command_line)
|
print('Copy and paste this line into the command prompt to manually run PyInstaller:\n\n', command_line)
|
||||||
|
|
||||||
|
|
||||||
def runCommand(cmd, timeout=None):
|
def runCommand(cmd, timeout=None, window=None):
|
||||||
""" run shell command
|
""" run shell command
|
||||||
|
|
||||||
@param cmd: command to execute
|
@param cmd: command to execute
|
||||||
|
@ -64,14 +64,21 @@ def runCommand(cmd, timeout=None):
|
||||||
|
|
||||||
@return: (return code from command, command output)
|
@return: (return code from command, command output)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
output = ''
|
output = ''
|
||||||
|
for line in p.stdout:
|
||||||
|
line = line.decode(errors='replace' if (sys.version_info) < (3, 5)
|
||||||
|
else 'backslashreplace').rstrip()
|
||||||
|
output += line
|
||||||
|
print(line)
|
||||||
|
if window:
|
||||||
|
window.Refresh()
|
||||||
|
|
||||||
out, err = p.communicate()
|
retval = p.wait(timeout)
|
||||||
p.wait(timeout)
|
|
||||||
|
return (retval, output)
|
||||||
|
|
||||||
return (out, err)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
Launcher()
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue