[DEV] add resizing file depende=ing on size and not do it a second time
This commit is contained in:
parent
c37eca8168
commit
523ffb2f51
@ -4,32 +4,39 @@ import lutinDebug as debug
|
|||||||
import lutinEnv as environement
|
import lutinEnv as environement
|
||||||
|
|
||||||
|
|
||||||
def need_re_build(dst, src, dependFile, file_cmd="", cmdLine=""):
|
def need_re_build(dst, src, dependFile=None, file_cmd="", cmdLine=""):
|
||||||
debug.verbose("Resuest check of dependency of :")
|
debug.verbose("Resuest check of dependency of :")
|
||||||
debug.verbose(" dst='" + dst + "'")
|
debug.verbose(" dst='" + str(dst) + "'")
|
||||||
debug.verbose(" str='" + src + "'")
|
debug.verbose(" str='" + str(src) + "'")
|
||||||
debug.verbose(" dept='" + dependFile + "'")
|
debug.verbose(" dept='" + str(dependFile) + "'")
|
||||||
debug.verbose(" cmd='" + file_cmd + "'")
|
debug.verbose(" cmd='" + str(file_cmd) + "'")
|
||||||
# if force mode selected ==> just force rebuild ...
|
# if force mode selected ==> just force rebuild ...
|
||||||
if environement.get_force_mode():
|
if environement.get_force_mode():
|
||||||
debug.verbose(" ==> must rebuild (force mode)")
|
debug.verbose(" ==> must rebuild (force mode)")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# check if the destination existed:
|
# check if the destination existed:
|
||||||
if False==os.path.exists(dst):
|
if dst != "" \
|
||||||
|
and dst != None \
|
||||||
|
and os.path.exists(dst) == False:
|
||||||
debug.verbose(" ==> must rebuild (dst does not exist)")
|
debug.verbose(" ==> must rebuild (dst does not exist)")
|
||||||
return True
|
return True
|
||||||
# chek the basic date if the 2 files
|
# chek the basic date if the 2 files
|
||||||
if os.path.getmtime(src) > os.path.getmtime(dst):
|
if dst != "" \
|
||||||
|
and dst != None \
|
||||||
|
and os.path.getmtime(src) > os.path.getmtime(dst):
|
||||||
debug.verbose(" ==> must rebuild (source time greater)")
|
debug.verbose(" ==> must rebuild (source time greater)")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if False==os.path.exists(dependFile):
|
if dependFile != "" \
|
||||||
|
and dependFile != None \
|
||||||
|
and os.path.exists(dependFile) == False:
|
||||||
debug.verbose(" ==> must rebuild (no depending file)")
|
debug.verbose(" ==> must rebuild (no depending file)")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if ""!=file_cmd:
|
if file_cmd != "" \
|
||||||
if False==os.path.exists(file_cmd):
|
and file_cmd != None:
|
||||||
|
if os.path.exists(file_cmd) == False:
|
||||||
debug.verbose(" ==> must rebuild (no commandLine file)")
|
debug.verbose(" ==> must rebuild (no commandLine file)")
|
||||||
return True
|
return True
|
||||||
# check if the 2 cmdline are similar :
|
# check if the 2 cmdline are similar :
|
||||||
@ -44,7 +51,8 @@ def need_re_build(dst, src, dependFile, file_cmd="", cmdLine=""):
|
|||||||
# the cmdfile is correct ...
|
# the cmdfile is correct ...
|
||||||
file2.close()
|
file2.close()
|
||||||
|
|
||||||
|
if dependFile != "" \
|
||||||
|
and dependFile != None:
|
||||||
debug.verbose(" start parsing dependency file : '" + dependFile + "'")
|
debug.verbose(" start parsing dependency file : '" + dependFile + "'")
|
||||||
file = open(dependFile, "r")
|
file = open(dependFile, "r")
|
||||||
for curLine in file.readlines():
|
for curLine in file.readlines():
|
||||||
|
@ -2,18 +2,32 @@
|
|||||||
import lutinDebug as debug
|
import lutinDebug as debug
|
||||||
import lutinTools as tools
|
import lutinTools as tools
|
||||||
import platform
|
import platform
|
||||||
|
import os
|
||||||
|
import lutinMultiprocess
|
||||||
|
import lutinDepend as dependency
|
||||||
|
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
import CoreGraphics
|
import CoreGraphics
|
||||||
else:
|
else:
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
def get_pow_2_multiple(size):
|
def get_pow_2_multiple(size):
|
||||||
base = 2
|
base = 2
|
||||||
while size>base:
|
while size>base:
|
||||||
base = base * 2
|
base = base * 2
|
||||||
return base
|
return base
|
||||||
|
|
||||||
def resize(srcFile, destFile, x, y):
|
# TODO : 3 things to do :
|
||||||
|
# check if force requested
|
||||||
|
# check if time change
|
||||||
|
# check if command line change
|
||||||
|
def resize(srcFile, destFile, x, y, cmd_file=None):
|
||||||
|
if os.path.exists(srcFile) == False:
|
||||||
|
debug.error("Request a resize an image that does not existed : '" + srcFile + "'")
|
||||||
|
cmd_line = "resize Image : " + srcFile + " ==> " + destFile + " newSize=(" + str(x) + "x" + str(y) + ")"
|
||||||
|
if False==dependency.need_re_build(destFile, srcFile, file_cmd=cmd_file , cmdLine=cmd_line):
|
||||||
|
return
|
||||||
|
# add cmdLine ...
|
||||||
x = get_pow_2_multiple(x)
|
x = get_pow_2_multiple(x)
|
||||||
extension = destFile[destFile.rfind('.'):]
|
extension = destFile[destFile.rfind('.'):]
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
@ -28,6 +42,7 @@ def resize(srcFile, destFile, x, y):
|
|||||||
# keep ratio :
|
# keep ratio :
|
||||||
y = int(float(x) * float(source_height) / float(source_width))
|
y = int(float(x) * float(source_height) / float(source_width))
|
||||||
y = get_pow_2_multiple(y)
|
y = get_pow_2_multiple(y)
|
||||||
|
debug.print_element("resize Image (" + str(x) + "x" + str(y) + ")", srcFile, "==>", destFile)
|
||||||
debug.debug("Resize image: " + srcFile + " size=(" + str(source_width) + "x" + str(source_height) + ") -> (" + str(x) + "x" + str(y) + ")")
|
debug.debug("Resize image: " + srcFile + " size=(" + str(source_width) + "x" + str(source_height) + ") -> (" + str(x) + "x" + str(y) + ")")
|
||||||
source_image_rect = CoreGraphics.CGRectMake(0, 0, source_width, source_height)
|
source_image_rect = CoreGraphics.CGRectMake(0, 0, source_width, source_height)
|
||||||
new_image = source_image.createWithImageInRect(source_image_rect)
|
new_image = source_image.createWithImageInRect(source_image_rect)
|
||||||
@ -55,7 +70,9 @@ def resize(srcFile, destFile, x, y):
|
|||||||
# keep ratio :
|
# keep ratio :
|
||||||
y = int(float(x) * float(im1.size[1]) / float(im1.size[0]))
|
y = int(float(x) * float(im1.size[1]) / float(im1.size[0]))
|
||||||
y = get_pow_2_multiple(y)
|
y = get_pow_2_multiple(y)
|
||||||
|
debug.print_element("resize Image (" + str(x) + "x" + str(y) + ")", srcFile, "==>", destFile)
|
||||||
# use one of these filter options to resize the image
|
# use one of these filter options to resize the image
|
||||||
tmpImage = im1.resize((x, y), Image.ANTIALIAS)
|
tmpImage = im1.resize((x, y), Image.ANTIALIAS)
|
||||||
tools.create_directory_of_file(destFile)
|
tools.create_directory_of_file(destFile)
|
||||||
tmpImage.save(destFile)
|
tmpImage.save(destFile)
|
||||||
|
lutinMultiprocess.store_command(cmd_line, cmd_file)
|
||||||
|
@ -391,13 +391,14 @@ class Module:
|
|||||||
if destination == "":
|
if destination == "":
|
||||||
destination = source[source.rfind('/')+1:]
|
destination = source[source.rfind('/')+1:]
|
||||||
debug.verbose("Regenerate Destination : '" + destination + "'")
|
debug.verbose("Regenerate Destination : '" + destination + "'")
|
||||||
|
file_cmd = target.generate_file(binaryName, self.name, self.originFolder, destination, "image")[0]
|
||||||
if sizeX > 0:
|
if sizeX > 0:
|
||||||
debug.verbose("Image file : " + displaySource + " ==> " + destination + " resize=(" + str(sizeX) + "," + str(sizeY) + ")")
|
debug.verbose("Image file : " + displaySource + " ==> " + destination + " resize=(" + str(sizeX) + "," + str(sizeY) + ")")
|
||||||
fileName, fileExtension = os.path.splitext(self.originFolder+"/" + source)
|
fileName, fileExtension = os.path.splitext(self.originFolder+"/" + source)
|
||||||
target.add_image_staging(source, destination, sizeX, sizeY)
|
target.add_image_staging(source, destination, sizeX, sizeY, file_cmd)
|
||||||
else:
|
else:
|
||||||
debug.verbose("Might copy file : " + displaySource + " ==> " + destination)
|
debug.verbose("Might copy file : " + displaySource + " ==> " + destination)
|
||||||
target.add_file_staging(source, destination)
|
target.add_file_staging(source, destination, file_cmd)
|
||||||
|
|
||||||
##
|
##
|
||||||
## @brief Commands for copying files
|
## @brief Commands for copying files
|
||||||
@ -409,9 +410,10 @@ class Module:
|
|||||||
if destination == "":
|
if destination == "":
|
||||||
destination = source[source.rfind('/')+1:]
|
destination = source[source.rfind('/')+1:]
|
||||||
debug.verbose("Regenerate Destination : '" + destination + "'")
|
debug.verbose("Regenerate Destination : '" + destination + "'")
|
||||||
|
file_cmd = target.generate_file(binaryName, self.name, self.originFolder, destination, "image")[0]
|
||||||
# TODO : when destination is missing ...
|
# TODO : when destination is missing ...
|
||||||
debug.verbose("Might copy file : " + displaySource + " ==> " + destination)
|
debug.verbose("Might copy file : " + displaySource + " ==> " + destination)
|
||||||
target.add_file_staging(source, destination)
|
target.add_file_staging(source, destination, file_cmd)
|
||||||
|
|
||||||
##
|
##
|
||||||
## @brief Commands for copying files
|
## @brief Commands for copying files
|
||||||
|
@ -21,7 +21,8 @@ processorAvaillable = 1 # number of CPU core availlable
|
|||||||
|
|
||||||
def store_command(cmdLine, file):
|
def store_command(cmdLine, file):
|
||||||
# write cmd line only after to prevent errors ...
|
# write cmd line only after to prevent errors ...
|
||||||
if file!="":
|
if file != "" \
|
||||||
|
and file != None:
|
||||||
# Create directory:
|
# Create directory:
|
||||||
lutinTools.create_directory_of_file(file)
|
lutinTools.create_directory_of_file(file)
|
||||||
# Store the command Line:
|
# Store the command Line:
|
||||||
|
@ -103,31 +103,34 @@ class Target:
|
|||||||
def get_build_mode(self):
|
def get_build_mode(self):
|
||||||
return self.buildMode
|
return self.buildMode
|
||||||
|
|
||||||
def add_image_staging(self, inputFile, outputFile, sizeX, sizeY):
|
def add_image_staging(self, inputFile, outputFile, sizeX, sizeY, cmdFile=None):
|
||||||
for source, dst, x, y in self.listFinalFile:
|
for source, dst, x, y, cmdFile2 in self.listFinalFile:
|
||||||
if dst == outputFile :
|
if dst == outputFile :
|
||||||
debug.verbose("already added : " + outputFile)
|
debug.verbose("already added : " + outputFile)
|
||||||
return
|
return
|
||||||
debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'");
|
debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'")
|
||||||
self.listFinalFile.append([inputFile,outputFile, sizeX, sizeY])
|
self.listFinalFile.append([inputFile,outputFile, sizeX, sizeY, cmdFile])
|
||||||
|
|
||||||
def add_file_staging(self, inputFile, outputFile):
|
def add_file_staging(self, inputFile, outputFile, cmdFile=None):
|
||||||
for source, dst, x, y in self.listFinalFile:
|
for source, dst, x, y, cmdFile2 in self.listFinalFile:
|
||||||
if dst == outputFile :
|
if dst == outputFile :
|
||||||
debug.verbose("already added : " + outputFile)
|
debug.verbose("already added : " + outputFile)
|
||||||
return
|
return
|
||||||
debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'");
|
debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'");
|
||||||
self.listFinalFile.append([inputFile,outputFile, -1, -1])
|
self.listFinalFile.append([inputFile, outputFile, -1, -1, cmdFile])
|
||||||
|
|
||||||
def copy_to_staging(self, binaryName):
|
def copy_to_staging(self, binaryName):
|
||||||
baseFolder = self.get_staging_folder_data(binaryName)
|
baseFolder = self.get_staging_folder_data(binaryName)
|
||||||
for source, dst, x, y in self.listFinalFile:
|
for source, dst, x, y, cmdFile in self.listFinalFile:
|
||||||
|
if cmdFile != None \
|
||||||
|
and cmdFile != "":
|
||||||
|
debug.verbose("cmd file " + cmdFile)
|
||||||
if x == -1:
|
if x == -1:
|
||||||
debug.verbose("must copy file : '" + source + "' ==> '" + dst + "'");
|
debug.verbose("must copy file : '" + source + "' ==> '" + dst + "'");
|
||||||
lutinTools.copy_file(source, baseFolder+"/"+dst)
|
lutinTools.copy_file(source, baseFolder+"/"+dst, cmdFile)
|
||||||
else:
|
else:
|
||||||
debug.verbose("resize image : '" + source + "' ==> '" + dst + "' size=(" + str(x) + "," + str(y) + ")");
|
debug.verbose("resize image : '" + source + "' ==> '" + dst + "' size=(" + str(x) + "," + str(y) + ")");
|
||||||
lutinImage.resize(source, baseFolder+"/"+dst, x, y)
|
lutinImage.resize(source, baseFolder+"/"+dst, x, y, cmdFile)
|
||||||
|
|
||||||
|
|
||||||
def clean_module_tree(self):
|
def clean_module_tree(self):
|
||||||
@ -159,17 +162,19 @@ class Target:
|
|||||||
list.append(file)
|
list.append(file)
|
||||||
list.append(self.get_staging_folder(binaryName) + "/" + self.folder_bin + "/" + moduleName + self.suffix_binary)
|
list.append(self.get_staging_folder(binaryName) + "/" + self.folder_bin + "/" + moduleName + self.suffix_binary)
|
||||||
list.append(self.get_build_folder(moduleName) + "/" + moduleName + self.suffix_dependence)
|
list.append(self.get_build_folder(moduleName) + "/" + moduleName + self.suffix_dependence)
|
||||||
list.append(self.get_staging_folder(binaryName) + "/" + self.folder_bin + "/" + moduleName + self.suffix_cmdLine)
|
list.append(self.get_build_folder(binaryName) + "/" + self.folder_bin + "/" + moduleName + self.suffix_cmdLine)
|
||||||
elif (type=="lib-shared"):
|
elif (type=="lib-shared"):
|
||||||
list.append(file)
|
list.append(file)
|
||||||
list.append(self.get_staging_folder(binaryName) + "/" + self.folder_lib + "/" + moduleName + self.suffix_lib_dynamic)
|
list.append(self.get_staging_folder(binaryName) + "/" + self.folder_lib + "/" + moduleName + self.suffix_lib_dynamic)
|
||||||
list.append(self.get_build_folder(moduleName) + "/" + moduleName + self.suffix_dependence)
|
list.append(self.get_build_folder(moduleName) + "/" + moduleName + self.suffix_dependence)
|
||||||
list.append(self.get_staging_folder(binaryName) + "/" + self.folder_lib + "/" + moduleName + self.suffix_cmdLine)
|
list.append(self.get_build_folder(binaryName) + "/" + self.folder_lib + "/" + moduleName + self.suffix_cmdLine)
|
||||||
elif (type=="lib-static"):
|
elif (type=="lib-static"):
|
||||||
list.append(file)
|
list.append(file)
|
||||||
list.append(self.get_build_folder(moduleName) + "/" + moduleName + self.suffix_lib_static)
|
list.append(self.get_build_folder(moduleName) + "/" + moduleName + self.suffix_lib_static)
|
||||||
list.append(self.get_build_folder(moduleName) + "/" + moduleName + self.suffix_dependence)
|
list.append(self.get_build_folder(moduleName) + "/" + moduleName + self.suffix_dependence)
|
||||||
list.append(self.get_build_folder(moduleName) + "/" + moduleName + self.suffix_cmdLine)
|
list.append(self.get_build_folder(moduleName) + "/" + moduleName + self.suffix_cmdLine)
|
||||||
|
elif (type=="image"):
|
||||||
|
list.append(self.get_build_folder(binaryName) + "/data/" + file + self.suffix_cmdLine)
|
||||||
else:
|
else:
|
||||||
debug.error("unknow type : " + type)
|
debug.error("unknow type : " + type)
|
||||||
return list
|
return list
|
||||||
|
@ -4,6 +4,8 @@ import shutil
|
|||||||
import errno
|
import errno
|
||||||
import lutinDebug as debug
|
import lutinDebug as debug
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
import lutinMultiprocess
|
||||||
|
import lutinDepend as dependency
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -78,16 +80,17 @@ def add_prefix(prefix,list):
|
|||||||
result.append(prefix+elem)
|
result.append(prefix+elem)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def copy_file(src, dst, force=False):
|
def copy_file(src, dst, cmd_file=None, force=False):
|
||||||
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 + "'")
|
||||||
if os.path.exists(dst):
|
cmd_line = "copy \"" + src + "\" \"" + dst + "\""
|
||||||
if force==False \
|
if force == False \
|
||||||
and os.path.getmtime(dst) > os.path.getmtime(src):
|
and dependency.need_re_build(dst, src, file_cmd=cmd_file , cmdLine=cmd_line) == False:
|
||||||
return
|
return
|
||||||
debug.print_element("copy file", src, "==>", dst)
|
debug.print_element("copy file", src, "==>", dst)
|
||||||
create_directory_of_file(dst)
|
create_directory_of_file(dst)
|
||||||
shutil.copyfile(src, dst)
|
shutil.copyfile(src, dst)
|
||||||
|
lutinMultiprocess.store_command(cmd_line, cmd_file)
|
||||||
|
|
||||||
|
|
||||||
def copy_anything(src, dst):
|
def copy_anything(src, dst):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user