def zip_subdirs(from_dir, to_dir): logger.info('zip_subdirs {} -> {}'.format(from_dir, to_dir)) FileUtils.create_dir(to_dir) for dir in FileUtils.listdir_nohidden(from_dir): logger.info('zip dir: {}'.format(dir)) ZipUtils.zip_dir('{}/{}'.format(from_dir, dir), '{}/{}.zip'.format(to_dir, dir))
def unzip(file_path, dst_path): if not zipfile.is_zipfile(file_path): return False if not os.path.exists(dst_path): os.mkdir(dst_path, 0o777) zfobj = zipfile.ZipFile(file_path) for name in zfobj.namelist(): oriname = name if os.sep == '\\': name = name.replace('/', os.sep) if name.endswith(os.sep): FileUtils.create_dir(os.path.join(dst_path, name)) pass else: filepath = os.path.join(dst_path, name) dir = os.path.dirname(filepath) if not os.path.exists(dir): FileUtils.create_dir(dir) file = open(filepath, 'wb') file.write(zfobj.read(oriname)) file.close() return True
def zip_all_libs_to_cache(self): os.system('rm -rf ' + self.cache_libs_path + '/*') FileUtils.create_dir(self.cache_libs_path) for dir in FileUtils.listdir_nohidden(self.generated_path): ZipUtils.zip_dir(self.generated_path + '/' + dir, self.cache_libs_path + '/' + dir + '.zip') FileUtils.copy_file_or_dir(self.prebuild_path + self.manifest_file, self.cache_path)
def unzip_cache(self): logger.info(f'Unzip cache, from {self.cache_libs_path} to {self.generated_path}') with step('unzip_prebuild_libs'): FileUtils.remove_dir(self.prebuild_path) FileUtils.create_dir(self.generated_path) FileUtils.copy_file_or_dir(os.path.join(self.cache_path, self.manifest_file), self.prebuild_path) # Unzip libs to pod-binary folder for zip_path in glob.iglob(os.path.join(self.cache_libs_path, '*.zip')): ZipUtils.unzip(zip_path, self.generated_path)
def unzip_cache(self): with step('unzip_prebuild_libs'): FileUtils.remove_dir(self.prebuild_path) FileUtils.create_dir(self.generated_path) FileUtils.copy_file_or_dir(self.cache_path + self.manifest_file, self.prebuild_path) # Unzip libs to pod-binary folder for zipPath in glob.iglob(self.cache_libs_path + '/*.zip'): ZipUtils.unzip(zipPath, self.generated_path)
def prebuild_if_needed(self, push=True): self.fetch_and_apply_cache() subprocess.run(['bundle', 'exec', 'pod', 'install'], check=True) # Sync with cache directory if not os.path.isfile(self.delta_path): logger.info('No change in prebuilt frameworks') return try: with open(self.delta_path) as f: FileUtils.create_dir(self.cache_path) data = f.read() data = re.sub('"', '', data) updatedMatches = re.findall(r'Updated: \[(.*)\]', data) if updatedMatches: updated = updatedMatches[0].strip() logger.info("Updated frameworks: {}".format(updated)) if len(updated): libs = updated.split(',') for lib in libs: libName = lib.strip() self.clean_cache(libName) self.zip_to_cache(libName) deletedMatches = re.findall(r'Deleted: \[(.*)\]', data) if deletedMatches: deleted = deletedMatches[0].strip() logger.info('Deleted frameworks: {}'.format(deleted)) if len(deleted): libs = deleted.split(',') for lib in libs: self.clean_cache(lib.strip()) # Copy manifest file FileUtils.copy_file_or_dir( self.prebuild_path + self.manifest_file, self.cache_path) if push: self.push_all_to_git(self.cache_path) except Exception as e: raise e