Skip to content

Commit

Permalink
use pycdlib to get iso label
Browse files Browse the repository at this point in the history
  • Loading branch information
nazunalika committed Nov 15, 2024
1 parent df4bb47 commit a4d6899
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
17 changes: 14 additions & 3 deletions iso/empanadas/empanadas/util/iso_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ def _extra_iso_build_wrap(self):
if not os.path.exists(lorax_path):
self.log.error(Color.FAIL + 'Lorax not found at all. This is considered fatal.')

# do we need to do a hard exit here?
raise SystemExit()

grafts = self._generate_graft_points(
Expand All @@ -779,7 +780,12 @@ def _extra_iso_build_wrap(self):
self.iso_map['images'][y]['repos'],
reposcan=reposcan
)
self._extra_iso_local_config(a, y, grafts, work_root, volname)
try:
self._extra_iso_local_config(a, y, grafts, work_root)
except ValueError as exc:
self.log.error(Color.FAIL + f'An error occured while configuring extra ISO build {exc}')
self.log.error(Color.FAIL + f'Error: {exc}')
continue

if self.extra_iso_mode == 'local':
self._extra_iso_local_run(a, y, work_root)
Expand All @@ -799,7 +805,7 @@ def _extra_iso_build_wrap(self):

self._extra_iso_podman_run(arches_to_build, images_to_build_podman, work_root)

def _extra_iso_local_config(self, arch, image, grafts, work_root, volname):
def _extra_iso_local_config(self, arch, image, grafts, work_root):
"""
Local ISO build configuration - This generates the configuration for
both mock and podman entries
Expand Down Expand Up @@ -839,12 +845,15 @@ def _extra_iso_local_config(self, arch, image, grafts, work_root, volname):
if self.updated_image:
datestamp = '-' + self.updated_image_date

volid = f'{self.shortname}-{self.major_version}-{self.minor_version}{rclevel}-{arch}-{volname}'
volid = Idents.get_vol_id(boot_iso)
isoname = f'{self.shortname}-{self.release}{rclevel}{datestamp}-{arch}-{image}.iso'
generic_isoname = f'{self.shortname}-{arch}-{image}.iso'
latest_isoname = f'{self.shortname}-{self.major_version}-latest-{arch}-{image}.iso'
required_pkgs = self.iso_map['lorax']['required_pkgs']

if not volid:
raise ValueError('Volume ID could not be determined')

lorax_pkg_cmd = '/usr/bin/dnf install {} -y {}'.format(
' '.join(required_pkgs),
log_path_command
Expand Down Expand Up @@ -882,6 +891,8 @@ def _extra_iso_local_config(self, arch, image, grafts, work_root, volname):
'iso_level': self.iso_map['iso_level'],
}

self.log.info(Color.INFO + f'boot.iso volume name: {volid}')

# Generate a xorriso compatible dialog
with open(grafts) as xp:
xorpoint = xp.read()
Expand Down
23 changes: 20 additions & 3 deletions iso/empanadas/empanadas/util/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import xmltodict
import productmd.treeinfo
import productmd.composeinfo
import pycdlib
import empanadas
import kobo.shortcuts
from empanadas.common import Color
Expand All @@ -24,8 +25,13 @@ class ArchCheck:
archfile = {
'x86_64': [
'isolinux/vmlinuz',
'images/efiboot.img',
'images/eltorito.img',
'images/grub.conf',
'EFI/BOOT/BOOTX64.EFI'
'images/install.img',
'boot/grub2/grub.cfg',
'EFI/BOOT/BOOTX64.EFI',
'EFI/BOOT/grub.cfg'
],
'aarch64': [
'EFI/BOOT/BOOTAA64.EFI'
Expand Down Expand Up @@ -1337,10 +1343,21 @@ def is_image(k):
return False

@staticmethod
def get_vol_id(opts):
def get_vol_id(i):
"""
Gets a volume ID
Gets a volume ID of a given ISO
"""
iso = pycdlib.PyCdlib()
try:
iso.open(i)
except pycdlib.pycdlibexception.PyCdlibInvalidISO as exc:
print(exc)
return False

pvd = iso.pvd
volume_id = pvd.volume_identifier.decode('UTF-8').strip()
iso.close()
return volume_id

class Syncs:
"""
Expand Down
24 changes: 23 additions & 1 deletion iso/empanadas/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions iso/empanadas/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ requests = "^2.32.2"
kobo = "^0.37.0"
attrs = "^24.2.0"
GitPython = ">=3.1.30"
file-magic = ">=0.4.0"
pycdlib = ">=1.14.0"

[tool.poetry.dev-dependencies]
pytest = "~5"
Expand Down

0 comments on commit a4d6899

Please sign in to comment.