File: mach_commands.py

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (121 lines) | stat: -rw-r--r-- 3,771 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, # You can obtain one at http://mozilla.org/MPL/2.0/.
import logging
import os
import sys
import tempfile

from mach.decorators import Command, CommandArgument
from mozbuild.base import BinaryNotFoundException

requirements = os.path.join(os.path.dirname(__file__), "requirements", "base.txt")


def _init(command_context):
    command_context.activate_virtualenv()
    command_context.virtualenv_manager.install_pip_requirements(
        requirements, require_hashes=False
    )


@Command("fetch-condprofile", category="testing")
@CommandArgument("--target-dir", default=None, help="Target directory")
@CommandArgument("--platform", default=None, help="Platform")
@CommandArgument("--scenario", default="full", help="Scenario")  # grab choices
@CommandArgument("--customization", default="default", help="Customization")  # same
@CommandArgument("--task-id", default=None, help="Task ID")
@CommandArgument("--download-cache", action="store_true", default=True)
@CommandArgument(
    "--repo",
    default="mozilla-central",
    choices=["mozilla-central", "try"],
    help="Repository",
)
def fetch(
    command_context,
    target_dir,
    platform,
    scenario,
    customization,
    task_id,
    download_cache,
    repo,
):
    _init(command_context)
    from condprof.client import get_profile
    from condprof.util import get_current_platform, get_version

    if platform is None:
        platform = get_current_platform()

    if target_dir is None:
        target_dir = tempfile.mkdtemp()

    version = get_version(command_context.get_binary_path())

    get_profile(
        target_dir,
        platform,
        scenario,
        customization,
        task_id,
        download_cache,
        repo,
        version,
    )
    print("Downloaded conditioned profile can be found at: %s" % target_dir)


@Command("run-condprofile", category="testing")
@CommandArgument("archive", help="Archives Dir", type=str, default=None)
@CommandArgument("--firefox", help="Firefox Binary", type=str, default=None)
@CommandArgument("--scenario", help="Scenario to use", type=str, default="all")
@CommandArgument("--profile", help="Existing profile Dir", type=str, default=None)
@CommandArgument(
    "--customization", help="Profile customization to use", type=str, default="all"
)
@CommandArgument(
    "--visible", help="Don't use headless mode", action="store_true", default=False
)
@CommandArgument(
    "--archives-dir", help="Archives local dir", type=str, default="/tmp/archives"
)
@CommandArgument(
    "--force-new", help="Create from scratch", action="store_true", default=False
)
@CommandArgument(
    "--strict",
    help="Errors out immediatly on a scenario failure",
    action="store_true",
    default=True,
)
@CommandArgument(
    "--geckodriver",
    help="Path to the geckodriver binary",
    type=str,
    default=sys.platform.startswith("win") and "geckodriver.exe" or "geckodriver",
)
@CommandArgument("--device-name", help="Name of the device", type=str, default=None)
def run(command_context, **kw):
    os.environ["MANUAL_MACH_RUN"] = "1"
    _init(command_context)

    if kw["firefox"] is None:
        try:
            kw["firefox"] = command_context.get_binary_path()
        except BinaryNotFoundException as e:
            command_context.log(
                logging.ERROR,
                "run-condprofile",
                {"error": str(e)},
                "ERROR: {error}",
            )
            command_context.log(
                logging.INFO, "run-condprofile", {"help": e.help()}, "{help}"
            )
            return 1

    from condprof.runner import run

    run(**kw)