Exemplo n.º 1
0
    def list_others(self):
        cmd = '%s --verbose --list --include_obsolete' % self._get_sdk_manager_path()
        return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd)
        if return_code != 0:
            print_error_and_exit('Failed to list packages')

        print('Installed Packages:')
        lines = stdout.split('\n')
        for (i, line) in enumerate(lines):
            line = line.strip()
            previous_line = None
            if i > 0:
                previous_line = lines[i - 1].strip()

            is_package_name = not previous_line or previous_line.startswith('---')

            if not is_package_name:
                continue

            print_verbose('Line is \"%s\" and previous line is \"%s\"' % (line, previous_line))

            if not line:
                continue
            elif line.startswith('system-images;') or line.startswith('platforms;') or line.startswith('sources;'):
                continue
            elif line.startswith('platform-tools'):
                continue
            elif line.startswith('build-tools;'):
                continue
            elif line.find('Info:') != -1:
                continue

            if line.endswith(':'):
                print('')
            print(line)
Exemplo n.º 2
0
    def _get_binary(binary_name, binary_paths_relative_to_android_sdk) -> str:
        sdk_location = AndroidSdkHelper._get_location_of_android_sdk()
        if not sdk_location:
            print_verbose('ANDROID_SDK_ROOT not defined')
        else:
            for relative_path in binary_paths_relative_to_android_sdk:
                binary_path = os.path.join(sdk_location, relative_path)
                if os.path.exists(binary_path):
                    print_error('\"%s\" found at \"%s\"' %
                                (binary_name, binary_path))
                    return binary_path
                else:
                    print_error('\"%s\" not found at \"%s\"' %
                                (binary_name, binary_path))

        # Only works on Mac and GNU/Linux
        if PlatformHelper.on_linux() or PlatformHelper.on_mac():
            return_code, stdout, stderr = PlatformHelper.execute_cmd(
                'command -v %s' % binary_name)
            if return_code == 0:
                return stdout.strip()
            else:
                print_error('\"%s\" not in path' % binary_name)
        print_error_and_exit(
            'Set ANDROID_SDK_ROOT environment variable to point to Android SDK root'
        )
Exemplo n.º 3
0
 def _accept_all_licenses(self):
     cmd = 'yes | %s --licenses' % self._get_sdk_manager_path()
     return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd)
     if return_code != 0:
         print_error_and_exit('Failed to accept licenses, return code: %d' % return_code)
     license_regex = '([0-9]*) of ([0-9]*) SDK package licenses not accepted'
     result = re.search(license_regex, stdout)
     if result is None:
         print_message('All licenses accepted')
     else:
         print_message('%d of %d licenses accepted' % (int(result.group(1)), int(result.group(2))))
Exemplo n.º 4
0
 def _get_build_tools(self) -> [str]:
     """
     :return: List of build tools packages, sorted by version number, latest package comes last
     """
     cmd = '%s --verbose --list --include_obsolete' % self._get_sdk_manager_path()
     return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd)
     if return_code != 0:
         print_error_and_exit('Failed to list build tools, stdout: %s, stderr: %s' % (stdout, stderr))
     build_tools = re.findall(_BUILD_TOOLS_REGEX, stdout)
     build_tools = sorted(set(build_tools))
     print_verbose('Build tools are %s' % build_tools)
     return build_tools
Exemplo n.º 5
0
    def _get_all_java_versions() -> [str]:
        if PlatformHelper.on_linux():
            return_code, stdout, stderr = PlatformHelper.execute_cmd(_GET_ALL_JAVA_VERSIONS_ON_LINUX)
            java_version_regex = 'java-([0-9]+.*?)/'
        elif PlatformHelper.on_mac():
            java_version_regex = r'"([0-9]+\.[0-9]+)\..*"'
            return_code, stdout, stderr = PlatformHelper.execute_cmd(_GET_ALL_JAVA_VERSIONS_ON_MAC)
        else:
            print_error('Unsupported operating system')
            return []

        if return_code != 0:
            print_error('Failed to list java versions')
            return []
        output = ''
        output += stdout
        output += stderr
        versions = re.findall(java_version_regex, output)
        versions = set(versions)
        print_verbose('Versions are %s' % versions)
        return versions
Exemplo n.º 6
0
 def _get_default_java_version() -> Optional[str]:
     return_code, stdout, stderr = PlatformHelper.execute_cmd('java -version')
     if return_code != 0:
         print_error('Failed to get java version')
         return None
     # TODO(ashishb): Do I need two different regex for Mac and Linux like _get_all_java_versions here?
     java_version_regex = r'"([0-9]+\.[0-9]+)\..*"'
     version = re.search(java_version_regex, stderr)
     if version is None:
         return None
     print_verbose('version object is %s' % version)
     return version.group(1)
Exemplo n.º 7
0
 def start_avd(self, avd_name, headless_mode, verbose_mode):
     # cmd = '%s -avd %s -no-boot-anim -no-skin' % (self._get_emulator_path(), avd_name)
     cmd = '%s -avd %s -no-boot-anim' % ('./emulator', avd_name)
     if headless_mode:
         cmd = '%s -no-window' % cmd.strip()
     if verbose_mode:
         cmd = '%s -verbose' % cmd.strip()
     return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd, cwd=os.path.dirname(self._get_emulator_path()))
     if return_code != 0:
         print_error('Failed to start emulator\nstdout:\n' + stdout + '\n\nstderr:\n' + stderr)
         print_message('List of valid virtual devices')
         self.list_avds()
Exemplo n.º 8
0
 def list_avds(self):
     avd_manager = self._get_avd_manager_path()
     if not avd_manager:
         print_error_and_exit('avdmanager not found')
     cmd = '%s --verbose list avd' % avd_manager
     return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd)
     if return_code != 0:
         print_error_and_exit('Failed to execute avdmanager')
     start = stdout.find('Virtual Devices')
     if start != -1:
         stdout = stdout[start:]
     print(stdout)
Exemplo n.º 9
0
    def list_packages(self, arch=None, api_type=None) -> None:
        print_verbose('List packages(arch: %s, api_type: %s)' %
                      (arch, api_type))
        if api_type is None:
            google_api_type = '.*?'
        else:
            google_api_type = api_type

        if arch is None:
            arch_pattern = '.*?'
        else:
            arch_pattern = arch + '.*?'
        regex_pattern = 'system-images;android-([0-9]+);(%s);(%s)\n' % (
            google_api_type, arch_pattern)
        print_verbose('Package pattern: %s' % regex_pattern)
        return_code, stdout, stderr = PlatformHelper.execute_cmd(
            '%s --verbose --list --include_obsolete' %
            self._get_sdk_manager_path())
        if return_code != 0:
            print_error_and_exit('Failed to list packages (return code: %d)' %
                                 return_code)
        system_images = re.findall(regex_pattern, stdout)
        arch_to_android_version_map = {}
        for system_image in system_images:
            android_api_version = system_image[0]
            google_api_type = system_image[1]
            arch = system_image[2]
            if google_api_type not in arch_to_android_version_map:
                arch_to_android_version_map[google_api_type] = {}
            if arch not in arch_to_android_version_map[google_api_type]:
                arch_to_android_version_map[google_api_type][arch] = []
            arch_to_android_version_map[google_api_type][arch].append(
                android_api_version)

        for (google_api_type,
             architectures) in arch_to_android_version_map.items():
            if google_api_type == 'default':
                print(
                    'Google API type: default (Standard Android image; no Google API)'
                )
            else:
                print('Google API type: %s' % google_api_type)
            for architecture in architectures:
                android_api_versions = arch_to_android_version_map[
                    google_api_type][architecture]
                print('%s -> %s' %
                      (architecture, ', '.join(android_api_versions)))
            print()
Exemplo n.º 10
0
    def _install_sdk_packages(self, package_names) -> bool:
        for package_name in package_names:
            exists = self._does_package_exist(package_name)
            if not exists:
                print_message('Package \"%s\" not found' % package_name)
                return False

        print_message('Installing packages [%s]...' % ', '.join(package_names))
        package_names_str = '\"' + '\" \"'.join(package_names) + '\"'
        cmd = 'yes | %s --verbose %s' % (self._get_sdk_manager_path(), package_names_str)
        return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd)
        if return_code != 0:
            print_error('Failed to install packages \"%s\"' % ' '.join(package_names))
            print_error('Stderr is \n%s' % stderr)
            return False
        return True
Exemplo n.º 11
0
 def update_all(self):
     cmd = '%s --update' % self._get_sdk_manager_path()
     return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd)
     if return_code != 0:
         print_error_and_exit('Failed to update, return code: %d' % return_code)
     count = 0
     if stdout:
         for line in stdout.split('\r'):
             if line.find('Fetch remote repository'):
                 continue
             else:
                 count += 1
     if count == 0:
         print_message('No packages to update')
         self._accept_all_licenses()
     else:
         print_message(stdout)
Exemplo n.º 12
0
    def _get_installed_packages(self) -> [str]:
        cmd = '%s --verbose --list --include_obsolete' % self._get_sdk_manager_path(
        )
        return_code, stdout, stderr = PlatformHelper.execute_cmd(cmd)
        if return_code != 0:
            print_error('Failed to list packages')
            return None

        start_line = 'Installed packages:'.lower()
        end_line = 'Available Packages:'.lower()
        lines = stdout.split('\n')
        i = 0
        while i < len(lines):
            line = lines[i]
            if line.lower().find(start_line) != -1:
                i += 1
                break
            else:
                i += 1
        installed_packages = set()
        for j in range(i, len(lines)):
            line = lines[j]
            if line.lower().find(end_line) != -1:
                break
            line = line.strip()
            if not line:
                continue

            if line.startswith('----'):
                continue
            if line.startswith('Description:'):
                continue
            if line.startswith('Version:'):
                continue
            if line.startswith('Installed Location:'):
                continue
            if line.startswith('Installed Obsolete Packages:'):
                continue
            if line.find('|') > 0:
                line = line[:line.find('|')]
            installed_packages.add(line)
        return sorted(installed_packages)
Exemplo n.º 13
0
 def create_avd(self, avd_name, api_version, arch, api_type):
     if api_type is None:
         api_type = 'google_apis'  # Preferred
     if arch is None:
         if PlatformHelper.is_64bit_architecture():
             arch = 'x86_64'
         else:
             arch = 'x86'
     package_name = AndroidEnhanced._get_system_images_package(api_version, arch, api_type)
     print_verbose('Package is %s' % package_name)
     self.install_api_version(api_version, arch=arch, api_type=api_type)
     # Say no to custom hardware profile.
     print_message('Creating AVD "%s" of type "%s" ' % (avd_name, package_name))
     create_cmd = 'echo no | %s --verbose create avd --name %s --package "%s"' % (
         self._get_avd_manager_path(), avd_name, package_name)
     return_code, stdout, stderr = PlatformHelper.execute_cmd(create_cmd)
     if return_code != 0:
         print_error('Failed to create AVD')
         print_error('stdout: %s' % stdout)
         print_error_and_exit('stderr: %s' % stderr)
     print_message('AVD \"%s\" created successfully' % avd_name)