| 1 |
# mypy: allow-untyped-defs |
| 2 |
|
| 3 |
import argparse |
| 4 |
from . import browser |
| 5 |
|
| 6 |
latest_channels = { |
| 7 |
'android_webview': 'dev', |
| 8 |
'firefox': 'nightly', |
| 9 |
'firefox_android': 'nightly', |
| 10 |
'chrome': 'canary', |
| 11 |
'chrome_android': 'dev', |
| 12 |
'chromium': 'nightly', |
| 13 |
'edge': 'dev', |
| 14 |
'safari': 'preview', |
| 15 |
'servo': 'nightly', |
| 16 |
'webkitgtk_minibrowser': 'nightly', |
| 17 |
'wpewebkit_minibrowser': 'nightly', |
| 18 |
'wktr': 'main', |
| 19 |
} |
| 20 |
|
| 21 |
channel_by_name = { |
| 22 |
'stable': 'stable', |
| 23 |
'release': 'stable', |
| 24 |
'beta': 'beta', |
| 25 |
'dev': 'dev', |
| 26 |
'canary': 'canary', |
| 27 |
'nightly': latest_channels, |
| 28 |
'preview': latest_channels, |
| 29 |
'experimental': latest_channels, |
| 30 |
} |
| 31 |
|
| 32 |
channel_args = argparse.ArgumentParser(add_help=False) |
| 33 |
channel_args.add_argument('--channel', choices=channel_by_name.keys(), |
| 34 |
default='nightly', |
| 35 |
help=''' |
| 36 |
Name of browser release channel (default: nightly). "stable" and "release" are |
| 37 |
synonyms for the latest browser stable release; "beta" is the beta release; |
| 38 |
"dev" is only meaningful for Chrome (i.e. Chrome Dev); "nightly", |
| 39 |
"experimental", and "preview" are all synonyms for the latest available |
| 40 |
development or trunk release. (For WebDriver installs, we attempt to select an |
| 41 |
appropriate, compatible version for the latest browser release on the selected |
| 42 |
channel.) This flag overrides --browser-channel.''') |
| 43 |
|
| 44 |
|
| 45 |
def get_parser(): |
| 46 |
parser = argparse.ArgumentParser( |
| 47 |
parents=[channel_args], |
| 48 |
description="Install a given browser or webdriver frontend.") |
| 49 |
parser.add_argument('browser', choices=['firefox', 'chrome', 'chromium', 'servo', 'safari', 'wktr'], |
| 50 |
help='name of web browser product') |
| 51 |
parser.add_argument('component', choices=['browser', 'webdriver'], |
| 52 |
help='name of component') |
| 53 |
parser.add_argument('--download-only', action="store_true", |
| 54 |
help="Download the selected component but don't install it") |
| 55 |
parser.add_argument('--rename', |
| 56 |
help="Filename, excluding extension for downloaded archive " |
| 57 |
"(only with --download-only)") |
| 58 |
parser.add_argument('-d', '--destination', |
| 59 |
help='filesystem directory to place the component') |
| 60 |
parser.add_argument('--revision', |
| 61 |
help='Chromium revision to install from snapshots') |
| 62 |
return parser |
| 63 |
|
| 64 |
|
| 65 |
def get_channel(browser, channel): |
| 66 |
channel = channel_by_name[channel] |
| 67 |
if isinstance(channel, dict): |
| 68 |
channel = channel.get(browser) |
| 69 |
return channel |
| 70 |
|
| 71 |
|
| 72 |
def run(venv, **kwargs): |
| 73 |
import logging |
| 74 |
logger = logging.getLogger("install") |
| 75 |
|
| 76 |
browser = kwargs["browser"] |
| 77 |
destination = kwargs["destination"] |
| 78 |
channel = get_channel(browser, kwargs["channel"]) |
| 79 |
|
| 80 |
if channel != kwargs["channel"]: |
| 81 |
logger.info("Interpreting channel '%s' as '%s'", kwargs["channel"], channel) |
| 82 |
|
| 83 |
if destination is None: |
| 84 |
if venv: |
| 85 |
if kwargs["component"] == "browser": |
| 86 |
destination = venv.path |
| 87 |
else: |
| 88 |
destination = venv.bin_path |
| 89 |
else: |
| 90 |
raise argparse.ArgumentError(None, |
| 91 |
"No --destination argument, and no default for the environment") |
| 92 |
|
| 93 |
if kwargs["revision"] is not None and browser != "chromium": |
| 94 |
raise argparse.ArgumentError(None, "--revision flag cannot be used for non-Chromium browsers.") |
| 95 |
|
| 96 |
install(browser, kwargs["component"], destination, channel, logger=logger, |
| 97 |
download_only=kwargs["download_only"], rename=kwargs["rename"], |
| 98 |
revision=kwargs["revision"]) |
| 99 |
|
| 100 |
|
| 101 |
def install(name, component, destination, channel="nightly", logger=None, download_only=False, |
| 102 |
rename=None, revision=None): |
| 103 |
if logger is None: |
| 104 |
import logging |
| 105 |
logger = logging.getLogger("install") |
| 106 |
|
| 107 |
prefix = "download" if download_only else "install" |
| 108 |
suffix = "_webdriver" if component == 'webdriver' else "" |
| 109 |
|
| 110 |
method = prefix + suffix |
| 111 |
|
| 112 |
if name == "wktr": |
| 113 |
canonical_name = "WebKitTestRunner" |
| 114 |
else: |
| 115 |
canonical_name = name.title() |
| 116 |
|
| 117 |
browser_cls = getattr(browser, canonical_name) |
| 118 |
logger.info('Now installing %s %s...', name, component) |
| 119 |
kwargs = {} |
| 120 |
if download_only and rename: |
| 121 |
kwargs["rename"] = rename |
| 122 |
if revision: |
| 123 |
kwargs["revision"] = revision |
| 124 |
|
| 125 |
path = getattr(browser_cls(logger), method)(dest=destination, channel=channel, **kwargs) |
| 126 |
if path: |
| 127 |
logger.info('Binary %s as %s', "downloaded" if download_only else "installed", path) |