From 13744df487851f7c9db8c37b6d9084cd508c2eef Mon Sep 17 00:00:00 2001 From: burstknight Date: Fri, 6 Oct 2023 22:08:43 +0800 Subject: [PATCH] fix: Failed to copy resource - Problem: The method `__copyResourceFiles()` of the class `myPyInstallerRunner` couldn't copy resources. - Reason: If the resource was a folder and existed, this method would copy it into the target directory. - Solution: Update the method `__copyResourceFiles()` of the class `myPyInstallerRunner`. --- PyInstallerRunner/myPyInstallerRunner.py | 8 ++++++-- test/examples/myApp02/myApp02.py | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/PyInstallerRunner/myPyInstallerRunner.py b/PyInstallerRunner/myPyInstallerRunner.py index 77e6603..a9d7c27 100644 --- a/PyInstallerRunner/myPyInstallerRunner.py +++ b/PyInstallerRunner/myPyInstallerRunner.py @@ -1,8 +1,8 @@ from typing import Dict, List from yaml import safe_load -from os.path import isfile, isdir, join +from os.path import isfile, isdir, join, exists from os import system -from shutil import copy, copyfile, copytree +from shutil import copy, copytree, rmtree class myPyInstallerRunner(object): """ @@ -166,6 +166,10 @@ def __copyResourceFiles(self, strBuildDir: str, vdctResources: List[Dict[str, st if True == isfile(strSourcePath): copy(strSourcePath, strTargetPath) elif True == isdir(strSourcePath): + if True == exists(strTargetPath): + rmtree(strTargetPath) + # End of if-condition + copytree(strSourcePath, strTargetPath) else: print("Warning: Not found file or directory: %s" %(strSourcePath)) diff --git a/test/examples/myApp02/myApp02.py b/test/examples/myApp02/myApp02.py index 4388abf..11082b9 100644 --- a/test/examples/myApp02/myApp02.py +++ b/test/examples/myApp02/myApp02.py @@ -1,6 +1,6 @@ from yaml import safe_load from os import listdir -from os.path import join +from os.path import join, isfile def main(): with open("version.txt", "r", encoding="utf-8") as oReader: @@ -12,6 +12,10 @@ def main(): strDataDir = "./data" for strFile in listdir(strDataDir): strPath = join(strDataDir, strFile) + if False == isfile(strPath): + continue + # End of if-condition + print("="*20 + " %s " %(strPath) + "="*20) with open(strPath, "r", encoding="utf-8") as oReader: