def __distribute(self, dl_info): assert isinstance(dl_info, download_info) util.report_info("Verifying <%s> ..." % dl_info.res_path) # Verify distribute source if not os.path.isfile(dl_info.store_path): util.report_error("File <%s> is not existed. Please check your network state and re-run build script." % dl_info.res_path) if fhash.hash_file(dl_info.store_path) != dl_info.tag: util.report_error("File <%s> verificaition is failed. Please check your network state and re-run build script." % dl_info.res_path) util.report_info("Distributing <%s> ..." % dl_info.res_path) # Clean target if file is existed. if dl_info.res_type in [RAW_FILE, COMPRESSED_FILE]: if os.path.isfile(dl_info.dist_path): os.remove(dl_info.dist_path) elif dl_info.res_type in [COMPRESSED_FOLDER]: if os.path.isdir(dl_info.dist_path): shutil.rmtree(dl_info.dist_path) dist_parent = os.path.dirname(dl_info.dist_path) if dl_info.res_type in [COMPRESSED_FILE, COMPRESSED_FOLDER]: self.__decompress(dl_info.store_path, dist_parent) else: shutil.copy(dl_info.store_path, dist_parent)
def __check_update(self, dl_info): assert isinstance(dl_info, download_info) need_download = False need_distribute = False if dl_info.need_distribute: if dl_info.res_type == COMPRESSED_FOLDER: if not os.path.isdir(dl_info.dist_path): need_distribute = True else: if not os.path.isfile(dl_info.dist_path): need_distribute = True if not os.path.isfile(dl_info.store_path): need_download = True need_distribute = dl_info.need_distribute elif fhash.hash_file(dl_info.store_path) != dl_info.tag: need_download = True need_distribute = dl_info.need_distribute return (need_download, need_distribute)
zipBinFullPath = os.path.join(srcPath, ZIP_BIN) sigFileFullPath = os.path.join(dstPath, SIG_FILE) with open("log.txt", "a") as f: f.write("GenPackage - Start\n") for zipSource in ZIP_LIST: zipSrcFullPath = os.path.join( srcPath, ToPath(zipSource) ) zipDstFullPath = os.path.join( dstPath, ToPath(zipSource + ".7z") ) print("Compressing <%s>" % zipSource) o = subprocess.check_output([zipBinFullPath, "a", zipDstFullPath, zipSrcFullPath]) f.writelines(o) if o.split('\n')[-2].strip() != "Everything is Ok": print "Error occured. details are in log.txt" sys.exit(1) print("Hashing <%s>" % zipSource) hashCode = fhash.hash_file(zipDstFullPath) res_type = "COMPRESSED_FOLDER" if os.path.isdir(zipSrcFullPath) else "COMPRESSED_FILE" fileHash.append( (zipSource, res_type, hashCode) ) for rawSource in RAW_LIST: rawSrcFullPath = os.path.join( srcPath, ToPath(rawSource) ) rawDstFullPath = os.path.join( dstPath, ToPath(rawSource) ) print("Copying <%s>" % rawSource) if os.path.isfile(rawSrcFullPath): dirName = os.path.dirname(rawDstFullPath) if not os.path.isdir(dirName): os.makedirs(dirName) shutil.copyfile(rawSrcFullPath, rawDstFullPath) print("Hashing <%s>" % rawSource) hashCode = fhash.hash_file(rawDstFullPath) fileHash.append( (rawSource, "RAW_FILE", hashCode) )