|
6 | 6 | import argparse |
7 | 7 | import json |
8 | 8 | import logging |
| 9 | +import pathlib |
| 10 | +import shutil |
9 | 11 | import sys |
10 | 12 |
|
11 | 13 | import adbutils |
12 | 14 |
|
13 | 15 | import uiautomator2 as u2 |
| 16 | +from uiautomator2.utils import with_package_resource |
14 | 17 | from uiautomator2.version import __version__ |
15 | 18 | from uiautomator2 import enable_pretty_logging |
16 | 19 |
|
@@ -49,6 +52,18 @@ def cmd_purge(args): |
49 | 52 | logger.info("com.github.uiautomator uninstalled, all done !!!") |
50 | 53 |
|
51 | 54 |
|
| 55 | +def cmd_copy_assets(args): |
| 56 | + target_dir = pathlib.Path("assets") |
| 57 | + target_dir.mkdir(exist_ok=True) |
| 58 | + with with_package_resource("assets/u2.jar") as jar_path: |
| 59 | + target_path = target_dir / "u2.jar" |
| 60 | + shutil.copy2(jar_path, target_path) |
| 61 | + print("Copied u2.jar to", target_path) |
| 62 | + with with_package_resource("assets/app-uiautomator.apk") as apk_path: |
| 63 | + target_path = target_dir / "app-uiautomator.apk" |
| 64 | + shutil.copy2(apk_path, target_path) |
| 65 | + print("Copied app-uiautomator.apk to", target_path) |
| 66 | + |
52 | 67 | def cmd_screenshot(args): |
53 | 68 | d = u2.connect(args.serial) |
54 | 69 | d.screenshot().save(args.filename) |
@@ -154,6 +169,11 @@ def cmd_console(args): |
154 | 169 | ), |
155 | 170 | ], |
156 | 171 | ), |
| 172 | + dict( |
| 173 | + action=cmd_copy_assets, |
| 174 | + command="copy-assets", |
| 175 | + help="copy uiautomator2 assets to current directory", |
| 176 | + ), |
157 | 177 | dict( |
158 | 178 | action=cmd_screenshot, |
159 | 179 | command="screenshot", |
|
0 commit comments