Last active
January 4, 2016 14:16
-
-
Save mgasiorowski/2f517f674885b26da3c1 to your computer and use it in GitHub Desktop.
Android SDK updated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import subprocess | |
import re | |
import sys | |
import os | |
parser = argparse.ArgumentParser(description="Android SDK updater") | |
parser.add_argument("-o", "--proxy-host", dest="proxy_host", help="HTTP/HTTPS proxy host") | |
parser.add_argument("-p", "--proxy-port", dest="proxy_port", help="HTTP/HTTPS proxy port") | |
args = parser.parse_args() | |
sdk_path = "{0}/tools/android".format(os.environ["ANDROID_HOME"]) | |
if args.proxy_host is not None and args.proxy_port is not None: | |
android_output = subprocess.check_output("{0} list sdk --all --proxy-host {1} --proxy-port {2} --no-https".format(sdk_path, args.proxy_host, args.proxy_port), shell=True, stderr=subprocess.STDOUT) | |
else: | |
android_output = subprocess.check_output("{0} list sdk --all".format(sdk_path), shell=True, stderr=subprocess.STDOUT) | |
lines = android_output.split("\n") | |
build_tools = filter(lambda x: "Build-tools" in x, lines) | |
filters = [] | |
for tool in build_tools: | |
search_id = re.search("^\s+([0-9]+)-", tool) | |
build_tool_id = search_id.group(1) | |
filters.append(build_tool_id) | |
if len(filters) == 0: | |
print android_output | |
raise Exception("Problem with SDK list") | |
filters.extend(['tools', 'platform-tools', 'extra-android-m2repository', 'extra-android-support', 'extra-google-analytics_sdk_v2', 'extra-google-google_play_services_froyo', 'extra-google-google_play_services', 'extra-google-m2repository', 'extra-google-gcm']) | |
filter = ",".join(filters) | |
if args.proxy_host is not None and args.proxy_port is not None: | |
expect = 'echo y | {0} update sdk --proxy-host {1} --proxy-port {2} --no-https --no-ui --all --filter {3};'.format(sdk_path, args.proxy_host, args.proxy_port, filter) | |
else: | |
expect = 'echo y | {0} update sdk --no-ui --all --filter {1};'.format(sdk_path, filter) | |
print expect | |
ret = subprocess.call(expect, shell=True) | |
sys.exit(ret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment