From 6b056befec879472424fabaea2687d3a960280d5 Mon Sep 17 00:00:00 2001 From: Brent Vollebregt Date: Sat, 15 Dec 2018 13:43:08 +1300 Subject: [PATCH] Manually create and delete the temporary directory This brings back support for Python 2.7 --- auto_py_to_exe/__main__.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/auto_py_to_exe/__main__.py b/auto_py_to_exe/__main__.py index 4feac6cc..5e66fcec 100644 --- a/auto_py_to_exe/__main__.py +++ b/auto_py_to_exe/__main__.py @@ -19,6 +19,7 @@ from tkinter.filedialog import askopenfilename, askdirectory, askopenfilenames except ImportError: from tkFileDialog import askopenfilename, askdirectory, askopenfilenames +import atexit import argparse import os import platform @@ -104,7 +105,17 @@ def write(self, message): eel.init(web_path) # Use the same temporary directory to speed up consecutive builds -temporary_directory = tempfile.TemporaryDirectory() +temporary_directory = tempfile.mkdtemp() + + +def cleanup(): + try: + shutil.rmtree(temporary_directory) + except: + pass + + +atexit.register(cleanup) @eel.expose @@ -184,11 +195,11 @@ def convert_pre_check(file_path, one_file, output_folder): def convert(command, output): """ Package the executable passing the arguments the user requested """ # Notify the user of the workspace and setup building to it - eel.addOutput("Building in the current instances temporary directory at {}\n".format(temporary_directory.name)) + eel.addOutput("Building in the current instances temporary directory at {}\n".format(temporary_directory)) eel.addOutput("To get a new temporary directory, restart this application\n") - dist_path = os.path.join(temporary_directory.name, 'application') - build_path = os.path.join(temporary_directory.name, 'build') - extra_args = ['--distpath', dist_path] + ['--workpath', build_path] + ['--specpath', temporary_directory.name] + dist_path = os.path.join(temporary_directory, 'application') + build_path = os.path.join(temporary_directory, 'build') + extra_args = ['--distpath', dist_path] + ['--workpath', build_path] + ['--specpath', temporary_directory] # Run PyInstaller pyinstaller_fail = True