summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/harness/wptrunner/update/__init__.py
blob: 84c19fd949c5c6c0f053b6edc38818f236ab27fd (plain)
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
# 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 os
import sys

from mozlog.structured import structuredlog, commandline

from .. import wptcommandline

from update import WPTUpdate

def remove_logging_args(args):
    """Take logging args out of the dictionary of command line arguments so
    they are not passed in as kwargs to the update code. This is particularly
    necessary here because the arguments are often of type file, which cannot
    be serialized.

    :param args: Dictionary of command line arguments.
    """
    for name in args.keys():
        if name.startswith("log_"):
            args.pop(name)


def setup_logging(args, defaults):
    """Use the command line arguments to set up the logger.

    :param args: Dictionary of command line arguments.
    :param defaults: Dictionary of {formatter_name: stream} to use if
                     no command line logging is specified"""
    logger = commandline.setup_logging("web-platform-tests-update", args, defaults)

    remove_logging_args(args)

    return logger


def run_update(logger, **kwargs):
    updater = WPTUpdate(logger, **kwargs)
    return updater.run()


def main():
    args = wptcommandline.parse_args_update()
    logger = setup_logging(args, {"mach": sys.stdout})
    assert structuredlog.get_default_logger() is not None
    success = run_update(logger, **args)
    sys.exit(0 if success else 1)