Skip to content

Commit

Permalink
add t3 [info|install], t3 install is alias for t3 app install
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Feb 27, 2024
1 parent 46e3746 commit b6749bc
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 17 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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: |
Expand Down
15 changes: 14 additions & 1 deletion tidevice3/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import datetime
import io
import os
from typing import Iterator, Optional

import requests
Expand All @@ -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):
Expand Down Expand Up @@ -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)
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)
14 changes: 3 additions & 11 deletions tidevice3/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tidevice3/cli/cli_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
18 changes: 18 additions & 0 deletions tidevice3/cli/info.py
Original file line number Diff line number Diff line change
@@ -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)

19 changes: 19 additions & 0 deletions tidevice3/cli/install.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b6749bc

Please sign in to comment.