Use platform.machine() when processor() fails.

With CPUARCH being set up automatically from the system via the
platform.processor() function, on some machines an empty string
is returned and the script refuses to build any images.

According to the documentation for the platform module, this can
be an issue with some processors, that either return nothing
or return the same string as with platform.machine().

This PR adds the option to obtain the value from platform.machine()
if the first (and preferred) method returns nothing.
This commit is contained in:
Lukáš Růžička 2024-01-03 13:06:26 +01:00
parent d65c71c11c
commit b1e084e93b
1 changed files with 7 additions and 2 deletions

View File

@ -43,6 +43,11 @@ from six.moves.urllib.request import urlopen
# directory.
SCRIPTDIR = os.path.abspath(os.path.dirname(sys.argv[0]))
CPUARCH = platform.processor()
# Some processors or platforms return an empty string in
# previous step and the script then ends with an error
# saying "Won't create X image on host."
# If that happens, let's read the value from the
# platform.machine() instead.
if not CPUARCH:
CPUARCH = platform.machine()
logger = logging.getLogger('createhdds')
@ -157,7 +162,7 @@ class GuestfsImage(object):
gpt_type = part.get("gpt_type", None)
if gpt_type:
gfs.part_set_gpt_type(disk, partnum, gpt_type)
# format the partition
# format the partition
gfs.mkfs(part['filesystem'], partname, label=part.get('label'))
# do file 'writes' (create a file with a given string as
# its content)
@ -308,7 +313,7 @@ class VirtInstallImage(object):
# build Workstation images out of Everything
if variant == 'Workstation':
variant = 'Everything'
try:
# this is almost complex enough to need fedfind but not
# quite, I think. also fedfind can't find the 'transient'