forked from kernelci/kernelci-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkci_data
executable file
·67 lines (54 loc) · 2.2 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
#!/usr/bin/env python3
#
# Copyright (C) 2020 Collabora Limited
# Author: Michal Galka <[email protected]>
# Author: Guillaume Tucker <[email protected]>
#
# 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 sys
from kernelci.cli import Args, Command, parse_opts
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
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 f:
data = f.read()
db = kernelci.data.get_db(config, args.db_token)
return db.submit(data, args.verbose)
if __name__ == '__main__':
opts = parse_opts("kci_data", "db-configs.yaml", globals())
configs = kernelci.config.data.from_yaml(opts.yaml_configs)
status = opts.command(configs, opts)
sys.exit(0 if status is True else 1)