def IppetPath():
    # Look for pre-installed IPPET.
    ippet_path = path.FindInstalledWindowsApplication(
        os.path.join('Intel', 'Intel(R) Platform Power Estimation Tool',
                     'ippet.exe'))
    if ippet_path:
        return ippet_path

    # Look for IPPET installed previously by this script.
    ippet_path = os.path.join(path.GetTelemetryDir(), 'bin', 'win', 'ippet',
                              'ippet.exe')
    if path.IsExecutable(ippet_path):
        return ippet_path

    # Install IPPET.
    zip_path = os.path.join(path.GetTelemetryDir(), 'bin', 'win', 'ippet.zip')
    cloud_storage.GetIfChanged(zip_path, bucket=cloud_storage.PUBLIC_BUCKET)
    with zipfile.ZipFile(zip_path, 'r') as zip_file:
        zip_file.extractall(os.path.dirname(zip_path))
    os.remove(zip_path)

    if path.IsExecutable(ippet_path):
        return ippet_path

    return None
def _FindExecutableInPath(relative_executable_path, *extra_search_paths):
    search_paths = list(extra_search_paths) + os.environ['PATH'].split(
        os.pathsep)
    for search_path in search_paths:
        executable_path = os.path.join(search_path, relative_executable_path)
        if path.IsExecutable(executable_path):
            return executable_path
    return None
예제 #3
0
 def AddIfFound(browser_type, build_dir, type_dir, app_name, content_shell):
     browser_directory = os.path.join(chrome_root, build_dir, type_dir)
     app = os.path.join(browser_directory, app_name)
     if path.IsExecutable(app):
         is_64 = browser_type.endswith('_x64')
         browsers.append(
             PossibleDesktopBrowser(browser_type,
                                    finder_options,
                                    app,
                                    flash_path_64 if is_64 else flash_path,
                                    content_shell,
                                    browser_directory,
                                    is_local_build=True))
         return True
     return False
예제 #4
0
 def testIsExecutable(self):
     self.assertFalse(path.IsExecutable('nonexistent_file'))
     self.assertTrue(path.IsExecutable(sys.executable))
예제 #5
0
def FindAllAvailableBrowsers(finder_options):
    """Finds all the desktop browsers available on this machine."""
    browsers = []

    if not CanFindAvailableBrowsers():
        return []

    has_display = True
    if (sys.platform.startswith('linux') and os.getenv('DISPLAY') == None):
        has_display = False

    # Look for a browser in the standard chrome build locations.
    if finder_options.chrome_root:
        chrome_root = finder_options.chrome_root
    else:
        chrome_root = path.GetChromiumSrcDir()

    flash_bin_dir = os.path.join(chrome_root, 'third_party', 'adobe', 'flash',
                                 'binaries', 'ppapi')

    chromium_app_names = []
    if sys.platform == 'darwin':
        chromium_app_names.append('Chromium.app/Contents/MacOS/Chromium')
        chromium_app_names.append(
            'Google Chrome.app/Contents/MacOS/Google Chrome')
        content_shell_app_name = 'Content Shell.app/Contents/MacOS/Content Shell'
        flash_bin = 'PepperFlashPlayer.plugin'
        flash_path = os.path.join(flash_bin_dir, 'mac', flash_bin)
        flash_path_64 = os.path.join(flash_bin_dir, 'mac_64', flash_bin)
    elif sys.platform.startswith('linux'):
        chromium_app_names.append('chrome')
        content_shell_app_name = 'content_shell'
        flash_bin = 'libpepflashplayer.so'
        flash_path = os.path.join(flash_bin_dir, 'linux', flash_bin)
        flash_path_64 = os.path.join(flash_bin_dir, 'linux_x64', flash_bin)
    elif sys.platform.startswith('win'):
        chromium_app_names.append('chrome.exe')
        content_shell_app_name = 'content_shell.exe'
        flash_bin = 'pepflashplayer.dll'
        flash_path = os.path.join(flash_bin_dir, 'win', flash_bin)
        flash_path_64 = os.path.join(flash_bin_dir, 'win_x64', flash_bin)
    else:
        raise Exception('Platform not recognized')

    # Add the explicit browser executable if given.
    if finder_options.browser_executable:
        normalized_executable = os.path.expanduser(
            finder_options.browser_executable)
        if path.IsExecutable(normalized_executable):
            browser_directory = os.path.dirname(
                finder_options.browser_executable)
            browsers.append(
                PossibleDesktopBrowser('exact', finder_options,
                                       normalized_executable, flash_path,
                                       False, browser_directory))
        else:
            raise Exception(
                '%s specified by --browser-executable does not exist',
                normalized_executable)

    def AddIfFound(browser_type, build_dir, type_dir, app_name, content_shell):
        browser_directory = os.path.join(chrome_root, build_dir, type_dir)
        app = os.path.join(browser_directory, app_name)
        if path.IsExecutable(app):
            is_64 = browser_type.endswith('_x64')
            browsers.append(
                PossibleDesktopBrowser(browser_type,
                                       finder_options,
                                       app,
                                       flash_path_64 if is_64 else flash_path,
                                       content_shell,
                                       browser_directory,
                                       is_local_build=True))
            return True
        return False

    # Add local builds
    for build_dir, build_type in path.GetBuildDirectories():
        for chromium_app_name in chromium_app_names:
            AddIfFound(build_type.lower(), build_dir, build_type,
                       chromium_app_name, False)
        AddIfFound('content-shell-' + build_type.lower(), build_dir,
                   build_type, content_shell_app_name, True)

    # Mac-specific options.
    if sys.platform == 'darwin':
        mac_canary_root = '/Applications/Google Chrome Canary.app/'
        mac_canary = mac_canary_root + 'Contents/MacOS/Google Chrome Canary'
        mac_system_root = '/Applications/Google Chrome.app'
        mac_system = mac_system_root + '/Contents/MacOS/Google Chrome'
        if path.IsExecutable(mac_canary):
            browsers.append(
                PossibleDesktopBrowser('canary', finder_options, mac_canary,
                                       None, False, mac_canary_root))

        if path.IsExecutable(mac_system):
            browsers.append(
                PossibleDesktopBrowser('system', finder_options, mac_system,
                                       None, False, mac_system_root))

    # Linux specific options.
    if sys.platform.startswith('linux'):
        # Look for a google-chrome instance.
        found = False
        try:
            with open(os.devnull, 'w') as devnull:
                found = subprocess.call(['google-chrome', '--version'],
                                        stdout=devnull,
                                        stderr=devnull) == 0
        except OSError:
            pass
        if found:
            browsers.append(
                PossibleDesktopBrowser('system', finder_options,
                                       'google-chrome', None, False,
                                       '/opt/google/chrome'))

    # Win32-specific options.
    if sys.platform.startswith('win'):
        app_paths = (
            ('system', os.path.join('Google', 'Chrome', 'Application')),
            ('canary', os.path.join('Google', 'Chrome SxS', 'Application')),
        )

        for browser_name, app_path in app_paths:
            for chromium_app_name in chromium_app_names:
                app_path = os.path.join(app_path, chromium_app_name)
                app_path = path.FindInstalledWindowsApplication(app_path)
                if app_path:
                    browsers.append(
                        PossibleDesktopBrowser(browser_name, finder_options,
                                               app_path, None, False,
                                               os.path.dirname(app_path)))

    if len(browsers) and not has_display:
        logging.warning(
            'Found (%s), but you do not have a DISPLAY environment set.' %
            ','.join([b.browser_type for b in browsers]))
        return []

    return browsers