def get_bootimg_block(self): old_script = os.path.join(self.p2_path, "META-INF", "com", "google", "android", "updater-script") cn.is_exist_path(old_script) bootimg_block = "" with open(old_script, "r", encoding="UTF-8", errors="ignore") as f: for line in f.readlines(): if line.strip().startswith("package_extract_file"): if "\"boot.img\"" in line: bootimg_block = cn.parameter_split(line.strip())[-1] if not bootimg_block: raise Exception("Can not get boot.img block!") return bootimg_block
def __init__(self, fullpath, vendor_flag=False): cn.is_exist_path(fullpath) self.fullpath = fullpath self.vendor_flag = vendor_flag self.basepath, self.dirpath = os.path.split(fullpath) if cn.is_win(): self.statfile_info = cn.get_statfile(self.fullpath) # 生成文件(FL_File对象)的列表 self.filelist = [] # 生成目录(FL_Dir对象)的列表 self.dirlist = [] for root, dirs, files in os.walk(self.fullpath, topdown=True): for f in files: if f in self.skip_list: continue fpath = os.path.join(root, f) new_f = FL_File(fpath, self.fullpath, self.vendor_flag) if cn.is_win(): new_f.set_info(self.statfile_info[new_f.rela_path]) self.filelist.append(new_f) sys.stderr.write("Found file %-99s\r" % f) for d in dirs: dpath = os.path.join(root, d) new_d = FL_Dir(dpath, self.fullpath, self.vendor_flag) if cn.is_win(): new_d.set_info(self.statfile_info[new_d.rela_path]) self.dirlist.append(new_d) cn.clean_line() # 生成文件相对路径的列表 self.file_pathlist = [f.spath for f in self.filelist] # 生成目录相对路径的列表 self.dir_pathlist = [f.spath for f in self.dirlist] # 为文件和目录对象设置selabel属性 if not self.set_selabels(self.basepath): if cn.is_win(): bootimg_ramdisk_path = cn.extract_bootimg( os.path.join(self.basepath, "boot.img")) if not self.set_selabels(bootimg_ramdisk_path): raise Exception( "Could not find (plat_)file_contexts(.bin)!" " So we can not get selabel of files!") else: if os.system("ls -Z") == 0: for f in (self.filelist + self.dirlist): f.selabel = cn.get_selabel_linux(f.path) else: raise Exception("Can not get selabel with " "\"ls -Z\" command!")
def cp_files(self): print("\nCopying files...") new_bootimg = os.path.join(self.p2_path, "boot.img") cn.is_exist_path(new_bootimg) cn.file2dir(new_bootimg, self.ota_path) for f in self.cps.FL_2_isolated_files: sys.stderr.write("Copying file %-99s\r" % f.spath) cn.file2file(f.path, os.path.join(self.ota_path, "system", f.rela_path)) if self.pt_flag: for f in self.cpv.FL_2_isolated_files: sys.stderr.write("Copying file %-99s\r" % f.spath) cn.file2file( f.path, os.path.join(self.ota_path, "vendor", f.rela_path)) cn.clean_line() cn.file2dir(cn.bin_call("busybox"), os.path.join(self.ota_path, "bin")) cn.file2dir(cn.bin_call("bspatch"), os.path.join(self.ota_path, "bin"))