|
65 | 65 | import logging |
66 | 66 | from mock import patch |
67 | 67 | from docopt import docopt |
| 68 | +from tempfile import TemporaryDirectory |
68 | 69 | from typing import ( |
69 | 70 | Dict, List |
70 | 71 | ) |
|
82 | 83 | from kiwi.utils.sync import DataSync |
83 | 84 | from kiwi.defaults import Defaults |
84 | 85 |
|
| 86 | +from kiwi_stackbuild_plugin.xml_merge import XMLMerge |
85 | 87 | from kiwi_stackbuild_plugin.exceptions import ( |
86 | 88 | KiwiStackBuildPluginTargetDirExists, |
87 | | - KiwiStackBuildPluginRootSyncFailed |
| 89 | + KiwiStackBuildPluginRootSyncFailed, |
88 | 90 | ) |
89 | 91 |
|
90 | 92 | log = logging.getLogger('kiwi') |
@@ -150,34 +152,57 @@ def process(self) -> None: |
150 | 152 | ) |
151 | 153 |
|
152 | 154 | if self.command_args.get('--description'): |
153 | | - with patch.object( |
154 | | - sys, 'argv', self._validate_kiwi_build_command( |
155 | | - [ |
156 | | - 'system', 'build', |
157 | | - '--description', self.command_args['--description'], |
158 | | - '--target-dir', self.command_args['--target-dir'], |
159 | | - '--allow-existing-root' |
160 | | - ] |
161 | | - ) |
162 | | - ): |
163 | | - kiwi_task = SystemBuildTask( |
164 | | - should_perform_task_setup=False |
165 | | - ) |
| 155 | + merger = XMLMerge(self.command_args['--description']) |
| 156 | + if merger.is_stackbuild_description(): |
| 157 | + merger.validate_schema() |
| 158 | + with TemporaryDirectory( |
| 159 | + prefix='kiwi_description.' |
| 160 | + ) as temp_desc: |
| 161 | + merger.merge_description( |
| 162 | + f'{image_root_dir}/image', temp_desc |
| 163 | + ) |
| 164 | + self._kiwi_build_task( |
| 165 | + temp_desc, self.command_args['--target-dir'] |
| 166 | + ).process() |
| 167 | + |
| 168 | + else: |
| 169 | + self._kiwi_build_task( |
| 170 | + self.command_args['--description'], |
| 171 | + self.command_args['--target-dir'] |
| 172 | + ).process() |
166 | 173 | else: |
167 | | - with patch.object( |
168 | | - sys, 'argv', self._validate_kiwi_create_command( |
169 | | - [ |
170 | | - 'system', 'create', |
171 | | - '--root', image_root_dir, |
172 | | - '--target-dir', self.command_args['--target-dir'] |
173 | | - ] |
174 | | - ) |
175 | | - ): |
176 | | - kiwi_task = SystemCreateTask( |
177 | | - should_perform_task_setup=False |
178 | | - ) |
| 174 | + self._kiwi_create_task( |
| 175 | + image_root_dir, self.command_args['--target-dir'] |
| 176 | + ).process() |
179 | 177 |
|
180 | | - kiwi_task.process() |
| 178 | + def _kiwi_build_task(self, description: str, target_dir: str) -> SystemBuildTask: |
| 179 | + with patch.object( |
| 180 | + sys, 'argv', self._validate_kiwi_build_command( |
| 181 | + [ |
| 182 | + 'system', 'build', |
| 183 | + '--description', description, |
| 184 | + '--target-dir', target_dir, |
| 185 | + '--allow-existing-root' |
| 186 | + ] |
| 187 | + ) |
| 188 | + ): |
| 189 | + return SystemBuildTask( |
| 190 | + should_perform_task_setup=False |
| 191 | + ) |
| 192 | + |
| 193 | + def _kiwi_create_task(self, root_dir: str, target_dir: str) -> SystemCreateTask: |
| 194 | + with patch.object( |
| 195 | + sys, 'argv', self._validate_kiwi_create_command( |
| 196 | + [ |
| 197 | + 'system', 'create', |
| 198 | + '--root', root_dir, |
| 199 | + '--target-dir', target_dir |
| 200 | + ] |
| 201 | + ) |
| 202 | + ): |
| 203 | + return SystemCreateTask( |
| 204 | + should_perform_task_setup=False |
| 205 | + ) |
181 | 206 |
|
182 | 207 | def _validate_kiwi_create_command( |
183 | 208 | self, kiwi_create_command: List[str] |
|
0 commit comments