diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 95099c1..19a2f12 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -14,10 +14,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: 3.8 - name: Install dependencies run: | @@ -42,7 +42,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: 3.8 - name: Install dependencies run: | diff --git a/tidevice3/api.py b/tidevice3/api.py index 5ef9fef..3bb44d4 100644 --- a/tidevice3/api.py +++ b/tidevice3/api.py @@ -3,6 +3,7 @@ import datetime import io +import os from typing import Iterator, Optional import requests @@ -14,9 +15,11 @@ from pymobiledevice3.services.dvt.dvt_secure_socket_proxy import DvtSecureSocketProxyService from pymobiledevice3.services.dvt.instruments.device_info import DeviceInfo from pymobiledevice3.services.dvt.instruments.screenshot import Screenshot +from pymobiledevice3.services.installation_proxy import InstallationProxyService from pymobiledevice3.services.screenshot import ScreenshotService from tidevice3.exceptions import FatalError +from tidevice3.utils.download import download_file, is_hyperlink class DeviceShortInfo(BaseModel): @@ -123,4 +126,14 @@ def proclist(service_provider: LockdownClient) -> Iterator[ProcessInfo]: for process in processes: if 'startDate' in process: process['startDate'] = str(process['startDate']) - yield ProcessInfo.model_validate(process) \ No newline at end of file + yield ProcessInfo.model_validate(process) + + +def app_install(service_provider: LockdownClient, path_or_url: str): + if is_hyperlink(path_or_url): + ipa_path = download_file(path_or_url) + elif os.path.isfile(path_or_url): + ipa_path = path_or_url + else: + raise ValueError("local file not found", path_or_url) + InstallationProxyService(lockdown=service_provider).install_from_local(ipa_path) \ No newline at end of file diff --git a/tidevice3/cli/app.py b/tidevice3/cli/app.py index beca2c0..204ca1b 100644 --- a/tidevice3/cli/app.py +++ b/tidevice3/cli/app.py @@ -15,15 +15,13 @@ from pymobiledevice3.cli.cli_common import print_json from pymobiledevice3.lockdown import LockdownClient from pymobiledevice3.services.dvt.dvt_secure_socket_proxy import DvtSecureSocketProxyService -from pymobiledevice3.services.dvt.instruments.device_info import DeviceInfo from pymobiledevice3.services.dvt.instruments.process_control import ProcessControl from pymobiledevice3.services.installation_proxy import InstallationProxyService -from tidevice3.api import proclist +from tidevice3.api import app_install, proclist from tidevice3.cli.cli_common import cli, pass_rsd, pass_service_provider from tidevice3.exceptions import FatalError from tidevice3.utils.common import print_dict_as_table -from tidevice3.utils.download import download_file, is_hyperlink logger = logging.getLogger(__name__) @@ -36,15 +34,9 @@ def app(): @app.command("install") @click.argument("path_or_url") @pass_service_provider -def app_install(service_provider: LockdownClient, path_or_url: str): +def cli_app_install(service_provider: LockdownClient, path_or_url: str): """install given .ipa or url""" - if is_hyperlink(path_or_url): - ipa_path = download_file(path_or_url) - elif os.path.isfile(path_or_url): - ipa_path = path_or_url - else: - raise ValueError("local file not found", path_or_url) - InstallationProxyService(lockdown=service_provider).install_from_local(ipa_path) + app_install(service_provider, path_or_url) @app.command("list") diff --git a/tidevice3/cli/cli_common.py b/tidevice3/cli/cli_common.py index 9fc9549..8f8d5be 100644 --- a/tidevice3/cli/cli_common.py +++ b/tidevice3/cli/cli_common.py @@ -56,6 +56,6 @@ def new_func(ctx, *args, **kwargs): return update_wrapper(new_func, func) -CLI_GROUPS = ["list", "developer", "screenshot", "screenrecord", "fsync", "app", "reboot", "tunneld", "runwda", "exec"] +CLI_GROUPS = ["list", "info", "developer", "screenshot", "screenrecord", "install", "fsync", "app", "reboot", "tunneld", "runwda", "exec"] for group in CLI_GROUPS: __import__(f"tidevice3.cli.{group}") diff --git a/tidevice3/cli/info.py b/tidevice3/cli/info.py new file mode 100644 index 0000000..5374852 --- /dev/null +++ b/tidevice3/cli/info.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""Created on Tue Feb 27 2024 10:38:24 by codeskyblue +""" + +from pymobiledevice3.cli.cli_common import print_json +from pymobiledevice3.lockdown import LockdownClient + +from tidevice3.cli.cli_common import cli, pass_service_provider + + +@cli.command("info") +@pass_service_provider +def info(service_provider: LockdownClient): + """ print device info """ + print_json(service_provider.short_info) + diff --git a/tidevice3/cli/install.py b/tidevice3/cli/install.py new file mode 100644 index 0000000..4864543 --- /dev/null +++ b/tidevice3/cli/install.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""Created on Tue Feb 27 2024 10:05:20 by codeskyblue +""" + +import click +from pymobiledevice3.lockdown import LockdownClient + +from tidevice3.api import app_install +from tidevice3.cli.cli_common import cli, pass_rsd, pass_service_provider + + +@cli.command("install") +@click.argument("path_or_url") +@pass_service_provider +def cli_install(service_provider: LockdownClient, path_or_url: str): + """install given .ipa or url, alias for app install""" + app_install(service_provider, path_or_url)