Loading tools/releasetools/common.py +27 −11 Original line number Diff line number Diff line Loading @@ -768,30 +768,46 @@ def Gunzip(in_filename, out_filename): shutil.copyfileobj(in_file, out_file) def UnzipTemp(filename, pattern=None): """Unzips the given archive into a temporary directory and returns the name. def UnzipToDir(filename, dirname, pattern=None): """Unzips the archive to the given directory. If filename is of the form "foo.zip+bar.zip", unzip foo.zip into a temp dir, then unzip bar.zip into that_dir/BOOTABLE_IMAGES. Args: filename: The name of the zip file to unzip. Returns: The name of the temporary directory. dirname: Where the unziped files will land. pattern: Files to unzip from the archive. If omitted, will unzip the entire archvie. """ def unzip_to_dir(filename, dirname): cmd = ["unzip", "-o", "-q", filename, "-d", dirname] if pattern is not None: cmd.extend(pattern) RunAndCheckOutput(cmd) def UnzipTemp(filename, pattern=None): """Unzips the given archive into a temporary directory and returns the name. Args: filename: If filename is of the form "foo.zip+bar.zip", unzip foo.zip into a temp dir, then unzip bar.zip into that_dir/BOOTABLE_IMAGES. pattern: Files to unzip from the archive. If omitted, will unzip the entire archvie. Returns: The name of the temporary directory. """ tmp = MakeTempDir(prefix="targetfiles-") m = re.match(r"^(.*[.]zip)\+(.*[.]zip)$", filename, re.IGNORECASE) if m: unzip_to_dir(m.group(1), tmp) unzip_to_dir(m.group(2), os.path.join(tmp, "BOOTABLE_IMAGES")) UnzipToDir(m.group(1), tmp, pattern) UnzipToDir(m.group(2), os.path.join(tmp, "BOOTABLE_IMAGES"), pattern) filename = m.group(1) else: unzip_to_dir(filename, tmp) UnzipToDir(filename, tmp, pattern) return tmp Loading tools/releasetools/merge_target_files.py +6 −12 Original line number Diff line number Diff line Loading @@ -163,19 +163,13 @@ def extract_items(target_files, target_files_temp_dir, extract_item_list): else: filtered_extract_item_list.append(pattern) # Extract the filtered_extract_item_list from target_files into # target_files_temp_dir. # Extract from target_files into target_files_temp_dir the # filtered_extract_item_list. # TODO(b/124464492): Extend common.UnzipTemp() to handle this use case. command = [ 'unzip', '-n', '-q', '-d', target_files_temp_dir, target_files ] + filtered_extract_item_list common.RunAndWait(command, verbose=True) common.UnzipToDir( target_files, target_files_temp_dir, filtered_extract_item_list) def process_ab_partitions_txt( Loading Loading
tools/releasetools/common.py +27 −11 Original line number Diff line number Diff line Loading @@ -768,30 +768,46 @@ def Gunzip(in_filename, out_filename): shutil.copyfileobj(in_file, out_file) def UnzipTemp(filename, pattern=None): """Unzips the given archive into a temporary directory and returns the name. def UnzipToDir(filename, dirname, pattern=None): """Unzips the archive to the given directory. If filename is of the form "foo.zip+bar.zip", unzip foo.zip into a temp dir, then unzip bar.zip into that_dir/BOOTABLE_IMAGES. Args: filename: The name of the zip file to unzip. Returns: The name of the temporary directory. dirname: Where the unziped files will land. pattern: Files to unzip from the archive. If omitted, will unzip the entire archvie. """ def unzip_to_dir(filename, dirname): cmd = ["unzip", "-o", "-q", filename, "-d", dirname] if pattern is not None: cmd.extend(pattern) RunAndCheckOutput(cmd) def UnzipTemp(filename, pattern=None): """Unzips the given archive into a temporary directory and returns the name. Args: filename: If filename is of the form "foo.zip+bar.zip", unzip foo.zip into a temp dir, then unzip bar.zip into that_dir/BOOTABLE_IMAGES. pattern: Files to unzip from the archive. If omitted, will unzip the entire archvie. Returns: The name of the temporary directory. """ tmp = MakeTempDir(prefix="targetfiles-") m = re.match(r"^(.*[.]zip)\+(.*[.]zip)$", filename, re.IGNORECASE) if m: unzip_to_dir(m.group(1), tmp) unzip_to_dir(m.group(2), os.path.join(tmp, "BOOTABLE_IMAGES")) UnzipToDir(m.group(1), tmp, pattern) UnzipToDir(m.group(2), os.path.join(tmp, "BOOTABLE_IMAGES"), pattern) filename = m.group(1) else: unzip_to_dir(filename, tmp) UnzipToDir(filename, tmp, pattern) return tmp Loading
tools/releasetools/merge_target_files.py +6 −12 Original line number Diff line number Diff line Loading @@ -163,19 +163,13 @@ def extract_items(target_files, target_files_temp_dir, extract_item_list): else: filtered_extract_item_list.append(pattern) # Extract the filtered_extract_item_list from target_files into # target_files_temp_dir. # Extract from target_files into target_files_temp_dir the # filtered_extract_item_list. # TODO(b/124464492): Extend common.UnzipTemp() to handle this use case. command = [ 'unzip', '-n', '-q', '-d', target_files_temp_dir, target_files ] + filtered_extract_item_list common.RunAndWait(command, verbose=True) common.UnzipToDir( target_files, target_files_temp_dir, filtered_extract_item_list) def process_ab_partitions_txt( Loading