Skip to content

Instantly share code, notes, and snippets.

@rosston
Last active May 23, 2020 03:21
Show Gist options
  • Save rosston/d164b2d6079bfbff1f83c139f24973d9 to your computer and use it in GitHub Desktop.
Save rosston/d164b2d6079bfbff1f83c139f24973d9 to your computer and use it in GitHub Desktop.
A script for watching and reporting progress of iOS update file downloads
#
# A script for watching and reporting progress of iOS update file downloads.
#
# Supported platforms: macOS
#
# Once your update begins downloading, run
# * on macOS:
# python3 /path/to/ios-update-watcher.py
#
import collections
import os
import os.path
import platform
import time
UPDATE_PATH = os.path.expanduser('~/Library/iTunes/iPhone Software Updates')
last_sizes = collections.deque(maxlen=3)
def get_last_file_path():
def path_with_ctime(file):
path = os.path.join(UPDATE_PATH, file)
return (path, os.lstat(path).st_ctime)
paths_with_ctimes = map(path_with_ctime, os.listdir(UPDATE_PATH))
paths_with_ctimes_sorted_by_ctime = sorted(
paths_with_ctimes, key=lambda x: x[1])
most_recent_path_with_ctime = paths_with_ctimes_sorted_by_ctime[-1]
return most_recent_path_with_ctime[0]
last_file_path = get_last_file_path()
def main():
is_update_finished = False
print('Checking download progress for:', last_file_path)
print('')
while not is_update_finished:
is_update_finished = has_update_finished()
if not is_update_finished:
time.sleep(5)
print('\n\n\nFINISHED UPDATE!!!')
if platform.system() == 'Darwin':
os.system('say "O M G, yay, your iOS update finally finished downloading!"')
def has_update_finished():
last_file_size = os.lstat(last_file_path).st_size
print('File size:', sizeof_fmt(last_file_size))
last_sizes.append(last_file_size)
return len(last_sizes) == 3 and len(set(last_sizes)) == 1
# Copied wholesale from https://stackoverflow.com/a/1094933
def sizeof_fmt(num, suffix='B'):
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
# End wholesale copy
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment