Skip to content

Commit 55822a5

Browse files
committed
extract_utils: add built-in extract fns to standalone extractor
Change-Id: I16bdb59566011703db9c6c1702738bd76debf7a1
1 parent f2a475a commit 55822a5

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

extract.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@
88

99
from extract_utils.extract import (
1010
ExtractCtx,
11+
extract_fns_type,
1112
extract_image,
1213
filter_already_extracted_partitions,
1314
get_dump_dir,
1415
)
16+
from extract_utils.extract_pixel import (
17+
extract_pixel_factory_image,
18+
extract_pixel_firmware,
19+
pixel_factory_image_regex,
20+
pixel_firmware_regex,
21+
)
22+
from extract_utils.extract_star import (
23+
extract_star_firmware,
24+
star_firmware_regex,
25+
)
1526

1627
DEFAULT_EXTRACTED_PARTITIONS = [
1728
'odm',
@@ -41,6 +52,24 @@
4152
action='store_true',
4253
help='Extract all files from archive',
4354
)
55+
parser.add_argument(
56+
'--pixel-factory',
57+
nargs='*',
58+
type=str,
59+
help='Files to extract as pixel factory image',
60+
)
61+
parser.add_argument(
62+
'--pixel-firmware',
63+
nargs='*',
64+
type=str,
65+
help='Files to extract as pixel firmware',
66+
)
67+
parser.add_argument(
68+
'--star-firmware',
69+
nargs='*',
70+
type=str,
71+
help='Files to extract as star firmware',
72+
)
4473

4574
parser.add_argument(
4675
'source',
@@ -52,13 +81,43 @@
5281
if __name__ == '__main__':
5382
args = parser.parse_args()
5483

84+
if args.pixel_factory is not None and not args.pixel_factory:
85+
args.pixel_factory = [pixel_factory_image_regex]
86+
87+
if args.pixel_firmware is not None and not args.pixel_firmware:
88+
args.pixel_firmware = [pixel_firmware_regex]
89+
90+
if args.star_firmware is not None and not args.star_firmware:
91+
args.star_firmware = [star_firmware_regex]
92+
93+
extract_fns: extract_fns_type = {}
94+
95+
if args.pixel_factory:
96+
for extract_pattern in args.pixel_factory:
97+
extract_fns.setdefault(extract_pattern, []).append(
98+
extract_pixel_factory_image,
99+
)
100+
101+
if args.pixel_firmware:
102+
for extract_pattern in args.pixel_firmware:
103+
extract_fns.setdefault(extract_pattern, []).append(
104+
extract_pixel_firmware,
105+
)
106+
107+
if args.star_firmware:
108+
for extract_pattern in args.star_firmware:
109+
extract_fns.setdefault(extract_pattern, []).append(
110+
extract_star_firmware,
111+
)
112+
55113
extract_partitions = args.partitions
56114
if args.extra_partitions is not None:
57115
extract_partitions += args.extra_partitions
58116

59117
ctx = ExtractCtx(
60118
keep_dump=True,
61119
extract_partitions=extract_partitions,
120+
extract_fns=extract_fns,
62121
extract_all=args.all,
63122
)
64123

0 commit comments

Comments
 (0)