Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --limit-rate option for slow links #95

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions installinstallmacos.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ def replicate_url(full_url,
root_dir='/tmp',
show_progress=False,
ignore_cache=False,
attempt_resume=False):
attempt_resume=False,
limit_rate=None):
'''Downloads a URL and stores it in the same relative path on our
filesystem. Returns a path to the replicated file.'''

Expand All @@ -270,6 +271,10 @@ def replicate_url(full_url,
'--create-dirs',
'-o', local_file_path,
'-w', '%{http_code}']

if limit_rate is not None:
curl_cmd.extend(['--limit-rate', limit_rate])

if not full_url.endswith(".gz"):
# stupid hack for stupid Apple behavior where it sometimes returns
# compressed files even when not asked for
Expand Down Expand Up @@ -464,7 +469,12 @@ def os_installer_product_info(catalog, workdir, ignore_cache=False):
return product_info


def replicate_product(catalog, product_id, workdir, ignore_cache=False):
def replicate_product(
catalog,
product_id,
workdir,
ignore_cache=False,
limit_rate=None):
'''Downloads all the packages for a product'''
product = catalog['Products'][product_id]
for package in product.get('Packages', []):
Expand All @@ -476,15 +486,17 @@ def replicate_product(catalog, product_id, workdir, ignore_cache=False):
replicate_url(
package['URL'], root_dir=workdir,
show_progress=True, ignore_cache=ignore_cache,
attempt_resume=(not ignore_cache))
attempt_resume=(not ignore_cache),
limit_rate=limit_rate)
except ReplicationError as err:
print('Could not replicate %s: %s' % (package['URL'], err),
file=sys.stderr)
exit(-1)
if 'MetadataURL' in package:
try:
replicate_url(package['MetadataURL'], root_dir=workdir,
ignore_cache=ignore_cache)
ignore_cache=ignore_cache,
limit_rate=limit_rate)
except ReplicationError as err:
print('Could not replicate %s: %s'
% (package['MetadataURL'], err), file=sys.stderr)
Expand Down Expand Up @@ -525,6 +537,8 @@ def main():
'less available disk space and is faster.')
parser.add_argument('--ignore-cache', action='store_true',
help='Ignore any previously cached files.')
parser.add_argument('--limit-rate', metavar='limit_rate', default=None,
help='limit the download speed per curl --limit-rate')
args = parser.parse_args()

if os.getuid() != 0:
Expand Down Expand Up @@ -595,7 +609,11 @@ def main():

# download all the packages for the selected product
replicate_product(
catalog, product_id, args.workdir, ignore_cache=args.ignore_cache)
catalog,
product_id,
args.workdir,
ignore_cache=args.ignore_cache,
limit_rate=args.limit_rate)

# generate a name for the sparseimage
volname = ('Install_macOS_%s-%s'
Expand Down