Skip to content

Commit

Permalink
slight changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdullah-Albanna committed Oct 30, 2024
1 parent 99272ec commit 8c31f8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pymobiledevice3/cli/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def uninstall(service_provider: LockdownClient, bundle_id):
@click.argument('package', type=click.Path(exists=True))
def install(service_provider: LockdownServiceProvider, package: str) -> None:
""" install given .ipa/.app/.ipcc """
InstallationProxyService(lockdown=service_provider).install(package)
InstallationProxyService(lockdown=service_provider).install_from_local(package)


@apps.command('afc', cls=Command)
Expand Down
26 changes: 19 additions & 7 deletions pymobiledevice3/services/installation_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from io import BytesIO
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Callable, Literal, Optional, Union
from typing import Callable, Optional, Union
from zipfile import ZIP_DEFLATED, BadZipFile, ZipFile
from enum import Enum

from parameter_decorators import str_to_path

Expand All @@ -20,6 +21,17 @@
TEMP_REMOTE_IPCC_FOLDER = f'{TEMP_REMOTE_BASEDIR}/pymobiledevice3.ipcc'


class ZipFileType(Enum):
IPCC = 'ipcc'
IPA = 'ipa'

def is_ipcc(self) -> bool:
return self == ZipFileType.IPCC

def is_ipa(self) -> bool:
return self == ZipFileType.IPA


def create_ipa_contents_from_directory(directory: str) -> bytes:
payload_prefix = 'Payload/' + os.path.basename(directory)
with TemporaryDirectory() as temp_dir:
Expand All @@ -34,7 +46,7 @@ def create_ipa_contents_from_directory(directory: str) -> bytes:
return zip_path.read_bytes()


def classify_zip_file(zip_bytes: bytes) -> Literal['ipa', 'ipcc']:
def classify_zip_file(zip_bytes: bytes) -> ZipFileType:
""" checks the zipped bytes if it's a .ipcc or .ipa """
try:
with ZipFile(BytesIO(zip_bytes), 'r') as zip_file:
Expand All @@ -44,9 +56,9 @@ def classify_zip_file(zip_bytes: bytes) -> Literal['ipa', 'ipcc']:
if dirs[0] != 'Payload':
raise AppInstallError('package does not have a payload')
if dirs[1].endswith('.app'):
return 'ipa'
return ZipFileType.IPA
elif dirs[1].endswith('.bundle'):
return 'ipcc'
return ZipFileType.IPCC
else:
raise AppInstallError('package does not have the appropriate folders structure')

Expand Down Expand Up @@ -100,9 +112,9 @@ def send_cmd_for_bundle_identifier(self, bundle_identifier: str, cmd: str = 'Arc
self.service.send_plist(cmd)
self._watch_completion(handler, *args)

def install(self, package: str, options: Optional[dict] = None, handler: Callable = None, *args) -> None:
def install(self, package_path: str, options: Optional[dict] = None, handler: Callable = None, *args) -> None:
""" install given ipa/ipcc from device path """
self.install_from_local(package, 'Install', options, handler, args)
self.install_from_local(package_path, 'Install', options, handler, args)

def upgrade(self, ipa_path: str, options: Optional[dict] = None, handler: Callable = None, *args) -> None:
""" upgrade given ipa from device path """
Expand All @@ -120,7 +132,7 @@ def uninstall(self, bundle_identifier: str, options: Optional[dict] = None, hand
def install_from_bytes(self, package_bytes: bytes, cmd: str = 'Install', options: Optional[dict] = None,
handler: Callable = None, *args) -> None:
""" upload given ipa/ipcc bytes object onto device and install it """
ipcc_mode = classify_zip_file(package_bytes) == 'ipcc'
ipcc_mode = classify_zip_file(package_bytes).is_ipcc()

if options is None:
options = {}
Expand Down

0 comments on commit 8c31f8e

Please sign in to comment.