feat: download dev image, fixing PermissionError while opening another opening temp file in Windows

main
Khiem Ton 2 years ago
parent 8b666b9c77
commit 00ac83c929
Signed by: th4tkh13m
GPG Key ID: 4D9CF147DCADD05D

@ -1,10 +1,14 @@
from pathlib import Path
from pymobiledevice3.lockdown import LockdownClient
from pymobiledevice3.cli.mounter import MobileImageMounterService, download_developer_disk_image
from pymobiledevice3.cli.mounter import MobileImageMounterService
from pymobiledevice3.cli.developer import DtSimulateLocation
from pymobiledevice3.services.diagnostics import DiagnosticsService
from pymobiledevice3.exceptions import PasscodeRequiredError
import logging
import requests
import tempfile
import zipfile
from tqdm import tqdm
from ispoof.utils import get_home_folder
DEVELOPER_DISK_IMAGE_URL = 'https://github.com/pdso/DeveloperDiskImage/raw/master/{ios_version}/{ios_version}.zip'
@ -33,11 +37,11 @@ class Device:
image_dir = f'{get_home_folder()}/DevDiskImage/'
image_path = f'{image_dir}/DeveloperDiskImage.dmg'
signature = f'{image_path}.signature'
developer_disk_image_dir = Path(image_dir)
developer_disk_image_dir = Path(image_path).parent
if not developer_disk_image_dir.exists():
try:
download_developer_disk_image(version, developer_disk_image_dir)
self.download_developer_disk_image(version, developer_disk_image_dir)
except PermissionError:
logger.error(
f'DeveloperDiskImage could not be saved to path ({developer_disk_image_dir}). '
@ -65,8 +69,18 @@ class Device:
self.location.clear()
self.diagnostics.restart()
def get_ios_version(self):
pass
def download_developer_disk_image(self, ios_version, directory):
url = DEVELOPER_DISK_IMAGE_URL.format(ios_version=ios_version)
with requests.get(url, stream=True) as r:
r.raise_for_status()
total_size_in_bytes = int(r.headers.get('content-length', 0))
with tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True, dynamic_ncols=True) as progress_bar:
with tempfile.NamedTemporaryFile('wb+') as f:
for chunk in r.iter_content(chunk_size=8192):
progress_bar.update(len(chunk))
f.write(chunk)
zip_file = zipfile.ZipFile(f)
zip_file.extractall(directory)

Loading…
Cancel
Save