diff options
author | Shyamnath Premnadh <[email protected]> | 2024-12-18 10:35:35 +0100 |
---|---|---|
committer | Shyamnath Premnadh <[email protected]> | 2024-12-18 17:25:08 +0100 |
commit | 6a3161e3fea6b84106b3dfcd84b541e643c9e531 (patch) | |
tree | bfdafad5559dfa3faac2f9fa20d224175bcba01d | |
parent | 1f26c800e0dff519b89418aaed4395d5497486df (diff) |
Deployment: Improve cleanup
- Handle removal of files/directories in the case of failure
- Add more details to the docstring
Pick-to: 6.8
Fixes: PYSIDE-2965
Change-Id: I6410963385c15899f49b60cae60b2200e8d13012
Reviewed-by: Friedemann Kleint <[email protected]>
Reviewed-by: Christian Tismer <[email protected]>
-rw-r--r-- | sources/pyside-tools/deploy_lib/deploy_util.py | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/sources/pyside-tools/deploy_lib/deploy_util.py b/sources/pyside-tools/deploy_lib/deploy_util.py index e2bb27946..496b7e00c 100644 --- a/sources/pyside-tools/deploy_lib/deploy_util.py +++ b/sources/pyside-tools/deploy_lib/deploy_util.py @@ -21,22 +21,38 @@ def config_option_exists(): def cleanup(config: Config, is_android: bool = False): """ - Cleanup the generated build folders/files + Cleanup the generated build folders/files. + + Parameters: + config (Config): The configuration object containing paths and settings. + is_android (bool): Flag indicating if the cleanup is for an Android project. Default is False. """ if config.generated_files_path.exists(): - shutil.rmtree(config.generated_files_path) - logging.info("[DEPLOY] Deployment directory purged") + try: + shutil.rmtree(config.generated_files_path) + logging.info("[DEPLOY] Deployment directory purged") + except PermissionError as e: + print(f"{type(e).__name__}: {e}") + logging.warning(f"[DEPLOY] Could not delete {config.generated_files_path}") if is_android: buildozer_spec: Path = config.project_dir / "buildozer.spec" if buildozer_spec.exists(): - buildozer_spec.unlink() - logging.info(f"[DEPLOY] {str(buildozer_spec)} removed") + try: + buildozer_spec.unlink() + logging.info(f"[DEPLOY] {str(buildozer_spec)} removed") + except PermissionError as e: + print(f"{type(e).__name__}: {e}") + logging.warning(f"[DEPLOY] Could not delete {buildozer_spec}") buildozer_build: Path = config.project_dir / ".buildozer" if buildozer_build.exists(): - shutil.rmtree(buildozer_build) - logging.info(f"[DEPLOY] {str(buildozer_build)} removed") + try: + shutil.rmtree(buildozer_build) + logging.info(f"[DEPLOY] {str(buildozer_build)} removed") + except PermissionError as e: + print(f"{type(e).__name__}: {e}") + logging.warning(f"[DEPLOY] Could not delete {buildozer_build}") def create_config_file(main_file: Path, dry_run: bool = False): |