From 399c64eed9b7b15b9a5e254596461384d0024873 Mon Sep 17 00:00:00 2001 From: stonebig Date: Sun, 6 Jul 2025 08:59:06 +0200 Subject: [PATCH] duplicate zip login in wppm --- make.py | 16 +--------------- wppm/__init__.py | 2 +- wppm/utils.py | 30 +++++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/make.py b/make.py index d524ac12..66e243c9 100644 --- a/make.py +++ b/make.py @@ -23,14 +23,6 @@ assert CHANGELOGS_DIRECTORY.is_dir(), f"Changelogs directory not found: {CHANGELOGS_DIRECTORY}" assert PORTABLE_DIRECTORY.is_dir(), f"Portable directory not found: {PORTABLE_DIRECTORY}" -def find_7zip_executable() -> str: - """Locates the 7-Zip executable (7z.exe).""" - possible_program_files = [r"C:\Program Files", r"C:\Program Files (x86)", Path(sys.prefix).parent / "t"] - for base_dir in possible_program_files: - if (executable_path := Path(base_dir) / "7-Zip" / "7z.exe").is_file(): - return str(executable_path) - raise RuntimeError("7ZIP is not installed on this computer.") - def copy_items(source_directories: list[Path], target_directory: Path, verbose: bool = False): """Copies items from source directories to the target directory.""" target_directory.mkdir(parents=True, exist_ok=True) @@ -138,7 +130,7 @@ def create_installer_7zip(self, installer_type: str = "exe", compression= "mx5") sfx_option = "-sfx7z.sfx" if installer_type == "exe" else "" zip_option = "-tzip" if installer_type == "zip" else "" compress_level = "mx5" if compression == "" else compression - command = f'"{find_7zip_executable()}" {zip_option} -{compress_level} a "{fullfilename}" "{DISTDIR}" {sfx_option}' + command = f'"{utils.find_7zip_executable()}" {zip_option} -{compress_level} a "{fullfilename}" "{DISTDIR}" {sfx_option}' print(f'Executing 7-Zip script: "{command}"') try: subprocess.run(command, shell=True, check=True, stderr=sys.stderr, stdout=sys.stderr) @@ -224,7 +216,6 @@ def make_all(build_number: int, release_level: str, basedir_wpy: Path = None, verbose: bool = False, rebuild: bool = True, create_installer: str = "True", install_options=["--no-index"], flavor: str = "", find_links: str | list[Path] = None, source_dirs: Path = None, toolsdirs: str | list[Path] = None, - python_target_release: str = None, # e.g. "37101" for 3.7.10 ): """ Make a WinPython distribution for a given set of parameters: @@ -240,7 +231,6 @@ def make_all(build_number: int, release_level: str, basedir_wpy: Path = None, find_links: package directories (r'D:\Winpython\packages.srcreq') source_dirs: the python.zip + rebuilt winpython wheel package directory toolsdirs: Directory with development tools r'D:\WinPython\basedir34\t.Slim' - python_target_release: Target Python release (str). """ assert basedir_wpy is not None, "The *winpython_dirname* directory must be specified" @@ -261,10 +251,6 @@ def make_all(build_number: int, release_level: str, basedir_wpy: Path = None, install_options=install_options_list + find_links_options, flavor=flavor ) - # define the directory where to create the distro - python_minor_version_str = "".join(builder.python_name.replace(".amd64", "").split(".")[-2:-1]) - while not python_minor_version_str.isdigit() and len(python_minor_version_str) > 0: - python_minor_version_str = python_minor_version_str[:-1] builder.build(rebuild=rebuild, winpy_dir=winpy_dir) diff --git a/wppm/__init__.py b/wppm/__init__.py index e7414c38..a454a334 100644 --- a/wppm/__init__.py +++ b/wppm/__init__.py @@ -28,6 +28,6 @@ OTHER DEALINGS IN THE SOFTWARE. """ -__version__ = '17.1.20250705' +__version__ = '17.1.20250705a1' __license__ = __doc__ __project_url__ = 'http://winpython.github.io/' diff --git a/wppm/utils.py b/wppm/utils.py index df8e759b..20f154e7 100644 --- a/wppm/utils.py +++ b/wppm/utils.py @@ -312,7 +312,35 @@ def zip_directory(folder_path, output_zip_path): if file.is_file(): arcname = file.relative_to(folder_path) zipf.write(file, arcname) - + +def find_7zip_executable() -> str: + """Locates the 7-Zip executable (7z.exe).""" + possible_program_files = [r"C:\Program Files", r"C:\Program Files (x86)", Path(sys.prefix).parent / "t"] + for base_dir in possible_program_files: + if (executable_path := Path(base_dir) / "7-Zip" / "7z.exe").is_file(): + return str(executable_path) + raise RuntimeError("7ZIP is not installed on this computer.") + +def create_installer_7zip(origin, destination, filename_stem, installer_type: str = "exe", compression= "mx5"): + """Creates a WinPython installer using 7-Zip: "exe", "7z", "zip")""" + fullfilename = destination / (filename_stem + "." + installer_type) + if installer_type not in ["exe", "7z", "zip"]: + return + sfx_option = "-sfx7z.sfx" if installer_type == "exe" else "" + zip_option = "-tzip" if installer_type == "zip" else "" + compress_level = "mx5" if compression == "" else compression + command = f'"{find_7zip_executable()}" {zip_option} -{compress_level} a "{fullfilename}" "{origin}" {sfx_option}' + print(f'Executing 7-Zip script: "{command}"') + try: + subprocess.run(command, shell=True, check=True, stderr=sys.stderr, stdout=sys.stderr) + except subprocess.CalledProcessError as e: + print(f"Error executing 7-Zip script: {e}", file=sys.stderr) + +def command_installer_7zip(origin, destination, filename_stem, create_installer: str = "exe"): + for commmand in create_installer.lower().replace("7zip",".exe").split('.'): + installer_type, compression = (commmand + "-").split("-")[:2] + create_installer_7zip(Path(origin), Path(destination), filename_stem, installer_type, compression) + if __name__ == '__main__': print_box("Test") dname = sys.prefix