forked from kernelci/kernelci-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkci_rootfs
More file actions
executable file
·152 lines (125 loc) · 5.67 KB
/
Copy pathkci_rootfs
File metadata and controls
executable file
·152 lines (125 loc) · 5.67 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/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
err = kernelci.sort_check(configs['rootfs_configs'])
if err:
print("Rootfs broken order: '{}' before '{}".format(*err))
return False
for name, config in configs['rootfs_configs'].items():
err = kernelci.sort_check(config.arch_list)
if err:
print("Arch order broken for {}: '{}' before '{}".format(
name, err[0], err[1]))
return False
err = kernelci.sort_check(config.extra_packages)
if err:
print("Packages order broken for {}: '{}' before '{}".format(
name, err[0], err[1]))
return False
err = kernelci.sort_check(config.extra_packages_remove)
if err:
print("Packages order broken for {}: '{}' before '{}".format(
name, err[0], err[1]))
return False
if args.verbose:
rootfs_configs = config_data['rootfs_configs']
for config_name, config in rootfs_configs.items():
print(config_name)
print('\trootfs_type: {}'.format(config.rootfs_type))
print('\tarch_list: {}'.format(config.arch_list))
print('\tdebian_release: {}'.format(config.debian_release))
print('\textra_packages: {}'.format(config.extra_packages))
print('\textra_packages_remove: {}'.format(
config.extra_packages_remove))
print('\textra_files_remove: {}'.format(
config.extra_files_remove))
print('\tscript: {}'.format(config.script))
print('\ttest_overlay: {}'.format(config.test_overlay))
print('\tcrush_image_options: {}'.format(
config.crush_image_options))
print('\tdebian_mirror: {}'.format(config.debian_mirror))
print('\tkeyring_package: {}'.format(config.keyring_package))
print('\tkeyring_file: {}'.format(config.keyring_file))
return True
class cmd_list_configs(Command):
help = "List all rootfs config names"
def __call__(self, config_data, *args, **kwargs):
rootfs_configs = config_data['rootfs_configs']
for config_name in rootfs_configs:
print(config_name)
return True
class cmd_list_variants(Command):
help = "List all rootfs variants"
opt_args = [Args.rootfs_config, Args.arch]
def __call__(self, config_data, args, **kwargs):
rootfs_configs = config_data['rootfs_configs']
config_name = args.rootfs_config
arch = args.arch
if config_name and config_name not in rootfs_configs:
print("{} : invalid config entry".format(config_name))
return False
if arch and config_name and \
arch not in rootfs_configs[config_name].arch_list:
print("{} : invalid arch entry".format(arch))
return False
configs = (config for config in rootfs_configs
if config == config_name or config_name is None)
for config in configs:
for arch_type in rootfs_configs[config].arch_list:
if arch_type == arch or arch is None:
print(' '.join([config, arch_type]))
return True
class cmd_build(Command):
help = "Build a rootfs image"
args = [Args.rootfs_config, Args.data_path, Args.arch]
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
return kernelci.rootfs.build(config_name, config,
args.data_path, args.arch)
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)