-
Notifications
You must be signed in to change notification settings - Fork 2
/
apis.py
67 lines (55 loc) · 1.75 KB
/
apis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# vim: fenc=utf-8
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
#
#
"""
File name: apis.py
Author: dhilipsiva <dhilipsiva@gmail.com>
Date created: 2016-06-19
"""
from os import path
# from pprint import pprint
def get_lockdown_and_service(udid):
from pymobiledevice2.lockdown import LockdownClient
lockdown = LockdownClient(udid)
service = lockdown.startService("com.apple.mobile.installation_proxy")
return lockdown, service
def run_command(service, uuid, cmd):
service.sendPlist(cmd)
z = service.recvPlist()
while 'PercentComplete' in z:
if not z:
break
if z.get("Status") == "Complete":
return z.get("Status")
z = service.recvPlist()
service.close()
return z
def install_ipa(uuid, ipa_path):
"""
docstring for install_ipa
"""
from pymobiledevice2.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 uninstall_ipa(uuid, bundle_id):
lockdown, service = get_lockdown_and_service(uuid)
cmd = {"Command": "Uninstall", "ApplicationIdentifier": bundle_id}
return run_command(service, uuid, cmd)
def list_ipas(uuid):
lockdown, service = get_lockdown_and_service(uuid)
cmd = {"Command": "Lookup"}
result = run_command(service, uuid, cmd)
apps_details = result.get("LookupResult")
apps = []
for app in apps_details:
if apps_details[app]['ApplicationType'] == 'User':
apps.append(app)
return apps