add magic

This commit is contained in:
Louis Abel 2024-11-15 15:08:03 -07:00
parent a4d6899601
commit f268502918
Signed by untrusted user: label
GPG Key ID: 2A6975660E424560

View File

@ -14,6 +14,7 @@ import xmltodict
import productmd.treeinfo import productmd.treeinfo
import productmd.composeinfo import productmd.composeinfo
import pycdlib import pycdlib
import magic
import empanadas import empanadas
import kobo.shortcuts import kobo.shortcuts
from empanadas.common import Color from empanadas.common import Color
@ -1342,6 +1343,19 @@ class Idents:
return False return False
@staticmethod
def get_magic(m):
"""
Gets magic data of a given file
"""
try:
meta = magic.detect_from_filename(m)
except ValueError as exc:
print(exc)
return False
return meta
@staticmethod @staticmethod
def get_vol_id(i): def get_vol_id(i):
""" """
@ -1353,6 +1367,14 @@ class Idents:
except pycdlib.pycdlibexception.PyCdlibInvalidISO as exc: except pycdlib.pycdlibexception.PyCdlibInvalidISO as exc:
print(exc) print(exc)
return False return False
# This is for s390x. a temporary hack
except pycdlib.pycdlibexception.PyCdlibInvalidInput as exc:
print(exc)
print('Trying magic instead')
magic_data = Idents.get_magic(i)
if magic_data.mime_type == 'application/x-iso9660-image':
volume_id = magic_data.name.split("'")[1]
return volume_id
pvd = iso.pvd pvd = iso.pvd
volume_id = pvd.volume_identifier.decode('UTF-8').strip() volume_id = pvd.volume_identifier.decode('UTF-8').strip()