Ejemplo n.º 1
0
def uninstall(path=sdk_path):
    print 'Uninstalling Android SDK at %s' % path
    try:
        shutil.rmtree(path)
    except OSError as err:
        raise errors.RuntimeError(err.errno, str(err))
    print 'Android SDK deleted from %s' % path
Ejemplo n.º 2
0
def sync_cmd(path, purge=False, purge_key=True):
    config = ConfigParser.ConfigParser(allow_no_value=True)
    try:
        res = config.read(path)
    except ConfigParser.Error as err:
        raise errors.RuntimeError(errno.EILSEQ, str(err))
    if len(res) == 0:
        raise errors.RuntimeError(
            errno.EIO, 'Could not load/read config file at %s.' % path)
    sections = config.sections()
    if 'keystore' in sections:
        ks_path = keytool.keytool_path()
        if os.path.exists(ks_path) and purge_key:
            os.remove(ks_path)
        keytool.gen(*[v for k, v in config.items('keystore')])
    pkgs = {}
    for section in [name for name in sections if not name in ['keystore']]:
        pkgs[section] = [k for k, v in config.items(section)]
    pkg.sync(pkgs)
Ejemplo n.º 3
0
def gen(alias, name, unit, org, loc, state, country, storepass, keypass):
    ks_path = keytool_path()
    dname = 'CN=%s, OU=%s, O=%s, L=%s, S=%s, C=%s'
    dname_values = (name, unit, org, loc, state, country)
    cmd = [
        'keytool', '-genkey ', '-noprompt', '-alias', alias, '-dname',
        dname % dname_values, '-keystore', ks_path, '-storepass', storepass,
        '-keypass', keypass, '-keysize', '2048', '-keyalg', 'RSA'
    ]
    code = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr)
    if code != 0:
        raise errors.RuntimeError(code, 'keytool exited abruptly.')
Ejemplo n.º 4
0
def unpack(path=sdk_path):
    print 'Unpacking Android SDK file...'
    try:
        with zipfile.ZipFile('%s/android-sdk-linux.zip' % path, 'r') as zf:
            for info in zf.infolist():
                zf.extract(info.filename, path=path)
                dest = os.path.join(path, info.filename)
                perm = info.external_attr >> 16L
                os.chmod(dest, perm)
    except IOError as err:
        raise errors.RuntimeError(err.errno, str(err))
    print 'Android SDK available at %s' % path
Ejemplo n.º 5
0
def download(url=sdk_url, path=sdk_path):
    if not os.path.exists(path):
        print 'Path %s does not exist, creating it...' % path
        try:
            os.mkdir(path)
        except OSError as err:
            raise errors.RuntimeError(err.errno, str(err))
    if os.path.exists('%s/android-sdk-linux.zip' % path):
        print 'Android SDK already downloaded'
        return
    print 'Downloading Android SDK from %s' % url
    try:
        res = requests.get(url, stream=True)
    except requests.exceptions.RequestException as err:
        raise errors.ConnectionError(err.message)
    try:
        with open('%s/android-sdk-linux.zip' % path, 'wb') as f:
            for chunk in res.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)
    except IOError as err:
        raise errors.RuntimeError(err.errno, str(err))
    print 'Android SDK downloaded'
Ejemplo n.º 6
0
def manager(*args):
    cmd = '%s/tools/bin/sdkmanager' % sdk_path
    cmd_args = [sdk_shell, cmd]
    proxy_settings = utils.get_proxy_settings(https_proxy)
    if proxy_settings:
        proxy_flags = ['--proxy=http', '--proxy_host=%s' % proxy_settings[0]]
        if proxy_settings[1]:
            proxy_flags.append('--proxy_port=%s' % proxy_settings[1])
        cmd_args.extend(proxy_flags)
    cmd_args.extend(args)
    print 'Running android sdkmanager, this might take a while.'
    code = subprocess.call(cmd_args, stdout=sys.stdout, stderr=sys.stderr)
    if code != 0:
        raise errors.RuntimeError(code, 'SDKManager exited abruptly.')