Beispiel #1
0
def get_android_sdk_manager():
    """
    Gets the location of SDK manager through CLI while in interactive mode, or via settings.properties if running headlessly
    """
    print common.term.yellow + str(
        common.config.get(
            'qarkhelper',
            'ANDROID_SDK_INFO')).decode('string-escape').format(t=common.term)
    print common.term.cyan
    choice = raw_input(
        common.config.get('qarkhelper', 'GET_ANDROID_SDK_MANAGER_PROMPT'))
    if str(choice).lower() == 'y':
        download_sdk()
    else:
        AndroidSDKPath = raw_input(
            common.config.get('qarkhelper', 'ANDROID_SDK_MANAGER_PATH_PROMPT'))
        if not str(AndroidSDKPath).endswith("/"):
            AndroidSDKPath = str(AndroidSDKPath).strip() + "/"
        #common.writeKey('AndroidSDKPath', AndroidSDKPath)
        while not (os.path.exists(AndroidSDKPath + "tools")):
            logger.error(
                str(
                    common.config.get(
                        'qarkhelper',
                        'ANDROID_SDK_MANAGER_PATH_PROMPT_AGAIN')).decode(
                            'string-escape'))
            print common.term.cyan
            AndroidSDKPath = raw_input(
                common.config.get('qarkhelper',
                                  'ANDROID_SDK_MANAGER_PATH_PROMPT'))
            if not str(AndroidSDKPath).endswith("/"):
                AndroidSDKPath = str(AndroidSDKPath).strip() + "/"
        common.writeKey('AndroidSDKPath', AndroidSDKPath)
        common.AndroidSDKPath = AndroidSDKPath
    common.logger.debug("Located SDK")
def get_android_sdk_manager():
    """
    Gets the location of SDK manager through CLI while in interactive mode, or via settings.properties if running headlessly
    """
    print common.term.yellow + str(common.config.get('qarkhelper','ANDROID_SDK_INFO')).decode('string-escape').format(t=common.term)
    print common.term.cyan
    choice=raw_input(common.config.get('qarkhelper','GET_ANDROID_SDK_MANAGER_PROMPT'))
    if str(choice).lower()=='y':
        download_sdk()
    else:
        AndroidSDKPath=raw_input(common.config.get('qarkhelper','ANDROID_SDK_MANAGER_PATH_PROMPT'))
        if not str(AndroidSDKPath).endswith("/"):
            AndroidSDKPath = str(AndroidSDKPath).strip() + "/"
        #common.writeKey('AndroidSDKPath', AndroidSDKPath)
        while not (os.path.exists(AndroidSDKPath + "tools")):
            logger.error(str(common.config.get('qarkhelper','ANDROID_SDK_MANAGER_PATH_PROMPT_AGAIN')).decode('string-escape'))
            print common.term.cyan
            AndroidSDKPath=raw_input(common.config.get('qarkhelper','ANDROID_SDK_MANAGER_PATH_PROMPT'))
            if not str(AndroidSDKPath).endswith("/"):
                AndroidSDKPath = str(AndroidSDKPath).strip() + "/"
        common.writeKey('AndroidSDKPath', AndroidSDKPath)
        common.AndroidSDKPath = AndroidSDKPath
    common.logger.debug("Located SDK")
def download_sdk():
    """
    Download the SDK from Google
    """

    url = ""
    url_macosx = "https://dl.google.com/android/android-sdk_r24.0.2-macosx.zip"
    url_linux = "https://dl.google.com/android/android-sdk_r24.3.4-linux.tgz"

    if sys.platform == "linux2":
        url = url_linux
    else:
        url = url_macosx

    file_name = url.split('/')[-1]
    u = urllib2.urlopen(url)
    f = open(common.getConfig("rootDir") + "/" + file_name, 'wb')
    meta = u.info()
    file_size = int(meta.getheaders("Content-Length")[0])
    common.logger.debug("Downloading: %s \r\n FileName: %s \r\n FileSize: \r\n %s" % (url, file_name, file_size))
    
    block_sz = file_size/100
    count = 0
    while True:
        buffer = u.read(block_sz)
        if not buffer:
            break

        f.write(buffer)
        count = count + 1
        if count%10==0:
            sys.stdout.write('\r[{0}] {1}%'.format('#'*(count/10), count))
            sys.stdout.flush()
            
    f.close()
    androidSDKZIP = f.name
    print common.term.cyan + str(common.config.get('qarkhelper','FILE_DOWNLOADED_TO')) + androidSDKZIP.decode('string-escape').format(t=common.term)
    print common.term.cyan + str(common.config.get('qarkhelper','UNPACKING')) + androidSDKZIP.decode('string-escape').format(t=common.term)
    if sys.platform == "linux2":
        try:
            if not os.path.exists(androidSDKZIP.rsplit(".",1)[0]):
                os.makedirs(androidSDKZIP.rsplit(".",1)[0])
            extract(androidSDKZIP, androidSDKZIP.rsplit(".",1)[0])
        except Exception as e:
            logger.error(e.message)
        common.writeKey('AndroidSDKPath', androidSDKZIP.rsplit(".",1)[0] + "/android-sdk-linux/")
    else:
        zf = zipfile.ZipFile(androidSDKZIP)
        for filename in [ zf.namelist()]:
            try:
                if not os.path.exists(androidSDKZIP.rsplit(".",1)[0]):
                    os.makedirs(androidSDKZIP.rsplit(".",1)[0])
                zf.extractall(androidSDKZIP.rsplit(".",1)[0] + "/", zf.namelist(), )
            except Exception as e:
                logger.error(e.message)
            else:
                logger.info('Done')
        common.writeKey('AndroidSDKPath', androidSDKZIP.rsplit(".",1)[0] + "/android-sdk-macosx/")
    #We dont need the ZIP file anymore
    os.remove(androidSDKZIP)
    run_sdk_manager()
Beispiel #4
0
def download_sdk():
    """
    Download the SDK from Google
    """

    url = ""
    url_macosx = "https://dl.google.com/android/android-sdk_r24.0.2-macosx.zip"
    url_linux = "https://dl.google.com/android/android-sdk_r24.3.4-linux.tgz"

    if sys.platform == "linux2":
        url = url_linux
    else:
        url = url_macosx

    file_name = url.split('/')[-1]
    u = urllib2.urlopen(url)
    f = open(common.getConfig("rootDir") + "/" + file_name, 'wb')
    meta = u.info()
    file_size = int(meta.getheaders("Content-Length")[0])
    common.logger.debug(
        "Downloading: %s \r\n FileName: %s \r\n FileSize: \r\n %s" %
        (url, file_name, file_size))

    block_sz = file_size / 100
    count = 0
    while True:
        buffer = u.read(block_sz)
        if not buffer:
            break

        f.write(buffer)
        count = count + 1
        if count % 10 == 0:
            sys.stdout.write('\r[{0}] {1}%'.format('#' * (count / 10), count))
            sys.stdout.flush()

    f.close()
    androidSDKZIP = f.name
    print common.term.cyan + str(
        common.config.get('qarkhelper', 'FILE_DOWNLOADED_TO')
    ) + androidSDKZIP.decode('string-escape').format(t=common.term)
    print common.term.cyan + str(common.config.get(
        'qarkhelper',
        'UNPACKING')) + androidSDKZIP.decode('string-escape').format(
            t=common.term)
    if sys.platform == "linux2":
        try:
            if not os.path.exists(androidSDKZIP.rsplit(".", 1)[0]):
                os.makedirs(androidSDKZIP.rsplit(".", 1)[0])
            extract(androidSDKZIP, androidSDKZIP.rsplit(".", 1)[0])
        except Exception as e:
            logger.error(e.message)
        common.writeKey(
            'AndroidSDKPath',
            androidSDKZIP.rsplit(".", 1)[0] + "/android-sdk-linux/")
    else:
        zf = zipfile.ZipFile(androidSDKZIP)
        for filename in [zf.namelist()]:
            try:
                if not os.path.exists(androidSDKZIP.rsplit(".", 1)[0]):
                    os.makedirs(androidSDKZIP.rsplit(".", 1)[0])
                zf.extractall(
                    androidSDKZIP.rsplit(".", 1)[0] + "/",
                    zf.namelist(),
                )
            except Exception as e:
                logger.error(e.message)
            else:
                logger.info('Done')
        common.writeKey(
            'AndroidSDKPath',
            androidSDKZIP.rsplit(".", 1)[0] + "/android-sdk-macosx/")
    #We dont need the ZIP file anymore
    os.remove(androidSDKZIP)
    run_sdk_manager()