def install(self, ipa_path, options=None, handler=None, *args): '''安装应用程序 :param ipa_path: 安装包的路径 :type ipa_path: str :return: boolean - 安装是否成功 ''' print "上传安装包..." afc_client = AFCClient(self.lockdown) tmp_ipa = "t%d.ipa" % time.time() with open(ipa_path, "rb") as f: ipa_content = f.read() afc_client.set_file_contents("/" + tmp_ipa, ipa_content) print "上传完毕" print "开始安装" cmd = {"Command": "Install", "PackagePath": tmp_ipa} if options: cmd.update(options) self.lockdown = LockdownClient(self.udid) self.service = self.lockdown.startService( "com.apple.mobile.installation_proxy") self.service.sendPlist(cmd) ret = self.wait_completion(handler, args) if ret[0]: print "安装成功" else: print "安装失败:%s" % ret[1] return ret
def install_or_upgrade(self, ipaPath, cmd="Install", options=None, handler=None, *args): afc = AFCClient(self.lockdown) afc.set_file_contents("/" + os.path.basename(ipaPath), open(ipaPath,"rb").read()) cmd = {"Command":cmd, "PackagePath": os.path.basename(ipaPath)} if options: cmd.update(options) self.service.sendPlist(cmd) # print "%s : " % (cmd, bundleID) print "%s : %s\n" % (cmd, self.watch_completion(handler, args))
def install_or_upgrade(self, ipaPath, cmd="Install", options={}, handler=None, *args): afc = AFCClient(self.lockdown) afc.set_file_contents("/" + os.path.basename(ipaPath), open(ipaPath,"rb").read()) cmd = { "Command": cmd, "ClientOptions": options, "PackagePath": os.path.basename(ipaPath)} self.service.sendPlist(cmd) self.watch_completion(handler, args)
def install_ipa(uuid, ipa_path): """ docstring for install_ipa """ from pymobiledevice.afc import AFCClient lockdown, service = get_lockdown_and_service(uuid) afc = AFCClient(lockdown=lockdown) afc.set_file_contents(path.basename(ipa_path), open(ipa_path, "rb").read()) cmd = {"Command": "Install", "PackagePath": path.basename(ipa_path)} return run_command(service, uuid, cmd)
def install_or_upgrade(self, ipaPath, cmd="Install", options=None, handler=None, *args): afc = AFCClient(self.lockdown) afc.set_file_contents("/" + os.path.basename(ipaPath), open(ipaPath, "rb").read()) cmd = {"Command": cmd, "PackagePath": os.path.basename(ipaPath)} if options: cmd.update(options) self.service.sendPlist(cmd) # print "%s : " % (cmd, bundleID) print "%s : %s\n" % (cmd, self.watch_completion(handler, args))
def install_or_upgrade(self, ipaPath, cmd="Install", options={}, handler=None, *args): afc = AFCClient(self.lockdown) afc.set_file_contents("/" + os.path.basename(ipaPath), open(ipaPath, "rb").read()) cmd = { "Command": cmd, "ClientOptions": options, "PackagePath": os.path.basename(ipaPath) } self.service.sendPlist(cmd) self.watch_completion(handler, args)
def test_install_app(self): if self.no_device: return ipa_path = os.path.join(os.path.expanduser("~"), "Downloads/app/DemoApp.ipa") tmp_ipa = "/t%d.ipa" % time.time() with open(ipa_path, "rb") as f: ipa_content = f.read() afc = AFCClient(self.lockdownclient) afc.set_file_contents(tmp_ipa, ipa_content) print("Upload completed") print("Starting installation") cmd = {"Command":"Install", "PackagePath": tmp_ipa} self.lockdownclient = LockdownClient(self.udid) self.service = self.lockdownclient.startService("com.apple.mobile.installation_proxy") self.service.sendPlist(cmd) result, err = self.wait_completion() self.assertTrue(result, 'install_app failed: %s' % err)
def install(self, ipa_path, options=None, handler=None, *args): '''安装应用程序 :param ipa_path: 安装包的路径 :type ipa_path: str :return: boolean - 安装是否成功 ''' print "上传安装包..." afc_client = AFCClient() tmp_ipa = "t%d.ipa" % time.time() with open(ipa_path, "rb") as f: ipa_content = f.read() afc_client.set_file_contents("/" + tmp_ipa, ipa_content) print "上传完毕" print "开始安装" cmd = {"Command": "Install", "PackagePath": tmp_ipa} if options: cmd.update(options) self.service.sendPlist(cmd) return self.wait_completion(handler, args)
def mobile_install(lockdown, ipaPath): # Start afc service & upload ipa afc = AFCClient(lockdown) afc.set_file_contents("/" + os.path.basename(ipaPath), open(ipaPath, 'rb').read()) mci = lockdown.startService("com.apple.mobile.installation_proxy") #print mci.sendPlist({"Command":"Archive","ApplicationIdentifier": "com.joystickgenerals.STActionPig"}) mci.sendPlist({"Command": "Install", # "ApplicationIdentifier": "com.gotohack.JBChecker", "PackagePath": os.path.basename(ipaPath)}) while True: z = mci.recvPlist() if not z: break completion = z.get('PercentComplete') if completion: print('Installing, %s: %s %% Complete' % ( ipaPath, z['PercentComplete'])) if z.get('Status') == 'Complete': print("Installation %s\n" % z['Status']) break
def mobile_install(lockdown, ipaPath): # Start afc service & upload ipa afc = AFCClient(lockdown) afc.set_file_contents("/" + os.path.basename(ipaPath), open(ipaPath, 'rb').read()) mci = lockdown.startService("com.apple.mobile.installation_proxy") # print mci.sendPlist({"Command":"Archive","ApplicationIdentifier": # "com.joystickgenerals.STActionPig"}) mci.sendPlist({"Command": "Install", #"ApplicationIdentifier": "com.gotohack.JBChecker", "PackagePath": os.path.basename(ipaPath)}) while True: z = mci.recvPlist() if not z: break completion = z.get('PercentComplete') if completion: print('Installing, %s: %s %% Complete' % (ipaPath, z['PercentComplete'])) if z.get('Status') == 'Complete': print("Installation %s\n" % z['Status']) break
class HouseArrestTest(unittest.TestCase): def setUp(self): mux = USBMux() if not mux.devices: mux.process(0.1) if len(mux.devices) == 0: print("no real device found") self.no_device = True return udid = mux.devices[0].serial lockdown_client = LockdownClient(udid) self.service = lockdown_client.startService( "com.apple.mobile.house_arrest") self.service.sendPlist({ "Command": "VendContainer", "Identifier": "com.gotohack.testapp" }) status = self.service.recvPlist() if 'Error' in status and status['Error'] == "ApplicationLookupFailed": raise RuntimeWarning('ApplicationLookupFailed') if 'Status' in status and status['Status'] != 'Complete': raise RuntimeWarning('House arrest service launch failed') self.afc = AFCClient(lockdown_client, service=self.service) self.afc_shell = AFCShell(client=self.afc) def test_list_files_in_sandbox(self): if self.no_device: return sandbox_tree = [] file_path = '/Documents' for l in self.afc.read_directory(file_path): if l not in ('.', '..'): tmp_dict = {} tmp_dict['path'] = os.path.join(file_path, l) info = self.afc.get_file_info(tmp_dict['path']) tmp_dict['is_dir'] = (info is not None and info['st_ifmt'] == 'S_IFDIR') sandbox_tree.append(tmp_dict) pprint.pprint(sandbox_tree) def test_push_file_to_sandbox(self): if self.no_device: return data = b"hello sandbox!" self.afc.set_file_contents('/Documents/test.log', data) def test_pull_file_from_sandbox(self): if self.no_device: return data = b"hello sandbox!" content = self.afc.get_file_contents('/Documents/test.log') print(content) def test_remove_file_in_sandbox(self): if self.no_device: return self.afc_shell.do_rm('/Documents/test.log') def tearDown(self): if not self.no_device and self.service: self.service.close()