Skip to content

Commit

Permalink
made install_from_bytes separate
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdullah-Albanna committed Oct 30, 2024
1 parent f0fa896 commit 99272ec
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions pymobiledevice3/services/installation_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ 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: Union[str, bytes], options: Optional[dict] = None, handler: Callable = None, *args) -> None:
def install(self, package: str, options: Optional[dict] = None, handler: Callable = None, *args) -> None:
""" install given ipa/ipcc from device path """
self.install_package(package, 'Install', options, handler, args)
self.install_from_local(package, 'Install', options, handler, args)

def upgrade(self, ipa_path: Union[str, bytes], options: Optional[dict] = None, handler: Callable = None, *args) -> None:
def upgrade(self, ipa_path: str, options: Optional[dict] = None, handler: Callable = None, *args) -> None:
""" upgrade given ipa from device path """
self.install_package(ipa_path, 'Upgrade', options, handler, args)
self.install_from_local(ipa_path, 'Upgrade', options, handler, args)

def restore(self, bundle_identifier: str, options: Optional[dict] = None, handler: Callable = None, *args) -> None:
""" no longer supported on newer iOS versions """
Expand All @@ -117,20 +117,14 @@ def uninstall(self, bundle_identifier: str, options: Optional[dict] = None, hand
""" uninstall given bundle_identifier """
self.send_cmd_for_bundle_identifier(bundle_identifier, 'Uninstall', options, handler, args)

def install_package(self, package: Union[str, bytes], cmd: str = 'Install', options: Optional[dict] = None,
handler: Callable = None, *args) -> None:
""" upload given ipa/ipcc onto device and install it """
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'

if options is None:
options = {}

if isinstance(package, str):
self.install_from_local(package, cmd, options, handler, *args)
elif isinstance(package, bytes):
self.install_from_bytes(package, cmd, options, handler, *args)

def install_from_bytes(self, package_bytes: bytes, cmd: str, options: Optional[dict], handler: Callable, *args) -> None:
ipcc_mode = classify_zip_file(package_bytes) == 'ipcc'

if ipcc_mode:
options['PackageType'] = 'CarrierBundle'

Expand All @@ -144,11 +138,17 @@ def install_from_bytes(self, package_bytes: bytes, cmd: str, options: Optional[d
self.send_package(cmd, options, handler, ipcc_mode, *args)

@str_to_path('package_path')
def install_from_local(self, package_path: Path, cmd: str, options: Optional[dict], handler: Callable, *args) -> None:
def install_from_local(self, package_path: Path, cmd: str = 'Install', options: Optional[dict] = None,
handler: Callable = None, *args) -> None:
""" upload given ipa/ipcc onto device and install it """
ipcc_mode = package_path.suffix == '.ipcc'

if options is None:
options = {}

if ipcc_mode:
options['PackageType'] = 'CarrierBundle'

else:
if package_path.is_dir():
# treat as app, convert into an ipa
Expand Down

0 comments on commit 99272ec

Please sign in to comment.