tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mach_commands.py (3771B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, # You can obtain one at http://mozilla.org/MPL/2.0/.
      4 import logging
      5 import os
      6 import sys
      7 import tempfile
      8 
      9 from mach.decorators import Command, CommandArgument
     10 from mozbuild.base import BinaryNotFoundException
     11 
     12 requirements = os.path.join(os.path.dirname(__file__), "requirements", "base.txt")
     13 
     14 
     15 def _init(command_context):
     16    command_context.activate_virtualenv()
     17    command_context.virtualenv_manager.install_pip_requirements(
     18        requirements, require_hashes=False
     19    )
     20 
     21 
     22 @Command("fetch-condprofile", category="testing")
     23 @CommandArgument("--target-dir", default=None, help="Target directory")
     24 @CommandArgument("--platform", default=None, help="Platform")
     25 @CommandArgument("--scenario", default="full", help="Scenario")  # grab choices
     26 @CommandArgument("--customization", default="default", help="Customization")  # same
     27 @CommandArgument("--task-id", default=None, help="Task ID")
     28 @CommandArgument("--download-cache", action="store_true", default=True)
     29 @CommandArgument(
     30    "--repo",
     31    default="mozilla-central",
     32    choices=["mozilla-central", "try"],
     33    help="Repository",
     34 )
     35 def fetch(
     36    command_context,
     37    target_dir,
     38    platform,
     39    scenario,
     40    customization,
     41    task_id,
     42    download_cache,
     43    repo,
     44 ):
     45    _init(command_context)
     46    from condprof.client import get_profile
     47    from condprof.util import get_current_platform, get_version
     48 
     49    if platform is None:
     50        platform = get_current_platform()
     51 
     52    if target_dir is None:
     53        target_dir = tempfile.mkdtemp()
     54 
     55    version = get_version(command_context.get_binary_path())
     56 
     57    get_profile(
     58        target_dir,
     59        platform,
     60        scenario,
     61        customization,
     62        task_id,
     63        download_cache,
     64        repo,
     65        version,
     66    )
     67    print("Downloaded conditioned profile can be found at: %s" % target_dir)
     68 
     69 
     70 @Command("run-condprofile", category="testing")
     71 @CommandArgument("archive", help="Archives Dir", type=str, default=None)
     72 @CommandArgument("--firefox", help="Firefox Binary", type=str, default=None)
     73 @CommandArgument("--scenario", help="Scenario to use", type=str, default="all")
     74 @CommandArgument("--profile", help="Existing profile Dir", type=str, default=None)
     75 @CommandArgument(
     76    "--customization", help="Profile customization to use", type=str, default="all"
     77 )
     78 @CommandArgument(
     79    "--visible", help="Don't use headless mode", action="store_true", default=False
     80 )
     81 @CommandArgument(
     82    "--archives-dir", help="Archives local dir", type=str, default="/tmp/archives"
     83 )
     84 @CommandArgument(
     85    "--force-new", help="Create from scratch", action="store_true", default=False
     86 )
     87 @CommandArgument(
     88    "--strict",
     89    help="Errors out immediatly on a scenario failure",
     90    action="store_true",
     91    default=True,
     92 )
     93 @CommandArgument(
     94    "--geckodriver",
     95    help="Path to the geckodriver binary",
     96    type=str,
     97    default=sys.platform.startswith("win") and "geckodriver.exe" or "geckodriver",
     98 )
     99 @CommandArgument("--device-name", help="Name of the device", type=str, default=None)
    100 def run(command_context, **kw):
    101    os.environ["MANUAL_MACH_RUN"] = "1"
    102    _init(command_context)
    103 
    104    if kw["firefox"] is None:
    105        try:
    106            kw["firefox"] = command_context.get_binary_path()
    107        except BinaryNotFoundException as e:
    108            command_context.log(
    109                logging.ERROR,
    110                "run-condprofile",
    111                {"error": str(e)},
    112                "ERROR: {error}",
    113            )
    114            command_context.log(
    115                logging.INFO, "run-condprofile", {"help": e.help()}, "{help}"
    116            )
    117            return 1
    118 
    119    from condprof.runner import run
    120 
    121    run(**kw)