| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import re, sys |
| 6 |
|
| 7 |
def filter_whence(file): |
| 8 |
pattern_dsp_1 = re.compile("^File: qcom/.*/(qc)?(a|c|gp)dsp.*.mbn") |
| 9 |
pattern_dsp_2 = re.compile("^File: qcom/.*/(qc)?slpi.*.mbn") |
| 10 |
pattern_dsp_3 = re.compile("^File: qcom/.*/.*dsp_dtb.*.(mbn|elf)") |
| 11 |
pattern_jsn_1 = re.compile("^RawFile: qcom/.*/.*dsp.*.jsn") |
| 12 |
pattern_jsn_2 = re.compile("^RawFile: qcom/.*/slpi.*.jsn") |
| 13 |
pattern_jsn_3 = re.compile("^RawFile: qcom/.*/battmgr.*.jsn") |
| 14 |
matched = True |
| 15 |
version = False |
| 16 |
header = "" |
| 17 |
|
| 18 |
for line in file: |
| 19 |
if line.startswith("File:") or line.startswith("RawFile:"): |
| 20 |
version = False |
| 21 |
if pattern_dsp_1.match(line) or \ |
| 22 |
pattern_dsp_2.match(line) or \ |
| 23 |
pattern_dsp_3.match(line) or \ |
| 24 |
pattern_jsn_1.match(line) or \ |
| 25 |
pattern_jsn_2.match(line) or \ |
| 26 |
pattern_jsn_3.match(line): |
| 27 |
matched = True |
| 28 |
version = True |
| 29 |
yield header |
| 30 |
header = "" |
| 31 |
yield line |
| 32 |
continue |
| 33 |
|
| 34 |
if line.startswith("Version:"): |
| 35 |
if matched and version: |
| 36 |
version = False |
| 37 |
yield line |
| 38 |
continue |
| 39 |
|
| 40 |
if line.startswith("------"): |
| 41 |
if matched: |
| 42 |
yield line |
| 43 |
yield "\n" |
| 44 |
matched = False |
| 45 |
version = False |
| 46 |
header = "" |
| 47 |
continue |
| 48 |
|
| 49 |
if matched: |
| 50 |
yield line |
| 51 |
else: |
| 52 |
header += line |
| 53 |
|
| 54 |
|
| 55 |
def main(args): |
| 56 |
if len(args) != 3: |
| 57 |
print("Usage: %s WHENCE-orig WHENCE" % args[0]) |
| 58 |
|
| 59 |
with open(args[1], encoding="utf-8") as whence, \ |
| 60 |
open(args[2], mode="wt", encoding="utf-8") as out: |
| 61 |
for line in filter_whence(whence): |
| 62 |
out.write(line) |
| 63 |
|
| 64 |
if __name__ == "__main__": |
| 65 |
sys.exit(main(sys.argv)) |