async def async_main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-d', '--debug', action="store_true", help="enable debug mode") parser.add_argument('-p', '--port', type=int, default=3600, help='listen port') parser.add_argument("-s", "--server", type=str, required=True, help="server address") args = parser.parse_args() # start server enable_pretty_logging() app = make_app(debug=args.debug) app.listen(args.port) global hbc self_url = "http://{}:{}".format(current_ip(), args.port) server_addr = args.server.replace("http://", "").replace("/", "") hbc = await heartbeat.heartbeat_connect(server_addr, platform='apple', self_url=self_url) await device_watch()
async def post(self, udid=None): udid = udid or self.get_argument('udid', None) assert udid d = idevices.get(udid) try: if not d: raise Exception("Device not found") d.restart_wda_proxy() # change wda public port wda_url = "http://{}:{}".format(current_ip(), d.public_port) await d.wda_healthcheck() await hbc.device_update({ "udid": udid, "colding": False, "provider": { "wdaUrl": wda_url, } }) self.write({ "success": True, "description": "Device successfully colded" }) except Exception as e: logger.warning("colding procedure got error: %s", e) self.set_status(400) # bad request self.write({ "success": False, "description": "udid: %s not found" % udid })
def __init__(self, serial: str, callback=nop_callback): self._serial = serial self._procs = [] self._current_ip = current_ip() self._current_ip_network = current_ip_network() self._device = adbclient.device(serial) self._callback = callback
async def async_main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-d', '--debug', action="store_true", help="enable debug mode") parser.add_argument('-p', '--port', type=int, default=3600, help='listen port') parser.add_argument("-s", "--server", type=str, default="localhost:4000", required=False, help="server address") parser.add_argument("-W", "--wda-directory", default="./WebDriverAgent", help="WebDriverAgent source directory") parser.add_argument( "--manually-start-wda", action="store_true", help= "Start wda manually like using tidevice(with xctest). Then atx won't start WebDriverAgent" ) parser.add_argument( "--use-tidevice", action="store_true", help= "Start wda automatically using tidevice command. Only works when not using manually-start-wda" ) parser.add_argument( "--wda-bundle-pattern", type=str, default="*WebDriverAgent*", required=False, help= "If using --use-tidevice, can override wda bundle name pattern manually" ) args = parser.parse_args() # start server enable_pretty_logging() app = make_app(debug=args.debug) app.listen(args.port) global hbc self_url = "http://{}:{}".format(current_ip(), args.port) server_addr = args.server.replace("http://", "").replace("/", "") hbc = await heartbeat.heartbeat_connect(server_addr, platform='apple', self_url=self_url) await device_watch(args.wda_directory, args.manually_start_wda, args.use_tidevice, args.wda_bundle_pattern)
async def async_main(): # 建立解析对象 formatter_class: 重置 help 信息输出的格式 parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) # 为应用程序添加参数选项 parser.add_argument('-s', '--server', default='localhost:4000', help='server address') parser.add_argument("--allow-remote", action="store_true", help="allow remote connect device") parser.add_argument('-t', '--test', action="store_true", help="run test code") parser.add_argument('-p', '--port', type=int, default=3500, help='listen port') parser.add_argument("--owner", type=str, help="provider owner email") parser.add_argument("--owner-file", type=argparse.FileType("r"), help="provider owner email from file") args = parser.parse_args() owner_email = args.owner if args.owner_file: with args.owner_file as file: owner_email = file.read().strip() logger.info("Owner: %s", owner_email) if args.test: for apk_name in ("cloudmusic.apk", ): # , "apkinfo.exe"): apk_path = "testdata/" + apk_name logger.info("Install %s", apk_path) # apk_path = r"testdata/cloudmusic.apk" ret = app_install_local("6EB0217704000486", apk_path, launch=True) logger.info("Ret: %s", ret) return # start local server provider_url = "http://" + current_ip() + ":" + str(args.port) app = make_app() app.listen(args.port) logger.info("ProviderURL: %s", provider_url) # connect to atxserver2 global hbconn hbconn = await heartbeat_connect(args.server, secret=secret, self_url=provider_url, owner=owner_email) await device_watch(args.allow_remote)
async def _device_callback(d: idb.IDevice, status: str, info=None): if status == "run": await hbc.device_update({ "udid": d.udid, "provider": None, # no provider indicate not present "colding": False, "properties": { "name": d.name, "product": d.product, "brand": "Apple", } }) print(d, "run") elif status == "ready": logger.debug("%s %s", d, "healthcheck passed") assert isinstance(info, dict) info = defaultdict(dict, info) await hbc.device_update({ "udid": d.udid, "colding": False, "provider": { "wdaUrl": "http://{}:{}".format(current_ip(), d.public_port) }, "properties": { "ip": info['value']['ios']['ip'], "version": info['value']['os']['version'], "sdkVersion": info['value']['os']['sdkVersion'], } }) # yapf: disable elif status == "update": assert isinstance(info, dict) info = defaultdict(dict, info) await hbc.device_update({ "udid": d.udid, "properties": { "ip": info['value']['ios']['ip'], "version": info['value']['os']['version'], "sdkVersion": info['value']['os']['sdkVersion'], } }) # yapf: disable elif status == "offline": await hbc.device_update({ "udid": d.udid, "provider": None, }) else: logger.error("Unknown status: %s", status)
async def _device_callback(d: idb.WDADevice, status: str, info: Union[dict, None] = None): """ monitor device status """ wd = idb.WDADevice if status == wd.status_preparing: await hbc.device_update({ "udid": d.udid, "provider": None, # no provider indicate not present "colding": False, "properties": { "name": d.name, "product": d.product, "brand": "Apple", } }) elif status == wd.status_ready: logger.debug("%s %s", d, "healthcheck passed") assert isinstance(info, dict) info = defaultdict(dict, info) await hbc.device_update({ # "colding": False, "udid": d.udid, "provider": { "wdaUrl": "http://{}:{}".format(current_ip(), d.public_port) }, "properties": { "ip": info['value']['ios']['ip'], "version": info['value']['os']['version'], "sdkVersion": info['value']['os']['sdkVersion'], } }) # yapf: disable elif status == wd.status_fatal: await hbc.device_update({ "udid": d.udid, "provider": None, }) else: logger.error("Unknown status: %s", status)