This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
squad-create-reproducer-from-testrun
executable file
·94 lines (71 loc) · 2.38 KB
/
squad-create-reproducer-from-testrun
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: set ts=4
#
# Copyright 2023-present Linaro Limited
#
# SPDX-License-Identifier: MIT
from argparse import ArgumentParser
from logging import INFO, basicConfig, getLogger
from os import chmod, getenv
from stat import S_IRUSR, S_IWUSR, S_IXUSR
from sys import exit
from squad_client.core.api import SquadApi
from squadutilslib import ReproducerNotFound, get_reproducer_from_testrun
squad_host_url = "https://qa-reports.linaro.org/"
SquadApi.configure(cache=3600, url=getenv("SQUAD_HOST", squad_host_url))
basicConfig(level=INFO)
logger = getLogger(__name__)
def parse_args(raw_args):
parser = ArgumentParser(
description="Provide a SQUAD TestRun ID to download the build or test reproducer for that TestRun."
+ " The reproducer will be printed to the terminal and written to a file."
)
parser.add_argument(
"--testrun",
required=True,
help="The TestRun ID of the build or test to fetch the reproducer for.",
)
# Optional arguments:
parser.add_argument(
"--debug",
required=False,
action="store_true",
default=False,
help="Display debug messages.",
)
parser.add_argument(
"--filename",
required=False,
help="Name for the reproducer file, 'reproducer' by default.",
)
parser.add_argument(
"--local",
required=False,
action="store_true",
default=False,
help="Fetch a TuxRun or TuxMake reproducer rather than a TuxPlan reproducer.",
)
return parser.parse_args(raw_args)
def run(raw_args=None):
args = parse_args(raw_args)
# If filename was not provided, set filename to "reproducer"
if not args.filename:
filename = "reproducer"
else:
filename = args.filename
try:
reproducer = get_reproducer_from_testrun(args.testrun, filename, args.local)
except ReproducerNotFound as e:
logger.error(f"No reproducer could be found for TestRun {args.testrun}")
logger.error(f"{e}")
return -1
# If a filename was provided, don't print the reproducer to console
if not args.filename:
print(reproducer)
if args.local:
# Make the script executable
chmod(filename, S_IXUSR | S_IRUSR | S_IWUSR)
logger.info(f"file created: {filename}")
if __name__ == "__main__":
exit(run())