1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Copyright (c) 2011 The Chromium OS Authors.
5#
6
7"""See README for more information"""
8
9import os
10import sys
11
12# Allow 'from patman import xxx to work'
13# pylint: disable=C0413
14our_path = os.path.dirname(os.path.realpath(__file__))
15sys.path.append(os.path.join(our_path, '..'))
16
17# Our modules
18from u_boot_pylib import test_util
19from u_boot_pylib import tout
20from patman import cmdline
21from patman import control
22
23
24def run_patman():
25    """Run patamn
26
27    This is the main program. It collects arguments and runs either the tests or
28    the control module.
29    """
30    args = cmdline.parse_args()
31
32    if not args.debug:
33        sys.tracebacklimit = 0
34
35    tout.init(tout.INFO if args.verbose else tout.WARNING)
36
37    # Run our reasonably good tests
38    if args.cmd == 'test':
39        # pylint: disable=C0415
40        from patman import func_test
41        from patman import test_checkpatch
42        from patman import test_cseries
43
44        to_run = args.testname if args.testname not in [None, 'test'] else None
45        result = test_util.run_test_suites(
46            'patman', False, args.verbose, args.no_capture,
47            args.test_preserve_dirs, None, to_run, None,
48            [test_checkpatch.TestPatch, func_test.TestFunctional, 'settings',
49             test_cseries.TestCseries])
50        sys.exit(0 if result.wasSuccessful() else 1)
51
52    # Process commits, produce patches files, check them, email them
53    else:
54        exit_code = control.do_patman(args)
55        sys.exit(exit_code)
56
57
58if __name__ == "__main__":
59    sys.exit(run_patman())
60