From b85c6d491af00b64a1e595fd96690e579f285018 Mon Sep 17 00:00:00 2001 From: Khiem Ton Date: Sat, 25 Mar 2023 18:50:12 +0700 Subject: [PATCH] refactor: static method to function, indentation --- ispoof/spoofer/device.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/ispoof/spoofer/device.py b/ispoof/spoofer/device.py index 499e4b8..0505497 100644 --- a/ispoof/spoofer/device.py +++ b/ispoof/spoofer/device.py @@ -16,6 +16,20 @@ DEVELOPER_DISK_IMAGE_URL = 'https://github.com/pdso/DeveloperDiskImage/raw/maste logger = logging.getLogger(__name__) +def download_developer_disk_image(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) + + class Device: def __init__(self): self.lockdown = LockdownClient() @@ -41,7 +55,7 @@ class Device: if not developer_disk_image_dir.exists(): try: - self.download_developer_disk_image(version, developer_disk_image_dir) + 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}). ' @@ -69,19 +83,6 @@ class Device: self.location.clear() self.diagnostics.restart() - 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) -