Skip to content

Commit c6f0ed4

Browse files
committed
extract_utils: remove support for extract_fns tuple key
This overcomplicates the code and isn't of much use, since there's regex support for matching multiple file names. Keep the extract_fns_user_type name since it's in use in device trees. Change-Id: I3c883df035508b03b595efa9ec539d5109f5a9ac
1 parent 08f86e9 commit c6f0ed4

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

extract.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from extract_utils.extract import (
1010
ExtractCtx,
11-
extract_fns_type,
11+
extract_fns_user_type,
1212
extract_image,
1313
get_dump_dir,
1414
)
@@ -88,7 +88,7 @@
8888
if args.star_firmware is not None and not args.star_firmware:
8989
args.star_firmware = [star_firmware_regex]
9090

91-
extract_fns: extract_fns_type = {}
91+
extract_fns: extract_fns_user_type = {}
9292

9393
if args.pixel_factory:
9494
for extract_pattern in args.pixel_factory:

extract_utils/extract.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@
1414
from contextlib import contextmanager
1515
from os import path
1616
from tarfile import TarFile, is_tarfile
17-
from typing import Callable, Generator, Iterable, List, Optional, Set, Union
17+
from typing import (
18+
Callable,
19+
Dict,
20+
Generator,
21+
Iterable,
22+
List,
23+
Optional,
24+
Set,
25+
Union,
26+
)
1827
from zipfile import ZipFile, is_zipfile
1928

20-
from extract_utils.fixups import fixups_type, fixups_user_type
2129
from extract_utils.tools import (
2230
brotli_path,
2331
lpunpack_path,
@@ -51,15 +59,14 @@
5159

5260
extract_fn_type = Callable[['ExtractCtx', str, str], Optional[str]]
5361
extract_fns_value_type = Union[extract_fn_type, List[extract_fn_type]]
54-
extract_fns_user_type = fixups_user_type[extract_fns_value_type]
55-
extract_fns_type = fixups_type[extract_fns_value_type]
62+
extract_fns_user_type = Dict[str, extract_fns_value_type]
5663

5764

5865
class ExtractCtx:
5966
def __init__(
6067
self,
6168
keep_dump=False,
62-
extract_fns: Optional[extract_fns_type] = None,
69+
extract_fns: Optional[extract_fns_user_type] = None,
6370
extract_partitions: Optional[List[str]] = None,
6471
firmware_partitions: Optional[List[str]] = None,
6572
firmware_files: Optional[List[str]] = None,
@@ -134,7 +141,7 @@ def find_files(
134141

135142

136143
def should_extract_pattern_file_name(
137-
extract_fns: extract_fns_type, file_name: str
144+
extract_fns: extract_fns_user_type, file_name: str
138145
):
139146
for extract_pattern in extract_fns:
140147
match = re.match(extract_pattern, file_name)
@@ -172,7 +179,7 @@ def find_alternate_partitions(
172179
def _filter_files(
173180
extract_partitions: List[str],
174181
extract_file_names: List[str],
175-
extract_fns: extract_fns_type,
182+
extract_fns: extract_fns_user_type,
176183
file_paths: List[str],
177184
found_partitions: Set[str],
178185
) -> List[str]:
@@ -208,7 +215,7 @@ def filter_files(
208215
partition_lists: List[List[str]],
209216
file_name_lists: List[List[str]],
210217
found_partitions: Set[str],
211-
extract_fns: extract_fns_type,
218+
extract_fns: extract_fns_user_type,
212219
file_paths: List[str],
213220
) -> List[str]:
214221
extract_partitions = sum(partition_lists, [])

extract_utils/module.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ def __init__(
428428

429429
self.blob_fixups = flatten_fixups(blob_fixups)
430430
self.lib_fixups = flatten_fixups(lib_fixups)
431-
self.extract_fns = flatten_fixups(extract_fns)
431+
432+
if extract_fns is None:
433+
extract_fns = {}
434+
self.extract_fns = extract_fns
432435

433436
self.namespace_imports = namespace_imports
434437
self.check_elf = check_elf

0 commit comments

Comments
 (0)