Skip to content

Instantly share code, notes, and snippets.

@rickychien
Last active October 6, 2015 06:24
Show Gist options
  • Save rickychien/50e091bec53d4dce1392 to your computer and use it in GitHub Desktop.
Save rickychien/50e091bec53d4dce1392 to your computer and use it in GitHub Desktop.
from __future__ import print_function
import os
import platform
import subprocess
import urlparse
import requests
import mozinstall
def download_b2g_sdk(b2g_sdk):
system = platform.system()
if system == "Linux":
url = "https://queue.taskcluster.net/v1/task/YamDhuDgTWa_kWXcSedDHA/artifacts/public/build/target.linux-x86_64.tar.bz2"
elif system == "Darwin":
url = "http://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/2015/09/2015-09-02-03-02-03-mozilla-central/b2g-43.0a1.en-US.mac64.dmg"
elif system == "Windows":
url = "http://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/2015/09/2015-09-02-03-02-03-mozilla-central/b2g-43.0a1.en-US.win32.zip"
else:
raise Exception('Unable to download b2g_sdk for %s' % system)
if not os.path.isdir(b2g_sdk):
os.mkdir(b2g_sdk)
b2g_path = os.path.join(b2g_sdk, "b2g")
if not os.path.isdir(b2g_path):
file_path = os.path.join(b2g_sdk, os.path.basename(urlparse.urlparse(url).path))
with open(file_path, "wb") as b2g:
print("Downloading %s" % url)
response = requests.get(url, stream=True)
total_length = response.headers.get("content-length")
if total_length is None: # no content length header
b2g.write(response.content)
else:
download_length = 0
total_length = int(total_length)
for data in response.iter_content(8192):
download_length += len(data)
b2g.write(data)
print("\r%10d / %10d [%3.2f%%]" %
(download_length,
total_length,
download_length * 100. / total_length),
end = "")
b2g.close()
print()
print("Extract %s..." % file_path)
mozinstall.install(file_path, os.path.join(b2g_sdk))
if system == "Darwin":
os.symlink(os.path.join(b2g_sdk, "B2G.app", "Contents", "MacOS"), b2g_path)
return b2g_path
download_b2g_sdk(os.path.join(os.getcwd(), "b2g_sdk"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment