diff options
Diffstat (limited to 'scripts/lib/wic')
| -rw-r--r-- | scripts/lib/wic/imager/direct.py | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/scripts/lib/wic/imager/direct.py b/scripts/lib/wic/imager/direct.py index 6340a59a0a..575fd95f11 100644 --- a/scripts/lib/wic/imager/direct.py +++ b/scripts/lib/wic/imager/direct.py | |||
| @@ -99,7 +99,7 @@ class DirectImageCreator: | |||
| 99 | self.compressor = compressor | 99 | self.compressor = compressor |
| 100 | self.bmap = bmap | 100 | self.bmap = bmap |
| 101 | 101 | ||
| 102 | def __get_part_num(self, num, parts): | 102 | def _get_part_num(self, num, parts): |
| 103 | """calculate the real partition number, accounting for partitions not | 103 | """calculate the real partition number, accounting for partitions not |
| 104 | in the partition table and logical partitions | 104 | in the partition table and logical partitions |
| 105 | """ | 105 | """ |
| @@ -142,7 +142,7 @@ class DirectImageCreator: | |||
| 142 | """Assume partition order same as in wks""" | 142 | """Assume partition order same as in wks""" |
| 143 | updated = False | 143 | updated = False |
| 144 | for num, part in enumerate(parts, 1): | 144 | for num, part in enumerate(parts, 1): |
| 145 | pnum = self.__get_part_num(num, parts) | 145 | pnum = self._get_part_num(num, parts) |
| 146 | if not pnum or not part.mountpoint \ | 146 | if not pnum or not part.mountpoint \ |
| 147 | or part.mountpoint in ("/", "/boot"): | 147 | or part.mountpoint in ("/", "/boot"): |
| 148 | continue | 148 | continue |
| @@ -209,7 +209,7 @@ class DirectImageCreator: | |||
| 209 | # | 209 | # |
| 210 | # Actual implemention | 210 | # Actual implemention |
| 211 | # | 211 | # |
| 212 | def _create(self): | 212 | def create(self): |
| 213 | """ | 213 | """ |
| 214 | For 'wic', we already have our build artifacts - we just create | 214 | For 'wic', we already have our build artifacts - we just create |
| 215 | filesystems from the artifacts directly and combine them into | 215 | filesystems from the artifacts directly and combine them into |
| @@ -217,7 +217,7 @@ class DirectImageCreator: | |||
| 217 | """ | 217 | """ |
| 218 | parts = self._get_parts() | 218 | parts = self._get_parts() |
| 219 | 219 | ||
| 220 | self.__image = Image(self.native_sysroot) | 220 | self._image = Image(self.native_sysroot) |
| 221 | 221 | ||
| 222 | disk_ids = {} | 222 | disk_ids = {} |
| 223 | for num, part in enumerate(parts, 1): | 223 | for num, part in enumerate(parts, 1): |
| @@ -234,7 +234,7 @@ class DirectImageCreator: | |||
| 234 | if part.disk not in disk_ids: | 234 | if part.disk not in disk_ids: |
| 235 | disk_ids[part.disk] = int.from_bytes(os.urandom(4), 'little') | 235 | disk_ids[part.disk] = int.from_bytes(os.urandom(4), 'little') |
| 236 | disk_id = disk_ids[part.disk] | 236 | disk_id = disk_ids[part.disk] |
| 237 | part.uuid = '%0x-%02d' % (disk_id, self.__get_part_num(num, parts)) | 237 | part.uuid = '%0x-%02d' % (disk_id, self._get_part_num(num, parts)) |
| 238 | 238 | ||
| 239 | fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) | 239 | fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) |
| 240 | 240 | ||
| @@ -262,7 +262,7 @@ class DirectImageCreator: | |||
| 262 | self.bootimg_dir, self.kernel_dir, self.native_sysroot) | 262 | self.bootimg_dir, self.kernel_dir, self.native_sysroot) |
| 263 | 263 | ||
| 264 | 264 | ||
| 265 | self.__image.add_partition(part.disk_size, | 265 | self._image.add_partition(part.disk_size, |
| 266 | part.disk, | 266 | part.disk, |
| 267 | part.mountpoint, | 267 | part.mountpoint, |
| 268 | part.source_file, | 268 | part.source_file, |
| @@ -279,28 +279,27 @@ class DirectImageCreator: | |||
| 279 | if fstab_path: | 279 | if fstab_path: |
| 280 | shutil.move(fstab_path + ".orig", fstab_path) | 280 | shutil.move(fstab_path + ".orig", fstab_path) |
| 281 | 281 | ||
| 282 | self.__image.layout_partitions(self.ptable_format) | 282 | self._image.layout_partitions(self.ptable_format) |
| 283 | 283 | ||
| 284 | self.__imgdir = self.workdir | 284 | for disk_name, disk in self._image.disks.items(): |
| 285 | for disk_name, disk in self.__image.disks.items(): | 285 | full_path = self._full_path(self.workdir, disk_name, "direct") |
| 286 | full_path = self._full_path(self.__imgdir, disk_name, "direct") | ||
| 287 | msger.debug("Adding disk %s as %s with size %s bytes" \ | 286 | msger.debug("Adding disk %s as %s with size %s bytes" \ |
| 288 | % (disk_name, full_path, disk['min_size'])) | 287 | % (disk_name, full_path, disk['min_size'])) |
| 289 | disk_obj = DiskImage(full_path, disk['min_size']) | 288 | disk_obj = DiskImage(full_path, disk['min_size']) |
| 290 | self.__disks[disk_name] = disk_obj | 289 | #self._disks[disk_name] = disk_obj |
| 291 | self.__image.add_disk(disk_name, disk_obj, disk_ids.get(disk_name)) | 290 | self._image.add_disk(disk_name, disk_obj, disk_ids.get(disk_name)) |
| 292 | 291 | ||
| 293 | self.__image.create() | 292 | self._image.create() |
| 294 | 293 | ||
| 295 | def assemble(self): | 294 | def assemble(self): |
| 296 | """ | 295 | """ |
| 297 | Assemble partitions into disk image(s) | 296 | Assemble partitions into disk image(s) |
| 298 | """ | 297 | """ |
| 299 | for disk_name, disk in self.__image.disks.items(): | 298 | for disk_name, disk in self._image.disks.items(): |
| 300 | full_path = self._full_path(self.__imgdir, disk_name, "direct") | 299 | full_path = self._full_path(self.workdir, disk_name, "direct") |
| 301 | msger.debug("Assembling disk %s as %s with size %s bytes" \ | 300 | msger.debug("Assembling disk %s as %s with size %s bytes" \ |
| 302 | % (disk_name, full_path, disk['min_size'])) | 301 | % (disk_name, full_path, disk['min_size'])) |
| 303 | self.__image.assemble(full_path) | 302 | self._image.assemble(full_path) |
| 304 | 303 | ||
| 305 | def finalize(self): | 304 | def finalize(self): |
| 306 | """ | 305 | """ |
| @@ -308,12 +307,11 @@ class DirectImageCreator: | |||
| 308 | 307 | ||
| 309 | For example, prepare the image to be bootable by e.g. | 308 | For example, prepare the image to be bootable by e.g. |
| 310 | creating and installing a bootloader configuration. | 309 | creating and installing a bootloader configuration. |
| 311 | |||
| 312 | """ | 310 | """ |
| 313 | source_plugin = self.get_default_source_plugin() | 311 | source_plugin = self.get_default_source_plugin() |
| 314 | if source_plugin: | 312 | if source_plugin: |
| 315 | self._source_methods = pluginmgr.get_source_plugin_methods(source_plugin, disk_methods) | 313 | self._source_methods = pluginmgr.get_source_plugin_methods(source_plugin, disk_methods) |
| 316 | for disk_name, disk in self.__image.disks.items(): | 314 | for disk_name, disk in self._image.disks.items(): |
| 317 | self._source_methods["do_install_disk"](disk, disk_name, self, | 315 | self._source_methods["do_install_disk"](disk, disk_name, self, |
| 318 | self.workdir, | 316 | self.workdir, |
| 319 | self.oe_builddir, | 317 | self.oe_builddir, |
| @@ -321,8 +319,8 @@ class DirectImageCreator: | |||
| 321 | self.kernel_dir, | 319 | self.kernel_dir, |
| 322 | self.native_sysroot) | 320 | self.native_sysroot) |
| 323 | 321 | ||
| 324 | for disk_name, disk in self.__image.disks.items(): | 322 | for disk_name, disk in self._image.disks.items(): |
| 325 | full_path = self._full_path(self.__imgdir, disk_name, "direct") | 323 | full_path = self._full_path(self.workdir, disk_name, "direct") |
| 326 | # Generate .bmap | 324 | # Generate .bmap |
| 327 | if self.bmap: | 325 | if self.bmap: |
| 328 | msger.debug("Generating bmap file for %s" % disk_name) | 326 | msger.debug("Generating bmap file for %s" % disk_name) |
| @@ -341,12 +339,12 @@ class DirectImageCreator: | |||
| 341 | 339 | ||
| 342 | parts = self._get_parts() | 340 | parts = self._get_parts() |
| 343 | 341 | ||
| 344 | for disk_name in self.__image.disks: | 342 | for disk_name in self._image.disks: |
| 345 | extension = "direct" + {"gzip": ".gz", | 343 | extension = "direct" + {"gzip": ".gz", |
| 346 | "bzip2": ".bz2", | 344 | "bzip2": ".bz2", |
| 347 | "xz": ".xz", | 345 | "xz": ".xz", |
| 348 | "": ""}.get(self.compressor) | 346 | "": ""}.get(self.compressor) |
| 349 | full_path = self._full_path(self.__imgdir, disk_name, extension) | 347 | full_path = self._full_path(self.outdir, disk_name, extension) |
| 350 | msg += ' %s\n\n' % full_path | 348 | msg += ' %s\n\n' % full_path |
| 351 | 349 | ||
| 352 | msg += 'The following build artifacts were used to create the image(s):\n' | 350 | msg += 'The following build artifacts were used to create the image(s):\n' |
| @@ -380,13 +378,13 @@ class DirectImageCreator: | |||
| 380 | return "PARTUUID=%s" % part.uuid | 378 | return "PARTUUID=%s" % part.uuid |
| 381 | else: | 379 | else: |
| 382 | suffix = 'p' if part.disk.startswith('mmcblk') else '' | 380 | suffix = 'p' if part.disk.startswith('mmcblk') else '' |
| 383 | pnum = self.__get_part_num(num, parts) | 381 | pnum = self._get_part_num(num, parts) |
| 384 | return "/dev/%s%s%-d" % (part.disk, suffix, pnum) | 382 | return "/dev/%s%s%-d" % (part.disk, suffix, pnum) |
| 385 | 383 | ||
| 386 | def _cleanup(self): | 384 | def cleanup(self): |
| 387 | if not self.__image is None: | 385 | if self._image: |
| 388 | try: | 386 | try: |
| 389 | self.__image.cleanup() | 387 | self._image.cleanup() |
| 390 | except ImageError as err: | 388 | except ImageError as err: |
| 391 | msger.warning("%s" % err) | 389 | msger.warning("%s" % err) |
| 392 | 390 | ||
