From 523ffb2f517b96b1f0de98340e3806ac27904575 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 15 Jun 2014 20:02:37 +0200 Subject: [PATCH] [DEV] add resizing file depende=ing on size and not do it a second time --- lutinDepend.py | 98 ++++++++++++++++++++++++-------------------- lutinImage.py | 21 +++++++++- lutinModule.py | 8 ++-- lutinMultiprocess.py | 3 +- lutinTarget.py | 29 +++++++------ lutinTools.py | 15 ++++--- 6 files changed, 105 insertions(+), 69 deletions(-) diff --git a/lutinDepend.py b/lutinDepend.py index 59bc0ed..5971d93 100644 --- a/lutinDepend.py +++ b/lutinDepend.py @@ -4,32 +4,39 @@ import lutinDebug as debug 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(" dst='" + dst + "'") - debug.verbose(" str='" + src + "'") - debug.verbose(" dept='" + dependFile + "'") - debug.verbose(" cmd='" + file_cmd + "'") + debug.verbose(" dst='" + str(dst) + "'") + debug.verbose(" str='" + str(src) + "'") + debug.verbose(" dept='" + str(dependFile) + "'") + debug.verbose(" cmd='" + str(file_cmd) + "'") # if force mode selected ==> just force rebuild ... if environement.get_force_mode(): debug.verbose(" ==> must rebuild (force mode)") return True # 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)") return True # 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)") 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)") return True - if ""!=file_cmd: - if False==os.path.exists(file_cmd): + if file_cmd != "" \ + and file_cmd != None: + if os.path.exists(file_cmd) == False: debug.verbose(" ==> must rebuild (no commandLine file)") return True # check if the 2 cmdline are similar : @@ -44,42 +51,43 @@ def need_re_build(dst, src, dependFile, file_cmd="", cmdLine=""): # the cmdfile is correct ... file2.close() - - debug.verbose(" start parsing dependency file : '" + dependFile + "'") - file = open(dependFile, "r") - for curLine in file.readlines(): - # normal file : end with : ": \\n" - curLine = curLine[:len(curLine)-1] - # removing last \ ... - if curLine[len(curLine)-1:] == '\\' : + if dependFile != "" \ + and dependFile != None: + debug.verbose(" start parsing dependency file : '" + dependFile + "'") + file = open(dependFile, "r") + for curLine in file.readlines(): + # normal file : end with : ": \\n" curLine = curLine[:len(curLine)-1] - # remove white space : - #debug.verbose(" Line (read) : '" + curLine + "'"); - curLine = curLine.strip() - #debug.verbose(" Line (strip) : '" + curLine + "'"); - - testFile="" - if curLine[len(curLine)-1:] == ':': - debug.verbose(" Line (no check (already done) : '" + curLine + "'"); - elif len(curLine) == 0 \ - or curLine == '\\': - debug.verbose(" Line (Not parsed) : '" + curLine + "'"); - else: - testFile = curLine - debug.verbose(" Line (might check) : '" + testFile + "'"); - # really check files: - if testFile!="": - debug.verbose(" ==> test"); - if False==os.path.exists(testFile): - debug.verbose(" ==> must rebuild (a dependency file does not exist)") - file.close() - return True - if os.path.getmtime(testFile) > os.path.getmtime(dst): - debug.verbose(" ==> must rebuild (a dependency file time is newer)") - file.close() - return True - # close the current file : - file.close() + # removing last \ ... + if curLine[len(curLine)-1:] == '\\' : + curLine = curLine[:len(curLine)-1] + # remove white space : + #debug.verbose(" Line (read) : '" + curLine + "'"); + curLine = curLine.strip() + #debug.verbose(" Line (strip) : '" + curLine + "'"); + + testFile="" + if curLine[len(curLine)-1:] == ':': + debug.verbose(" Line (no check (already done) : '" + curLine + "'"); + elif len(curLine) == 0 \ + or curLine == '\\': + debug.verbose(" Line (Not parsed) : '" + curLine + "'"); + else: + testFile = curLine + debug.verbose(" Line (might check) : '" + testFile + "'"); + # really check files: + if testFile!="": + debug.verbose(" ==> test"); + if False==os.path.exists(testFile): + debug.verbose(" ==> must rebuild (a dependency file does not exist)") + file.close() + return True + if os.path.getmtime(testFile) > os.path.getmtime(dst): + debug.verbose(" ==> must rebuild (a dependency file time is newer)") + file.close() + return True + # close the current file : + file.close() debug.verbose(" ==> Not rebuild (all dependency is OK)") return False diff --git a/lutinImage.py b/lutinImage.py index 69abf05..e9c7cb8 100644 --- a/lutinImage.py +++ b/lutinImage.py @@ -2,18 +2,32 @@ import lutinDebug as debug import lutinTools as tools import platform +import os +import lutinMultiprocess +import lutinDepend as dependency if platform.system() == "Darwin": import CoreGraphics else: from PIL import Image + def get_pow_2_multiple(size): base = 2 while size>base: base = base * 2 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) extension = destFile[destFile.rfind('.'):] if platform.system() == "Darwin": @@ -28,6 +42,7 @@ def resize(srcFile, destFile, x, y): # keep ratio : y = int(float(x) * float(source_height) / float(source_width)) 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) + ")") source_image_rect = CoreGraphics.CGRectMake(0, 0, source_width, source_height) new_image = source_image.createWithImageInRect(source_image_rect) @@ -55,7 +70,9 @@ def resize(srcFile, destFile, x, y): # keep ratio : y = int(float(x) * float(im1.size[1]) / float(im1.size[0])) 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 tmpImage = im1.resize((x, y), Image.ANTIALIAS) tools.create_directory_of_file(destFile) tmpImage.save(destFile) + lutinMultiprocess.store_command(cmd_line, cmd_file) diff --git a/lutinModule.py b/lutinModule.py index e4da1b1..ec70372 100644 --- a/lutinModule.py +++ b/lutinModule.py @@ -391,13 +391,14 @@ class Module: if destination == "": destination = source[source.rfind('/')+1:] debug.verbose("Regenerate Destination : '" + destination + "'") + file_cmd = target.generate_file(binaryName, self.name, self.originFolder, destination, "image")[0] if sizeX > 0: debug.verbose("Image file : " + displaySource + " ==> " + destination + " resize=(" + str(sizeX) + "," + str(sizeY) + ")") 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: 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 @@ -409,9 +410,10 @@ class Module: if destination == "": destination = source[source.rfind('/')+1:] debug.verbose("Regenerate Destination : '" + destination + "'") + file_cmd = target.generate_file(binaryName, self.name, self.originFolder, destination, "image")[0] # TODO : when destination is missing ... 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 diff --git a/lutinMultiprocess.py b/lutinMultiprocess.py index be55cb5..d9d3fb3 100644 --- a/lutinMultiprocess.py +++ b/lutinMultiprocess.py @@ -21,7 +21,8 @@ processorAvaillable = 1 # number of CPU core availlable def store_command(cmdLine, file): # write cmd line only after to prevent errors ... - if file!="": + if file != "" \ + and file != None: # Create directory: lutinTools.create_directory_of_file(file) # Store the command Line: diff --git a/lutinTarget.py b/lutinTarget.py index c9ce628..d99895f 100644 --- a/lutinTarget.py +++ b/lutinTarget.py @@ -103,31 +103,34 @@ class Target: def get_build_mode(self): return self.buildMode - def add_image_staging(self, inputFile, outputFile, sizeX, sizeY): - for source, dst, x, y in self.listFinalFile: + def add_image_staging(self, inputFile, outputFile, sizeX, sizeY, cmdFile=None): + for source, dst, x, y, cmdFile2 in self.listFinalFile: if dst == outputFile : debug.verbose("already added : " + outputFile) return - debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'"); - self.listFinalFile.append([inputFile,outputFile, sizeX, sizeY]) + debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'") + self.listFinalFile.append([inputFile,outputFile, sizeX, sizeY, cmdFile]) - def add_file_staging(self, inputFile, outputFile): - for source, dst, x, y in self.listFinalFile: + def add_file_staging(self, inputFile, outputFile, cmdFile=None): + for source, dst, x, y, cmdFile2 in self.listFinalFile: if dst == outputFile : debug.verbose("already added : " + outputFile) return 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): 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: debug.verbose("must copy file : '" + source + "' ==> '" + dst + "'"); - lutinTools.copy_file(source, baseFolder+"/"+dst) + lutinTools.copy_file(source, baseFolder+"/"+dst, cmdFile) else: 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): @@ -159,17 +162,19 @@ class Target: list.append(file) 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_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"): list.append(file) 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_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"): 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_dependence) 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: debug.error("unknow type : " + type) return list diff --git a/lutinTools.py b/lutinTools.py index 9746070..3d5fe23 100644 --- a/lutinTools.py +++ b/lutinTools.py @@ -4,6 +4,8 @@ import shutil import errno import lutinDebug as debug import fnmatch +import lutinMultiprocess +import lutinDepend as dependency """ @@ -78,16 +80,17 @@ def add_prefix(prefix,list): result.append(prefix+elem) return result -def copy_file(src, dst, force=False): - if os.path.exists(src)==False: +def copy_file(src, dst, cmd_file=None, force=False): + if os.path.exists(src) == False: debug.error("Request a copy a file that does not existed : '" + src + "'") - if os.path.exists(dst): - if force==False \ - and os.path.getmtime(dst) > os.path.getmtime(src): - return + cmd_line = "copy \"" + src + "\" \"" + dst + "\"" + if force == False \ + and dependency.need_re_build(dst, src, file_cmd=cmd_file , cmdLine=cmd_line) == False: + return debug.print_element("copy file", src, "==>", dst) create_directory_of_file(dst) shutil.copyfile(src, dst) + lutinMultiprocess.store_command(cmd_line, cmd_file) def copy_anything(src, dst):