[DEV] update methodologie of copy data
This commit is contained in:
parent
54fddc82b5
commit
1ac0ecd5c5
@ -97,14 +97,33 @@ def add_prefix(prefix,list):
|
|||||||
result.append(prefix+elem)
|
result.append(prefix+elem)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def copy_file(src, dst, cmd_file=None, force=False, force_identical=False):
|
##
|
||||||
|
## @brief Copy a specific file in a specific directory
|
||||||
|
## @param[in] src Input file path
|
||||||
|
## @param[in] dst Output file path
|
||||||
|
## @param[in] cmd_file (default None) Path of file to store the command line used
|
||||||
|
## @param[in] force (default False) Force copy of the file
|
||||||
|
## @param[in] force_identical (default False) Force file to be identical (read it in binary)
|
||||||
|
## @param[in,out] in_list (default None) Not real copy: set the request copy in the input list
|
||||||
|
##
|
||||||
|
def copy_file(src, dst, cmd_file=None, force=False, force_identical=False, in_list=None):
|
||||||
if os.path.exists(src) == False:
|
if os.path.exists(src) == False:
|
||||||
debug.error("Request a copy a file that does not existed : '" + src + "'")
|
debug.error("Request a copy a file that does not existed : '" + src + "'")
|
||||||
cmd_line = "copy \"" + src + "\" \"" + dst + "\""
|
cmd_line = "copy \"" + src + "\" \"" + dst + "\""
|
||||||
if force == False \
|
if force == False \
|
||||||
and depend.need_re_build(dst, src, file_cmd=cmd_file , cmd_line=cmd_line, force_identical=force_identical) == False:
|
and depend.need_re_build(dst, src, file_cmd=cmd_file , cmd_line=cmd_line, force_identical=force_identical) == False:
|
||||||
debug.verbose ("no need to copy ...")
|
debug.verbose ("no need to copy ...")
|
||||||
|
if in_list != None:
|
||||||
|
if dst in in_list:
|
||||||
|
debug.verbose("replace copy file " + os.path.relpath(src) + " ==> " + os.path.relpath(dst))
|
||||||
|
else:
|
||||||
|
debug.verbose("append copy file " + os.path.relpath(src) + " ==> " + os.path.relpath(dst))
|
||||||
|
# update element in dictionnary:
|
||||||
|
in_list[dst] = {"src":src,
|
||||||
|
"cmd_file":cmd_file,
|
||||||
|
"need_copy":False}
|
||||||
return
|
return
|
||||||
|
if in_list == None:
|
||||||
debug.print_element("copy file ", os.path.relpath(src), "==>", os.path.relpath(dst))
|
debug.print_element("copy file ", os.path.relpath(src), "==>", os.path.relpath(dst))
|
||||||
create_directory_of_file(dst)
|
create_directory_of_file(dst)
|
||||||
shutil.copyfile(src, dst)
|
shutil.copyfile(src, dst)
|
||||||
@ -112,9 +131,22 @@ def copy_file(src, dst, cmd_file=None, force=False, force_identical=False):
|
|||||||
stat_info = os.stat(src)
|
stat_info = os.stat(src)
|
||||||
os.chmod(dst, stat_info.st_mode)
|
os.chmod(dst, stat_info.st_mode)
|
||||||
store_command(cmd_line, cmd_file)
|
store_command(cmd_line, cmd_file)
|
||||||
|
else:
|
||||||
|
debug.verbose("append copy file " + os.path.relpath(src) + " ==> " + os.path.relpath(dst))
|
||||||
|
# update element in dictionnary:
|
||||||
|
in_list[dst] = {"src":src,
|
||||||
|
"cmd_file":cmd_file,
|
||||||
|
"need_copy":True}
|
||||||
|
|
||||||
|
##
|
||||||
def copy_anything(src, dst, recursive = False, force_identical=False):
|
## @brief Copy a compleate directory in a specific folder
|
||||||
|
## @param[in] src Input folder path
|
||||||
|
## @param[in] dst Output folder path
|
||||||
|
## @param[in] recursive (default False) Copy folder with all his dependency
|
||||||
|
## @param[in] force (default False) Force copy of the file
|
||||||
|
## @param[in,out] in_list (default None) Not real copy: set the request copy in the input list
|
||||||
|
##
|
||||||
|
def copy_anything(src, dst, recursive = False, force_identical=False, in_list=None):
|
||||||
debug.verbose(" copy anything : '" + str(src) + "'")
|
debug.verbose(" copy anything : '" + str(src) + "'")
|
||||||
debug.verbose(" to : '" + str(dst) + "'")
|
debug.verbose(" to : '" + str(dst) + "'")
|
||||||
if os.path.isdir(os.path.realpath(src)):
|
if os.path.isdir(os.path.realpath(src)):
|
||||||
@ -127,6 +159,10 @@ def copy_anything(src, dst, recursive = False, force_identical=False):
|
|||||||
debug.verbose(" " + str(tmp_path) + ":")
|
debug.verbose(" " + str(tmp_path) + ":")
|
||||||
for root, dirnames, filenames in os.walk(tmp_path):
|
for root, dirnames, filenames in os.walk(tmp_path):
|
||||||
deltaRoot = root[len(tmp_path):]
|
deltaRoot = root[len(tmp_path):]
|
||||||
|
while len(deltaRoot) > 0 \
|
||||||
|
and ( deltaRoot[0] == '/' \
|
||||||
|
or deltaRoot[0] == '\\' ):
|
||||||
|
deltaRoot = deltaRoot[1:]
|
||||||
if recursive == False \
|
if recursive == False \
|
||||||
and deltaRoot != "":
|
and deltaRoot != "":
|
||||||
return
|
return
|
||||||
@ -139,16 +175,22 @@ def copy_anything(src, dst, recursive = False, force_identical=False):
|
|||||||
for cycleFile in tmpList:
|
for cycleFile in tmpList:
|
||||||
#for cycleFile in filenames:
|
#for cycleFile in filenames:
|
||||||
debug.verbose(" '" + cycleFile + "'")
|
debug.verbose(" '" + cycleFile + "'")
|
||||||
debug.extreme_verbose("Might copy : '" + tmp_path + "/" + deltaRoot + "/" + cycleFile + "' ==> '" + dst + "'")
|
debug.extreme_verbose("Might copy : '" + tmp_path + " " + deltaRoot + " " + cycleFile + "' ==> '" + dst + "'")
|
||||||
copy_file(tmp_path + "/" + deltaRoot + "/" + cycleFile,
|
|
||||||
dst + "/" + deltaRoot + "/" + cycleFile,
|
|
||||||
force_identical=force_identical)
|
|
||||||
""" TODO : Might be better, but does not work ...
|
|
||||||
debug.extreme_verbose("Might copy : '" + os.path.join(tmp_path, deltaRoot, cycleFile) + "' ==> '" + dst + "'")
|
|
||||||
copy_file(os.path.join(tmp_path, deltaRoot, cycleFile),
|
copy_file(os.path.join(tmp_path, deltaRoot, cycleFile),
|
||||||
os.path.join(dst, deltaRoot, cycleFile),
|
os.path.join(dst, deltaRoot, cycleFile),
|
||||||
force_identical=force_identical)
|
force_identical=force_identical,
|
||||||
"""
|
in_list=in_list)
|
||||||
|
|
||||||
|
##
|
||||||
|
## @brief real copy of files in a specific dictionnary list
|
||||||
|
## @param[in] in_list Dictionnary of file to copy
|
||||||
|
##
|
||||||
|
def copy_list(in_list):
|
||||||
|
for dst in in_list:
|
||||||
|
if in_list[dst]["need_copy"] == False:
|
||||||
|
continue
|
||||||
|
# note we force the copy to disable the check of needed of copy (already done)
|
||||||
|
copy_file(in_list[dst]["src"], dst, cmd_file=in_list[dst]["cmd_file"], force=True)
|
||||||
|
|
||||||
def filter_extention(list_files, extentions, invert=False):
|
def filter_extention(list_files, extentions, invert=False):
|
||||||
out = []
|
out = []
|
||||||
|
@ -117,6 +117,8 @@ class Target(target.Target):
|
|||||||
else:
|
else:
|
||||||
target_outpath_data = os.path.join(target_outpath, self.pkg_path_data)
|
target_outpath_data = os.path.join(target_outpath, self.pkg_path_data)
|
||||||
tools.create_directory_of_file(target_outpath_data)
|
tools.create_directory_of_file(target_outpath_data)
|
||||||
|
# prepare list of copy files
|
||||||
|
copy_list={}
|
||||||
debug.debug("heritage for " + str(pkg_name) + ":")
|
debug.debug("heritage for " + str(pkg_name) + ":")
|
||||||
for heritage in heritage_list.list_heritage:
|
for heritage in heritage_list.list_heritage:
|
||||||
debug.debug("sub elements: " + str(heritage.name))
|
debug.debug("sub elements: " + str(heritage.name))
|
||||||
@ -126,11 +128,22 @@ class Target(target.Target):
|
|||||||
if static == True:
|
if static == True:
|
||||||
debug.debug(" need copy: " + path_src + " to " + target_outpath_data)
|
debug.debug(" need copy: " + path_src + " to " + target_outpath_data)
|
||||||
#copy all data:
|
#copy all data:
|
||||||
tools.copy_anything(path_src, target_outpath_data, recursive=True, force_identical=True)
|
tools.copy_anything(path_src,
|
||||||
|
target_outpath_data,
|
||||||
|
recursive=True,
|
||||||
|
force_identical=True,
|
||||||
|
in_list=copy_list)
|
||||||
else:
|
else:
|
||||||
debug.debug(" need copy: " + os.path.dirname(path_src) + " to " + target_outpath_data)
|
debug.debug(" need copy: " + os.path.dirname(path_src) + " to " + target_outpath_data)
|
||||||
#copy all data:
|
#copy all data:
|
||||||
tools.copy_anything(os.path.dirname(path_src), target_outpath_data, recursive=True, force_identical=True)
|
tools.copy_anything(os.path.dirname(path_src),
|
||||||
|
target_outpath_data,
|
||||||
|
recursive=True,
|
||||||
|
force_identical=True,
|
||||||
|
in_list=copy_list)
|
||||||
|
#real copy files
|
||||||
|
tools.copy_list(copy_list)
|
||||||
|
|
||||||
|
|
||||||
## copy binary files:
|
## copy binary files:
|
||||||
target_outpath_bin = os.path.join(target_outpath, self.pkg_path_bin)
|
target_outpath_bin = os.path.join(target_outpath, self.pkg_path_bin)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user