forked from kernelci/kernelci-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kci_rootfs
executable file
·133 lines (107 loc) · 4.44 KB
/
kci_rootfs
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python3
#
# Copyright (C) 2019 Collabora Limited
# Author: Michal Galka <michal.galka@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 sys
from kernelci.cli import Args, Command, parse_opts
import kernelci.rootfs
import kernelci.config.rootfs
# -----------------------------------------------------------------------------
# Commands
#
class cmd_validate(Command):
help = "Validate the YAML configuration"
opt_args = [Args.verbose]
def __call__(self, config_data, args, **kwargs):
# ToDo: Use jsonschema
result = kernelci.config.rootfs.validate(configs)
if args.verbose and result:
kernelci.config.rootfs.dump_configs(configs)
return result
class cmd_list_configs(Command):
help = "List all rootfs config names"
opt_args = [Args.rootfs_type]
def __call__(self, config_data, args, **kwargs):
rootfs_configs = config_data['rootfs_configs']
if args.rootfs_type is None:
config_names = rootfs_configs
else:
config_names = (name
for name, config_data in rootfs_configs.items()
if config_data.rootfs_type == args.rootfs_type)
for config_name in config_names:
print(config_name)
return True
class cmd_list_variants(Command):
help = "List all rootfs variants"
opt_args = [Args.rootfs_config, Args.arch, Args.rootfs_type]
def __call__(self, configs, args, **kwargs):
rootfs_configs = configs['rootfs_configs']
if args.rootfs_config and args.rootfs_type:
print("--rootfs-config and --rootfs-type can't be used at once")
return False
if args.rootfs_config:
config = rootfs_configs.get(args.rootfs_config)
if not config:
print("{} : invalid config entry".format(args.rootfs_config))
return False
build_configs = [config]
elif args.rootfs_type:
build_configs = list(
config
for config in rootfs_configs.values()
if config.rootfs_type == args.rootfs_type
)
else:
build_configs = list(rootfs_configs.values())
for config in build_configs:
for arch in config.arch_list:
if args.arch and args.arch != arch:
continue
print(' '.join([config.name, arch, config.rootfs_type]))
return True
class cmd_build(Command):
help = "Build a rootfs image"
args = [Args.rootfs_config, Args.arch, Args.output]
opt_args = [Args.data_path]
def __call__(self, config_data, args, **kwargs):
config_name = args.rootfs_config
config = config_data['rootfs_configs'].get(config_name)
if not config:
print("{} invalid. Check 'kci_rootfs list_configs' for valid \
entries".format(config_name))
return False
data_path = (
args.data_path or 'config/rootfs/{}'.format(config.rootfs_type)
)
return kernelci.rootfs.build(config_name, config, data_path,
args.arch, args.output)
class cmd_upload(Command):
help = "Upload a rootfs image"
args = [Args.rootfs_dir, Args.upload_path, Args.api, Args.db_token]
def __call__(self, config_data, args):
kernelci.rootfs.upload(args.api, args.db_token, args.upload_path,
args.rootfs_dir)
return True
# -----------------------------------------------------------------------------
# Main
#
if __name__ == '__main__':
opts = parse_opts("kci_rootfs", globals())
configs = kernelci.config.load(opts.yaml_config)
status = opts.command(configs, opts)
sys.exit(0 if status is True else 1)