Format code base with black
https://black.readthedocs.io/en/stable/ JIRA: COMPOSE-4086 Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
parent
38142d30ba
commit
41a629969c
84 changed files with 5748 additions and 3325 deletions
|
|
@ -24,60 +24,62 @@ from pungi.wrappers import iso
|
|||
|
||||
|
||||
def sh(log, cmd, *args, **kwargs):
|
||||
log.info('Running: %s', ' '.join(shlex_quote(x) for x in cmd))
|
||||
log.info("Running: %s", " ".join(shlex_quote(x) for x in cmd))
|
||||
ret, out = shortcuts.run(cmd, *args, universal_newlines=True, **kwargs)
|
||||
if out:
|
||||
log.debug('%s', out)
|
||||
log.debug("%s", out)
|
||||
return ret, out
|
||||
|
||||
|
||||
def get_lorax_dir(default='/usr/share/lorax'):
|
||||
def get_lorax_dir(default="/usr/share/lorax"):
|
||||
try:
|
||||
_, out = shortcuts.run(['python3', '-c' 'import pylorax; print(pylorax.find_templates())'],
|
||||
universal_newlines=True)
|
||||
_, out = shortcuts.run(
|
||||
["python3", "-c" "import pylorax; print(pylorax.find_templates())"],
|
||||
universal_newlines=True,
|
||||
)
|
||||
return out.strip()
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
def as_bool(arg):
|
||||
if arg == 'true':
|
||||
if arg == "true":
|
||||
return True
|
||||
elif arg == 'false':
|
||||
elif arg == "false":
|
||||
return False
|
||||
else:
|
||||
return arg
|
||||
|
||||
|
||||
def get_arch(log, iso_dir):
|
||||
di_path = os.path.join(iso_dir, '.discinfo')
|
||||
di_path = os.path.join(iso_dir, ".discinfo")
|
||||
if os.path.exists(di_path):
|
||||
di = productmd.discinfo.DiscInfo()
|
||||
di.load(di_path)
|
||||
log.info('Detected bootable ISO for %s (based on .discinfo)', di.arch)
|
||||
log.info("Detected bootable ISO for %s (based on .discinfo)", di.arch)
|
||||
return di.arch
|
||||
|
||||
ti_path = os.path.join(iso_dir, '.treeinfo')
|
||||
ti_path = os.path.join(iso_dir, ".treeinfo")
|
||||
if os.path.exists(ti_path):
|
||||
ti = productmd.treeinfo.TreeInfo()
|
||||
ti.load(ti_path)
|
||||
log.info('Detected bootable ISO for %s (based on .treeinfo)', ti.tree.arch)
|
||||
log.info("Detected bootable ISO for %s (based on .treeinfo)", ti.tree.arch)
|
||||
return ti.tree.arch
|
||||
|
||||
# There is no way to tell the architecture of an ISO file without guessing.
|
||||
# Let's print a warning and continue with assuming unbootable ISO.
|
||||
|
||||
log.warning('Failed to detect arch for ISO, assuming unbootable one.')
|
||||
log.warning('If this is incorrect, use the --force-arch option.')
|
||||
log.warning("Failed to detect arch for ISO, assuming unbootable one.")
|
||||
log.warning("If this is incorrect, use the --force-arch option.")
|
||||
return None
|
||||
|
||||
|
||||
def run(log, opts):
|
||||
# mount source iso
|
||||
log.info('Mounting %s', opts.source)
|
||||
log.info("Mounting %s", opts.source)
|
||||
target = os.path.abspath(opts.target)
|
||||
|
||||
with util.temp_dir(prefix='patch-iso-') as work_dir:
|
||||
with util.temp_dir(prefix="patch-iso-") as work_dir:
|
||||
with iso.mount(opts.source) as source_iso_dir:
|
||||
util.copy_all(source_iso_dir, work_dir)
|
||||
|
||||
|
|
@ -94,29 +96,34 @@ def run(log, opts):
|
|||
# create graft points from mounted source iso + overlay dir
|
||||
graft_points = iso.get_graft_points([work_dir] + opts.dirs)
|
||||
# if ks.cfg is detected, patch syslinux + grub to use it
|
||||
if 'ks.cfg' in graft_points:
|
||||
log.info('Adding ks.cfg to boot configs')
|
||||
tweak_configs(work_dir, volume_id, graft_points['ks.cfg'], logger=log)
|
||||
if "ks.cfg" in graft_points:
|
||||
log.info("Adding ks.cfg to boot configs")
|
||||
tweak_configs(work_dir, volume_id, graft_points["ks.cfg"], logger=log)
|
||||
|
||||
arch = opts.force_arch or get_arch(log, work_dir)
|
||||
|
||||
with tempfile.NamedTemporaryFile(prefix='graft-points-') as graft_file:
|
||||
iso.write_graft_points(graft_file.name, graft_points,
|
||||
exclude=["*/TRANS.TBL", "*/boot.cat"])
|
||||
with tempfile.NamedTemporaryFile(prefix="graft-points-") as graft_file:
|
||||
iso.write_graft_points(
|
||||
graft_file.name, graft_points, exclude=["*/TRANS.TBL", "*/boot.cat"]
|
||||
)
|
||||
|
||||
# make the target iso bootable if source iso is bootable
|
||||
boot_args = input_charset = None
|
||||
if arch:
|
||||
boot_args = iso.get_boot_options(
|
||||
arch, os.path.join(get_lorax_dir(), 'config_files/ppc'))
|
||||
input_charset = 'utf-8' if 'ppc' not in arch else None
|
||||
arch, os.path.join(get_lorax_dir(), "config_files/ppc")
|
||||
)
|
||||
input_charset = "utf-8" if "ppc" not in arch else None
|
||||
# Create the target ISO
|
||||
mkisofs_cmd = iso.get_mkisofs_cmd(target, None,
|
||||
volid=volume_id,
|
||||
exclude=["./lost+found"],
|
||||
graft_points=graft_file.name,
|
||||
input_charset=input_charset,
|
||||
boot_args=boot_args)
|
||||
mkisofs_cmd = iso.get_mkisofs_cmd(
|
||||
target,
|
||||
None,
|
||||
volid=volume_id,
|
||||
exclude=["./lost+found"],
|
||||
graft_points=graft_file.name,
|
||||
input_charset=input_charset,
|
||||
boot_args=boot_args,
|
||||
)
|
||||
sh(log, mkisofs_cmd, workdir=work_dir)
|
||||
|
||||
# isohybrid support
|
||||
|
|
@ -124,7 +131,9 @@ def run(log, opts):
|
|||
isohybrid_cmd = iso.get_isohybrid_cmd(target, arch)
|
||||
sh(log, isohybrid_cmd)
|
||||
|
||||
supported = as_bool(opts.supported or iso.get_checkisomd5_data(opts.source)['Supported ISO'])
|
||||
supported = as_bool(
|
||||
opts.supported or iso.get_checkisomd5_data(opts.source)["Supported ISO"]
|
||||
)
|
||||
# implantmd5 + supported bit (use the same as on source iso, unless
|
||||
# overriden by --supported option)
|
||||
isomd5sum_cmd = iso.get_implantisomd5_cmd(target, supported)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue