Skip to content

Commit

Permalink
fix: Failed to copy resource
Browse files Browse the repository at this point in the history
- 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`.
  • Loading branch information
burstknight committed Oct 6, 2023
1 parent bef241c commit 13744df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions PyInstallerRunner/myPyInstallerRunner.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 5 additions & 1 deletion test/examples/myApp02/myApp02.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 13744df

Please sign in to comment.