|
| 1 | +from typing import overload |
| 2 | + |
| 3 | + |
| 4 | +@overload |
| 5 | +def remove_shell_warning(s: bytes) -> bytes: ... |
| 6 | + |
| 7 | + |
| 8 | +@overload |
| 9 | +def remove_shell_warning(s: str) -> str: ... |
| 10 | + |
| 11 | + |
| 12 | +def remove_shell_warning(s): |
| 13 | + """ |
| 14 | + Remove warnings from shell |
| 15 | +
|
| 16 | + 1. Warnings in VMOS shell |
| 17 | + https://github.com/LmeSzinc/AzurLaneAutoScript/issues/1425 |
| 18 | +
|
| 19 | + WARNING: linker: [vdso]: unused DT entry: type 0x70000001 arg 0x0\n |
| 20 | + \x89PNG\r\n\x1a\n\x00\x00\x00\rIH... |
| 21 | +
|
| 22 | + 2. This linker thingy might appear multiple times when executing multiple commands |
| 23 | +
|
| 24 | + mek_8q:/dev # getprop | grep gnss |
| 25 | + WARNING: linker: Warning: "[vdso]" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring) |
| 26 | + WARNING: linker: Warning: "[vdso]" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring) |
| 27 | + [init.svc.gnss_service]: [running] |
| 28 | + [init.svc_debug_pid.gnss_service]: [406] |
| 29 | + [ro.boottime.gnss_service]: [27308752875] |
| 30 | +
|
| 31 | + Args: |
| 32 | + s (str | bytes): bytes or str |
| 33 | +
|
| 34 | + Returns: |
| 35 | + str | bytes: Shell output with warnings removed |
| 36 | + """ |
| 37 | + if isinstance(s, bytes): |
| 38 | + while 1: |
| 39 | + if s.startswith(b'WARNING: linker:'): |
| 40 | + _, _, s = s.partition(b'\n') |
| 41 | + else: |
| 42 | + break |
| 43 | + elif isinstance(s, str): |
| 44 | + while 1: |
| 45 | + if s.startswith('WARNING: linker:'): |
| 46 | + _, _, s = s.partition('\n') |
| 47 | + else: |
| 48 | + break |
| 49 | + |
| 50 | + return s |
| 51 | + |
| 52 | + |
| 53 | +@overload |
| 54 | +def remove_screenshot_warning(s: bytes) -> bytes: ... |
| 55 | + |
| 56 | + |
| 57 | +@overload |
| 58 | +def remove_screenshot_warning(s: str) -> str: ... |
| 59 | + |
| 60 | + |
| 61 | +def remove_screenshot_warning(s): |
| 62 | + """ |
| 63 | + Remove warnings when taking screenshot |
| 64 | +
|
| 65 | + 1. Errors in waydroid screencap render |
| 66 | + https://github.com/LmeSzinc/AzurLaneAutoScript/issues/4760 |
| 67 | +
|
| 68 | + Failed to create //.cache for shader cache (Read-only file system)---disabling.\n |
| 69 | +
|
| 70 | + 2. Warning when taking screenshot from multiscreen device |
| 71 | +
|
| 72 | + [Warning] Multiple displays were found, but no display id was specified! Defaulting to the first display found, |
| 73 | + however this default is not guaranteed to be consistent across captures.\n |
| 74 | + A display id should be specified.\n |
| 75 | + See "dumpsys SurfaceFlinger --display-id" for valid display IDs.\n |
| 76 | + \x89PNG... |
| 77 | +
|
| 78 | + 3. Another format of multiscreen warning |
| 79 | + https://github.com/LmeSzinc/AzurLaneAutoScript/issues/5682 |
| 80 | +
|
| 81 | + [Warning] Multiple displays were found, but no display id was specified! Defaulting to the first display found, |
| 82 | + however this default is not guaranteed to be consistent across captures. A display id should be specified.\n |
| 83 | + A display ID can be specified with the [-d display-id] option.\n |
| 84 | + See "dumpsys SurfaceFlinger --display-id" for valid display IDs.\n |
| 85 | + \x89PNG... |
| 86 | +
|
| 87 | + 4. Unknown header on VMOS PRO screenshot |
| 88 | + https://github.com/LmeSzinc/AzurLaneAutoScript/pull/940 |
| 89 | +
|
| 90 | + long long=8 fun*=10\n\x89PNG... |
| 91 | +
|
| 92 | + Args: |
| 93 | + s (str | bytes): bytes or str |
| 94 | +
|
| 95 | + Returns: |
| 96 | + str | bytes: Screenshot data with warnings removed |
| 97 | + """ |
| 98 | + if isinstance(s, bytes): |
| 99 | + if s.startswith(b'Failed to create'): |
| 100 | + _, _, s = s.partition(b'\n') |
| 101 | + if s.startswith(b'[Warning] Multiple displays'): |
| 102 | + _, _, s = s.partition(b'\n') |
| 103 | + if s.startswith(b'A display id') or s.startswith(b'A display ID'): |
| 104 | + _, _, s = s.partition(b'\n') |
| 105 | + if s.startswith(b'See "dumpsys'): |
| 106 | + _, _, s = s.partition(b'\n') |
| 107 | + if s.startswith(b'long long=8'): |
| 108 | + _, _, s = s.partition(b'\n') |
| 109 | + |
| 110 | + elif isinstance(s, str): |
| 111 | + if s.startswith('Failed to create'): |
| 112 | + _, _, s = s.partition('\n') |
| 113 | + if s.startswith('[Warning] Multiple displays'): |
| 114 | + _, _, s = s.partition('\n') |
| 115 | + if s.startswith('A display id') or s.startswith('A display ID'): |
| 116 | + _, _, s = s.partition('\n') |
| 117 | + if s.startswith('See "dumpsys'): |
| 118 | + _, _, s = s.partition('\n') |
| 119 | + if s.startswith('long long=8'): |
| 120 | + _, _, s = s.partition('\n') |
| 121 | + |
| 122 | + return s |
0 commit comments