forked from kernelci/kernelci-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kci_data
executable file
·104 lines (83 loc) · 3.37 KB
/
kci_data
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
#!/usr/bin/env python3
#
# Copyright (C) 2020 Collabora Limited
# Author: Michal Galka <michal.galka@collabora.com>
# Author: Guillaume Tucker <guillaume.tucker@collabora.com>
#
# This module is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import json
import sys
from kernelci.cli import Args, Command, parse_opts
import kernelci.build
import kernelci.config.data
import kernelci.data
class cmd_validate(Command):
help = "Validate the YAML configuration"
opt_args = [Args.verbose]
def __call__(self, configs, args):
# ToDo: Use jsonschema
entries = [
'db_configs',
]
err = kernelci.config.validate_yaml(opts.yaml_config, entries)
if err:
print(err)
return False
return True
class cmd_list_configs(Command):
help = "List all database configurations"
def __call__(self, config_data, args):
db_configs = config_data['db_configs']
for config_name in db_configs:
print(config_name)
return True
class cmd_submit(Command):
help = "Submit data to the specified database"
args = [Args.db_config, Args.data_file]
opt_args = [Args.db_token, Args.verbose]
def __call__(self, config_data, args):
config = config_data['db_configs'][args.db_config]
if args.data_file == '-':
data = sys.stdin.read()
else:
with open(args.data_file, 'r') as json_file:
data = json.load(json_file)
db = kernelci.data.get_db(config, args.db_token)
return db.submit(data, args.verbose)
class cmd_submit_build(Command):
help = "Submit meta-data for a kernel build"
args = [Args.kdir, Args.db_config]
opt_args = [Args.db_token, Args.output, Args.verbose]
def __call__(self, config_data, args):
config = config_data['db_configs'][args.db_config]
install = kernelci.build.Step.get_install_path(args.kdir, args.output)
meta = kernelci.build.Metadata(install)
db = kernelci.data.get_db(config, args.db_token)
return db.submit_build(meta, args.verbose)
class cmd_submit_test(Command):
help = "Submit test results"
args = [Args.db_config, Args.data_file]
opt_args = [Args.db_token, Args.verbose]
def __call__(self, config_data, args):
config = config_data['db_configs'][args.db_config]
with open(args.data_file, 'r') as json_file:
data = json.load(json_file)
db = kernelci.data.get_db(config, args.db_token)
return db.submit_test(data, args.verbose)
if __name__ == '__main__':
opts = parse_opts("kci_data", globals())
configs = kernelci.config.load(opts.yaml_config)
status = opts.command(configs, opts)
sys.exit(0 if status is True else 1)