diff --git a/assemblers/org.osbuild.oci-archive b/assemblers/org.osbuild.oci-archive index 83c061e0..de6920af 100755 --- a/assemblers/org.osbuild.oci-archive +++ b/assemblers/org.osbuild.oci-archive @@ -112,7 +112,7 @@ MEDIA_TYPES = { def sha256sum(path: str) -> str: ret = subprocess.run(["sha256sum", path], stdout=subprocess.PIPE, - encoding="utf-8", + encoding="utf8", check=True) return ret.stdout.strip().split(" ")[0] @@ -135,7 +135,7 @@ def blobs_add_file(blobs: str, path: str, mtype: str): def blobs_add_json(blobs: str, js: str, mtype: str): js_file = os.path.join(blobs, "temporary.js") - with open(js_file, "w") as f: + with open(js_file, "w", encoding="utf8") as f: json.dump(js, f) return blobs_add_file(blobs, js_file, mtype) @@ -246,11 +246,11 @@ def create_oci_dir(tree, output_dir, options): # index print("writing index") - with open(os.path.join(output_dir, "index.json"), "w") as f: + with open(os.path.join(output_dir, "index.json"), "w", encoding="utf8") as f: json.dump(index, f) # oci-layout tag - with open(os.path.join(output_dir, "oci-layout"), "w") as f: + with open(os.path.join(output_dir, "oci-layout"), "w", encoding="utf8") as f: json.dump({"imageLayoutVersion": "1.0.0"}, f) diff --git a/assemblers/org.osbuild.ostree.commit b/assemblers/org.osbuild.ostree.commit index e37800ab..d6f42d96 100755 --- a/assemblers/org.osbuild.ostree.commit +++ b/assemblers/org.osbuild.ostree.commit @@ -166,7 +166,7 @@ def main(tree, output_dir, options, meta): stdout=sys.stderr, check=True) - with open(os.path.join(output_dir, "compose.json"), "r") as f: + with open(os.path.join(output_dir, "compose.json"), "r", encoding="utf8") as f: compose = json.load(f) api.metadata({"compose": compose}) diff --git a/assemblers/org.osbuild.qemu b/assemblers/org.osbuild.qemu index daaf3104..a2d71ac4 100755 --- a/assemblers/org.osbuild.qemu +++ b/assemblers/org.osbuild.qemu @@ -171,7 +171,7 @@ def mkfs_ext4(device, uuid, label): if label: opts = ["-L", label] subprocess.run(["mkfs.ext4", "-U", uuid] + opts + [device], - input="y", encoding='utf-8', check=True) + input="y", encoding='utf8', check=True) def mkfs_xfs(device, uuid, label): @@ -179,7 +179,7 @@ def mkfs_xfs(device, uuid, label): if label: opts = ["-L", label] subprocess.run(["mkfs.xfs", "-m", f"uuid={uuid}"] + opts + [device], - encoding='utf-8', check=True) + encoding='utf8', check=True) def mkfs_btrfs(device, uuid, label): @@ -187,7 +187,7 @@ def mkfs_btrfs(device, uuid, label): if label: opts = ["-L", label] subprocess.run(["mkfs.btrfs", "-U", uuid] + opts + [device], - encoding='utf-8', check=True) + encoding='utf8', check=True) def mkfs_vfat(device, uuid, label): @@ -195,7 +195,7 @@ def mkfs_vfat(device, uuid, label): opts = [] if label: opts = ["-n", label] - subprocess.run(["mkfs.vfat", "-i", volid] + opts + [device], encoding='utf-8', check=True) + subprocess.run(["mkfs.vfat", "-i", volid] + opts + [device], encoding='utf8', check=True) class Filesystem: @@ -336,7 +336,7 @@ class PartitionTable: subprocess.run(["sfdisk", "-q", target], input=command, - encoding='utf-8', + encoding='utf8', check=True) if sync: @@ -346,7 +346,7 @@ class PartitionTable: """Update and fill in missing information from disk""" r = subprocess.run(["sfdisk", "--json", target], stdout=subprocess.PIPE, - encoding='utf-8', + encoding='utf8', check=True) disk_table = json.loads(r.stdout)["partitiontable"] disk_parts = disk_table["partitions"] @@ -596,7 +596,7 @@ def install_grub2(image: str, pt: PartitionTable, options): def parse_blsfile(blsfile): params = {} - with open(blsfile, "r") as bls: + with open(blsfile, "r", encoding="utf8") as bls: for line in bls: key, value = line.split(' ', 1) params[key] = value.strip() @@ -698,7 +698,7 @@ def main(tree, output_dir, options, loop_client): if fmt == "raw": subprocess.run(["cp", image, f"{output_dir}/{filename}"], check=True) elif fmt == "raw.xz": - with open(f"{output_dir}/{filename}", "w") as f: + with open(f"{output_dir}/{filename}", "w", encoding="utf8") as f: subprocess.run( ["xz", "--keep", "--stdout", "-0", image], stdout=f, diff --git a/assemblers/org.osbuild.rawfs b/assemblers/org.osbuild.rawfs index 9d4b3506..80c223b0 100755 --- a/assemblers/org.osbuild.rawfs +++ b/assemblers/org.osbuild.rawfs @@ -68,15 +68,15 @@ def mount(source, dest, *options): def mkfs_ext4(device, uuid): - subprocess.run(["mkfs.ext4", "-U", uuid, device], input="y", encoding='utf-8', check=True) + subprocess.run(["mkfs.ext4", "-U", uuid, device], input="y", encoding='utf8', check=True) def mkfs_xfs(device, uuid): - subprocess.run(["mkfs.xfs", "-m", f"uuid={uuid}", device], encoding='utf-8', check=True) + subprocess.run(["mkfs.xfs", "-m", f"uuid={uuid}", device], encoding='utf8', check=True) def mkfs_btrfs(device, uuid): - subprocess.run(["mkfs.btrfs", "-U", uuid, device], encoding='utf-8', check=True) + subprocess.run(["mkfs.btrfs", "-U", uuid, device], encoding='utf8', check=True) def main(tree, output_dir, options, loop_client): diff --git a/runners/org.osbuild.rhel7 b/runners/org.osbuild.rhel7 index 9399a6c2..89988771 100755 --- a/runners/org.osbuild.rhel7 +++ b/runners/org.osbuild.rhel7 @@ -9,7 +9,7 @@ import osbuild.api def ldconfig(): # ld.so.conf must exist, or `ldconfig` throws a warning - with open("/etc/ld.so.conf", "w", ) as f: + with open("/etc/ld.so.conf", "w", encoding="utf8") as f: # qemu-img needs `libiscsi`, which is located in /usr/lib64/iscsi f.write("/usr/lib64/iscsi\n") f.flush() diff --git a/runners/org.osbuild.rhel81 b/runners/org.osbuild.rhel81 index 5312a00e..4341e035 100755 --- a/runners/org.osbuild.rhel81 +++ b/runners/org.osbuild.rhel81 @@ -46,7 +46,7 @@ def os_release(): # remove the symlink that systemd-nspawn creates os.remove("/etc/os-release") - with open("/etc/os-release", "w") as f: + with open("/etc/os-release", "w", encoding="utf8") as f: f.write('NAME="Red Hat Enterprise Linux"\n') f.write('VERSION="8.1 (Ootpa)"\n') f.write('ID="rhel"\n') diff --git a/stages/org.osbuild.anaconda b/stages/org.osbuild.anaconda index 7ccebfe5..adb2bd51 100755 --- a/stages/org.osbuild.anaconda +++ b/stages/org.osbuild.anaconda @@ -45,7 +45,7 @@ def main(tree, options): product_dir = os.path.join(tree, "etc/anaconda/conf.d") os.makedirs(product_dir, exist_ok=True) - with open(os.path.join(product_dir, "90-osbuild.conf"), "w") as f: + with open(os.path.join(product_dir, "90-osbuild.conf"), "w", encoding="utf8") as f: f.write(CONFIG) for m in modules: f.write(f" {m}\n") diff --git a/stages/org.osbuild.bootiso.mono b/stages/org.osbuild.bootiso.mono index daa99b3e..034223f4 100755 --- a/stages/org.osbuild.bootiso.mono +++ b/stages/org.osbuild.bootiso.mono @@ -171,7 +171,7 @@ def replace(target, patterns): finder = [(re.compile(p), s) for p, s in patterns] newfile = target + ".replace" - with open(target, "r") as i, open(newfile, "w") as o: + with open(target, "r", encoding="utf8") as i, open(newfile, "w", encoding="utf8") as o: for line in i: for p, s in finder: line = p.sub(s, line) @@ -180,7 +180,7 @@ def replace(target, patterns): def make_rootfs(tree, image, size, workdir, loop_client): - with open(image, "w") as f: + with open(image, "w", encoding="utf8") as f: os.ftruncate(f.fileno(), size) root = os.path.join(workdir, "rootfs") @@ -192,7 +192,7 @@ def make_rootfs(tree, image, size, workdir, loop_client): "-b", "4096", "-m", "0", dev], - input="y", encoding='utf-8', check=True) + input="y", encoding='utf8', check=True) with mount(dev, root): print("copying tree") @@ -267,7 +267,7 @@ def make_efi(efi, info, root, loop_client): # create the image image = os.path.join(info["imgdir"], "efiboot.img") - with open(image, "w") as f: + with open(image, "w", encoding="utf8") as f: os.ftruncate(f.fileno(), size) root = os.path.join(info["workdir"], "mnt") @@ -277,7 +277,7 @@ def make_efi(efi, info, root, loop_client): subprocess.run(["mkfs.fat", "-n", "ANACONDA", dev], - input="y", encoding='utf-8', check=True) + input="y", encoding='utf8', check=True) with mount(dev, root): target = os.path.join(root, "EFI", "BOOT") diff --git a/stages/org.osbuild.buildstamp b/stages/org.osbuild.buildstamp index d1c5523f..0053a5f9 100755 --- a/stages/org.osbuild.buildstamp +++ b/stages/org.osbuild.buildstamp @@ -74,7 +74,7 @@ def main(tree, options): "osbuild": "devel", } - with open(f"{tree}/.buildstamp", "w") as f: + with open(f"{tree}/.buildstamp", "w", encoding="utf8") as f: stamp.write(f) return 0 diff --git a/stages/org.osbuild.chrony b/stages/org.osbuild.chrony index 5a43d56d..8590afd6 100755 --- a/stages/org.osbuild.chrony +++ b/stages/org.osbuild.chrony @@ -154,7 +154,7 @@ def main(tree, options): # therefore default to 'None' to distinguish these two cases. leapsectz = options.get("leapsectz", None) - with open(f"{tree}/etc/chrony.conf") as f: + with open(f"{tree}/etc/chrony.conf", encoding="utf8") as f: chrony_conf = f.read() # Split to lines and remove ones starting with server, pool or peer. @@ -172,7 +172,7 @@ def main(tree, options): new_chrony_conf = "\n".join(lines) - with open(f"{tree}/etc/chrony.conf", "w") as f: + with open(f"{tree}/etc/chrony.conf", "w", encoding="utf8") as f: f.write(new_chrony_conf) return 0 diff --git a/stages/org.osbuild.clevis.luks-bind b/stages/org.osbuild.clevis.luks-bind index bb74a7ad..0a6843cb 100755 --- a/stages/org.osbuild.clevis.luks-bind +++ b/stages/org.osbuild.clevis.luks-bind @@ -68,7 +68,7 @@ def main(devices, options): os.symlink("/proc/self/fd", "/dev/fd") subprocess.run(command, - encoding='utf-8', check=True, + encoding='utf8', check=True, input=passphrase) diff --git a/stages/org.osbuild.cloud-init b/stages/org.osbuild.cloud-init index ca1aff4f..ac8aa16d 100755 --- a/stages/org.osbuild.cloud-init +++ b/stages/org.osbuild.cloud-init @@ -151,7 +151,7 @@ def main(tree, options): config_files_dir = f"{tree}/etc/cloud/cloud.cfg.d" - with open(f"{config_files_dir}/{filename}", "w") as f: + with open(f"{config_files_dir}/{filename}", "w", encoding="utf8") as f: yaml.dump(config, f, default_flow_style=False) return 0 diff --git a/stages/org.osbuild.containers.storage.conf b/stages/org.osbuild.containers.storage.conf index da3b58a2..85886ad4 100755 --- a/stages/org.osbuild.containers.storage.conf +++ b/stages/org.osbuild.containers.storage.conf @@ -161,12 +161,12 @@ def main(tree, options): data = {} with contextlib.suppress(FileNotFoundError): - with open(path, "r", encoding="utf-8") as f: + with open(path, "r", encoding="utf8") as f: data = toml.load(f) merge_config("storage", data, config) - with open(path, "w", encoding="utf-8") as f: + with open(path, "w", encoding="utf8") as f: write_comment(f, HEADER) write_comment(f, comment) diff --git a/stages/org.osbuild.cron.script b/stages/org.osbuild.cron.script index d18ef20f..c29ba400 100755 --- a/stages/org.osbuild.cron.script +++ b/stages/org.osbuild.cron.script @@ -66,7 +66,7 @@ def main(tree, options): filename = options["filename"] filepath = os.path.join(tree, "etc", f"cron.{interval}", filename) - with open(filepath, "w", encoding="utf-8") as f: + with open(filepath, "w", encoding="utf8") as f: cmd = options["simple"] cmdline = cmd["command"] comment = cmd.get("comment") diff --git a/stages/org.osbuild.crypttab b/stages/org.osbuild.crypttab index f12beecd..5c8b33cd 100755 --- a/stages/org.osbuild.crypttab +++ b/stages/org.osbuild.crypttab @@ -66,7 +66,7 @@ SCHEMA = """ def main(tree, options): volumes = options["volumes"] - with open(f"{tree}/etc/crypttab", "w") as f: + with open(f"{tree}/etc/crypttab", "w", encoding="utf8") as f: for volume in volumes: name = volume["volume"] uuid = volume.get("uuid") diff --git a/stages/org.osbuild.debug-shell b/stages/org.osbuild.debug-shell index 8f944c14..935f129f 100755 --- a/stages/org.osbuild.debug-shell +++ b/stages/org.osbuild.debug-shell @@ -56,7 +56,7 @@ KillSignal=SIGHUP UnsetEnvironment=LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION """ - with open(f"{tree}/etc/systemd/system/osbuild-debug-shell.service", "w") as f: + with open(f"{tree}/etc/systemd/system/osbuild-debug-shell.service", "w", encoding="utf8") as f: f.write(unit) os.symlink("../osbuild-debug-shell.service", diff --git a/stages/org.osbuild.discinfo b/stages/org.osbuild.discinfo index 3fc86607..894eee39 100755 --- a/stages/org.osbuild.discinfo +++ b/stages/org.osbuild.discinfo @@ -35,7 +35,7 @@ def main(tree, options): # Based on `pylorax/discinfo.py` timestamp = time.time() - with open(os.path.join(tree, ".discinfo"), "w") as f: + with open(os.path.join(tree, ".discinfo"), "w", encoding="utf8") as f: f.write(f"{timestamp}\n") f.write(f"{release}\n") f.write(f"{basearch}\n") diff --git a/stages/org.osbuild.dnf-automatic.config b/stages/org.osbuild.dnf-automatic.config index a7975860..1acec52a 100755 --- a/stages/org.osbuild.dnf-automatic.config +++ b/stages/org.osbuild.dnf-automatic.config @@ -68,7 +68,7 @@ def main(tree, options): return 0 try: - with open(dnf_automatic_config_path, "r") as f: + with open(dnf_automatic_config_path, "r", encoding="utf8") as f: dnf_automatic_conf.readfp(f) except FileNotFoundError: print(f"Error: DNF automatic configuration file '{dnf_automatic_config_path}' does not exist.") @@ -80,7 +80,7 @@ def main(tree, options): value = bool_to_yes_no(value) dnf_automatic_conf.set(config_section, option, value) - with open(dnf_automatic_config_path, "w") as f: + with open(dnf_automatic_config_path, "w", encoding="utf8") as f: dnf_automatic_conf.write(f) return 0 diff --git a/stages/org.osbuild.dnf.config b/stages/org.osbuild.dnf.config index d91d06c3..88444a78 100755 --- a/stages/org.osbuild.dnf.config +++ b/stages/org.osbuild.dnf.config @@ -102,7 +102,7 @@ def configure_variable(tree, name, value): """ vars_directory = "/etc/dnf/vars" - with open(f"{tree}{vars_directory}/{name}", "w", encoding="utf-8") as f: + with open(f"{tree}{vars_directory}/{name}", "w", encoding="utf8") as f: f.write(value + "\n") @@ -133,7 +133,7 @@ def make_dnf_config(tree, config_options): dnf_config = iniparse.SafeConfigParser() try: - with open(dnf_config_path, "r", encoding="utf-8") as f: + with open(dnf_config_path, "r", encoding="utf8") as f: dnf_config.readfp(f) except FileNotFoundError: print(f"Warning: DNF configuration file '{dnf_config_path}' does not exist, will create it.") @@ -142,7 +142,7 @@ def make_dnf_config(tree, config_options): for section, items in config_options.items(): make_section(dnf_config, section, items) - with open(dnf_config_path, "w", encoding="utf-8") as f: + with open(dnf_config_path, "w", encoding="utf8") as f: os.fchmod(f.fileno(), 0o644) dnf_config.write(f) diff --git a/stages/org.osbuild.dracut.conf b/stages/org.osbuild.dracut.conf index 4cd6010b..346542d5 100755 --- a/stages/org.osbuild.dracut.conf +++ b/stages/org.osbuild.dracut.conf @@ -172,7 +172,7 @@ def main(tree, options): "reproducible": bool_option_writer } - with open(f"{config_files_dir}/{filename}", "w") as f: + with open(f"{config_files_dir}/{filename}", "w", encoding="utf8") as f: for option, value in config.items(): try: writter_func = SUPPORTED_OPTIONS[option] diff --git a/stages/org.osbuild.first-boot b/stages/org.osbuild.first-boot index 005ded22..8922a226 100755 --- a/stages/org.osbuild.first-boot +++ b/stages/org.osbuild.first-boot @@ -63,13 +63,13 @@ Type=oneshot {execs}""" os.makedirs(f"{tree}/usr/lib/systemd/system/default.target.wants", exist_ok=True) - with open(f"{tree}/usr/lib/systemd/system/osbuild-first-boot.service", "w") as f: + with open(f"{tree}/usr/lib/systemd/system/osbuild-first-boot.service", "w", encoding="utf8") as f: f.write(service) os.symlink("../osbuild-first-boot.service", f"{tree}/usr/lib/systemd/system/default.target.wants/osbuild-first-boot.service") os.makedirs(f"{tree}/etc", exist_ok=True) - open(f"{tree}/etc/osbuild-first-boot", 'a').close() + open(f"{tree}/etc/osbuild-first-boot", 'a', encoding="utf8").close() def main(tree, options): diff --git a/stages/org.osbuild.fix-bls b/stages/org.osbuild.fix-bls index 23380e9d..556e73ac 100755 --- a/stages/org.osbuild.fix-bls +++ b/stages/org.osbuild.fix-bls @@ -49,10 +49,10 @@ def main(tree, options): path_re = re.compile(r"(/.*)+/boot") for name in glob.glob(f"{tree}/boot/loader/entries/*.conf"): - with open(name) as f: + with open(name, encoding="utf8") as f: entry = f.read().splitlines(keepends=True) - with open(name, "w") as f: + with open(name, "w", encoding="utf8") as f: for line in entry: f.write(path_re.sub(prefix, line)) diff --git a/stages/org.osbuild.fstab b/stages/org.osbuild.fstab index f95214fc..c1764ace 100755 --- a/stages/org.osbuild.fstab +++ b/stages/org.osbuild.fstab @@ -129,7 +129,7 @@ def main(tree, options): path = f"{root}/etc/fstab" - with open(path, "w") as f: + with open(path, "w", encoding="utf8") as f: for filesystem in filesystems: uuid = filesystem.get("uuid") path = filesystem["path"] diff --git a/stages/org.osbuild.gcp.guest-agent.conf b/stages/org.osbuild.gcp.guest-agent.conf index 22f67b22..86de71b0 100755 --- a/stages/org.osbuild.gcp.guest-agent.conf +++ b/stages/org.osbuild.gcp.guest-agent.conf @@ -257,7 +257,7 @@ def main(tree, options): parser = iniparse.SafeConfigParser() try: - with open(filepath, "r", encoding="utf-8") as f: + with open(filepath, "r", encoding="utf8") as f: parser.readfp(f) except FileNotFoundError: print(f"Creating new guest-agent configuration file at '{filepath}'.") @@ -266,7 +266,7 @@ def main(tree, options): for section_id, section_content in config.items(): make_section(parser, section_id, section_content) - with open(filepath, "w", encoding="utf-8") as f: + with open(filepath, "w", encoding="utf8") as f: parser.write(f) return 0 diff --git a/stages/org.osbuild.greenboot b/stages/org.osbuild.greenboot index 6d142aef..700bda6e 100755 --- a/stages/org.osbuild.greenboot +++ b/stages/org.osbuild.greenboot @@ -67,7 +67,7 @@ def main(tree, options): new_svcs = [ns for ns in value if ns not in svcs] new_svcs.extend(svcs) sys.stdout.write('GREENBOOT_MONITOR_SERVICES="{0}"\n'.format(" ".join(new_svcs))) - with open(config_file, mode="a") as f: + with open(config_file, "a", encoding="utf8") as f: for key, value in changes.items(): if key == "monitor_services": f.write('GREENBOOT_MONITOR_SERVICES="{0}"\n'.format(" ".join(value))) diff --git a/stages/org.osbuild.grub2 b/stages/org.osbuild.grub2 index 0b4c11da..221986b7 100755 --- a/stages/org.osbuild.grub2 +++ b/stages/org.osbuild.grub2 @@ -440,7 +440,7 @@ class GrubConfig: tplt = string.Template(GRUB_CFG_TEMPLATE) data = tplt.safe_substitute(config) - with open(path, "w") as cfg: + with open(path, "w", encoding="utf8") as cfg: cfg.write(data) def write_redirect(self, tree, path): @@ -456,7 +456,7 @@ class GrubConfig: tplt = string.Template(GRUB_REDIRECT_TEMPLATE) data = tplt.safe_substitute(config) - with open(os.path.join(tree, path), "w") as cfg: + with open(os.path.join(tree, path), "w", encoding="utf8") as cfg: cfg.write(data) def defaults(self): @@ -530,7 +530,7 @@ def main(tree, options): # Create the configuration file that determines how grub.cfg is generated. if write_defaults: os.makedirs(f"{tree}/etc/default", exist_ok=True) - with open(f"{tree}/etc/default/grub", "w") as default: + with open(f"{tree}/etc/default/grub", "w", encoding="utf8") as default: default.write(config.defaults()) os.makedirs(f"{tree}/boot/grub2", exist_ok=True) @@ -545,7 +545,7 @@ def main(tree, options): except FileNotFoundError: pass - with open(grubenv, "w") as env: + with open(grubenv, "w", encoding="utf8") as env: fs_type, fs_id = fs_spec_decode(root_fs) data = "# GRUB Environment Block\n" diff --git a/stages/org.osbuild.grub2.iso b/stages/org.osbuild.grub2.iso index 62046c48..c7f4edec 100755 --- a/stages/org.osbuild.grub2.iso +++ b/stages/org.osbuild.grub2.iso @@ -145,7 +145,7 @@ def main(root, options): }) config = os.path.join(efidir, "grub.cfg") - with open(config, "w") as cfg: + with open(config, "w", encoding="utf8") as cfg: cfg.write(data) if "IA32" in architectures: diff --git a/stages/org.osbuild.grub2.legacy b/stages/org.osbuild.grub2.legacy index c5a71623..5e2af58c 100755 --- a/stages/org.osbuild.grub2.legacy +++ b/stages/org.osbuild.grub2.legacy @@ -423,7 +423,7 @@ class GrubConfig: data += "\n" - with open(path, "w") as cfg: + with open(path, "w", encoding="utf8") as cfg: print(data) cfg.write(data) @@ -478,13 +478,13 @@ def main(tree, options): # Create the configuration file that determines how grub.cfg is generated. if write_defaults: os.makedirs(f"{tree}/etc/default", exist_ok=True) - with open(f"{tree}/etc/default/grub", "w") as default: + with open(f"{tree}/etc/default/grub", "w", encoding="utf8") as default: default.write(config.defaults()) os.makedirs(f"{tree}/boot/grub2", exist_ok=True) grubenv = f"{tree}/boot/grub2/grubenv" - with open(grubenv, "w") as env: + with open(grubenv, "w", encoding="utf8") as env: data = ( "# GRUB Environment Block\n" ) diff --git a/stages/org.osbuild.gunzip b/stages/org.osbuild.gunzip index 956618b8..531fe68e 100755 --- a/stages/org.osbuild.gunzip +++ b/stages/org.osbuild.gunzip @@ -52,7 +52,7 @@ def main(inputs, output, options): source = parse_input(inputs) target = os.path.join(output, path.lstrip("/")) - with open(target, "w") as f: + with open(target, "w", encoding="utf8") as f: cmd = ["gunzip", "--stdout", source] subprocess.run(cmd, stdout=f, check=True) diff --git a/stages/org.osbuild.gzip b/stages/org.osbuild.gzip index fe257490..2fa2164a 100755 --- a/stages/org.osbuild.gzip +++ b/stages/org.osbuild.gzip @@ -53,7 +53,7 @@ def main(inputs, output, options): source = parse_input(inputs) target = os.path.join(output, filename) - with open(target, "w") as f: + with open(target, "w", encoding="utf8") as f: cmd = [ "gzip", "--no-name", "--stdout", "-1", source ] diff --git a/stages/org.osbuild.ignition b/stages/org.osbuild.ignition index 555bba1b..f743ebe8 100755 --- a/stages/org.osbuild.ignition +++ b/stages/org.osbuild.ignition @@ -44,7 +44,7 @@ def main(tree, options): # itself will be sourced this the 'ignition_network_kcmdline' # that is also in the "ignition_firstboot" variable can be # overwritten with the contents of `network` - with open(f"{tree}/boot/ignition.firstboot", "w") as f: + with open(f"{tree}/boot/ignition.firstboot", "w", encoding="utf8") as f: if network: netstr = " ".join(network) f.write(f"ignition_network_kcmdline={netstr}") diff --git a/stages/org.osbuild.isolinux b/stages/org.osbuild.isolinux index 30044a48..3effe65d 100755 --- a/stages/org.osbuild.isolinux +++ b/stages/org.osbuild.isolinux @@ -228,7 +228,7 @@ def main(tree, inputs, options): }) config = os.path.join(isolinux, "isolinux.cfg") - with open(config, "w") as cfg: + with open(config, "w", encoding="utf8") as cfg: cfg.write(data) # link the kernel diff --git a/stages/org.osbuild.kernel-cmdline b/stages/org.osbuild.kernel-cmdline index 0ed9745b..02149575 100755 --- a/stages/org.osbuild.kernel-cmdline +++ b/stages/org.osbuild.kernel-cmdline @@ -52,7 +52,7 @@ def main(tree, options): base = os.path.join(tree, "etc/kernel") os.makedirs(base, exist_ok=True) - with open(f"{base}/cmdline", "w") as f: + with open(f"{base}/cmdline", "w", encoding="utf8") as f: f.write(" ".join(filter(len, params))) return 0 diff --git a/stages/org.osbuild.keymap b/stages/org.osbuild.keymap index 418c01c8..551c237f 100755 --- a/stages/org.osbuild.keymap +++ b/stages/org.osbuild.keymap @@ -70,7 +70,7 @@ Section "InputClass" EndSection """ - with open(f"{tree}/etc/X11/xorg.conf.d/00-keyboard.conf", "w") as f: + with open(f"{tree}/etc/X11/xorg.conf.d/00-keyboard.conf", "w", encoding="utf8") as f: f.write(file_content) diff --git a/stages/org.osbuild.kickstart b/stages/org.osbuild.kickstart index 479e87a9..136a1d24 100755 --- a/stages/org.osbuild.kickstart +++ b/stages/org.osbuild.kickstart @@ -218,13 +218,13 @@ def main(tree, options): base = os.path.dirname(target) os.makedirs(base, exist_ok=True) - with open(target, "w") as f: + with open(target, "w", encoding="utf8") as f: if config: f.write("\n".join(config)) f.write("\n") print(f"created kickstarted at: {path}\n") - with open(target, "r") as f: + with open(target, "r", encoding="utf8") as f: print(f.read()) return 0 diff --git a/stages/org.osbuild.luks2.format b/stages/org.osbuild.luks2.format index 28991408..5e2a7cce 100755 --- a/stages/org.osbuild.luks2.format +++ b/stages/org.osbuild.luks2.format @@ -172,7 +172,7 @@ def main(devices, options): command += ["--pbkdf-parallel", str(parallelism)] subprocess.run(command + [path], - encoding='utf-8', check=True, + encoding='utf8', check=True, input=passphrase) diff --git a/stages/org.osbuild.luks2.remove-key b/stages/org.osbuild.luks2.remove-key index a964a99a..d9574520 100755 --- a/stages/org.osbuild.luks2.remove-key +++ b/stages/org.osbuild.luks2.remove-key @@ -51,7 +51,7 @@ def main(devices, options): ] subprocess.run(command + [path], - encoding='utf-8', check=True, + encoding='utf8', check=True, input=passphrase) diff --git a/stages/org.osbuild.lvm2.create b/stages/org.osbuild.lvm2.create index ca9f01cf..c0646b89 100755 --- a/stages/org.osbuild.lvm2.create +++ b/stages/org.osbuild.lvm2.create @@ -83,11 +83,11 @@ def main(devices, options): print(f"LVM2: using vg name '{vg_name}'") subprocess.run(["pvcreate", path], - encoding='utf-8', + encoding='utf8', check=True) subprocess.run(["vgcreate", vg_name, path], - encoding='utf-8', + encoding='utf8', check=True) for volume in volumes: @@ -104,7 +104,7 @@ def main(devices, options): cmd += ["-n", name, vg_name] - subprocess.run(cmd, encoding='utf-8', check=True) + subprocess.run(cmd, encoding='utf8', check=True) if __name__ == '__main__': diff --git a/stages/org.osbuild.mkfs.btrfs b/stages/org.osbuild.mkfs.btrfs index 46a8cc15..1b7f54a4 100755 --- a/stages/org.osbuild.mkfs.btrfs +++ b/stages/org.osbuild.mkfs.btrfs @@ -56,7 +56,7 @@ def main(devices, options): opts = ["-L", label] subprocess.run(["mkfs.btrfs", "-U", uuid] + opts + [device], - encoding='utf-8', check=True) + encoding='utf8', check=True) if __name__ == '__main__': diff --git a/stages/org.osbuild.mkfs.ext4 b/stages/org.osbuild.mkfs.ext4 index 57b875cf..07957a4a 100755 --- a/stages/org.osbuild.mkfs.ext4 +++ b/stages/org.osbuild.mkfs.ext4 @@ -56,7 +56,7 @@ def main(devices, options): opts = ["-L", label] subprocess.run(["mkfs.ext4", "-U", uuid] + opts + [device], - encoding='utf-8', check=True) + encoding='utf8', check=True) if __name__ == '__main__': diff --git a/stages/org.osbuild.mkfs.fat b/stages/org.osbuild.mkfs.fat index 647d265d..a37f4727 100755 --- a/stages/org.osbuild.mkfs.fat +++ b/stages/org.osbuild.mkfs.fat @@ -69,7 +69,7 @@ def main(devices, options): opts = ["-F", str(fatsize)] subprocess.run(["mkfs.fat", "-I", "-i", volid] + opts + [device], - encoding='utf-8', check=True) + encoding='utf8', check=True) if __name__ == '__main__': diff --git a/stages/org.osbuild.mkfs.xfs b/stages/org.osbuild.mkfs.xfs index 61b490e4..9af0aa89 100755 --- a/stages/org.osbuild.mkfs.xfs +++ b/stages/org.osbuild.mkfs.xfs @@ -56,7 +56,7 @@ def main(devices, options): opts = ["-L", label] subprocess.run(["mkfs.xfs", "-m", f"uuid={uuid}"] + opts + [device], - encoding='utf-8', check=True) + encoding='utf8', check=True) if __name__ == '__main__': diff --git a/stages/org.osbuild.modprobe b/stages/org.osbuild.modprobe index a544f5aa..188c38de 100755 --- a/stages/org.osbuild.modprobe +++ b/stages/org.osbuild.modprobe @@ -102,7 +102,7 @@ def main(tree, options): else: raise ValueError() - with open(f"{config_dir}/{config_file}", "w") as f: + with open(f"{config_dir}/{config_file}", "w", encoding="utf8") as f: f.writelines(lines) return 0 diff --git a/stages/org.osbuild.nginx.conf b/stages/org.osbuild.nginx.conf index 5dbf682b..96b70976 100755 --- a/stages/org.osbuild.nginx.conf +++ b/stages/org.osbuild.nginx.conf @@ -77,7 +77,7 @@ pid {pid}; daemon {daemon}; """ - with open(target, "w") as f: + with open(target, "w", encoding="utf8") as f: f.write(content) return 0 diff --git a/stages/org.osbuild.nm.conf b/stages/org.osbuild.nm.conf index 0958637a..1cbfa1d4 100755 --- a/stages/org.osbuild.nm.conf +++ b/stages/org.osbuild.nm.conf @@ -191,7 +191,7 @@ def main(tree, options): else: raise ValueError(f"Invalid section type: {type(items)}") - with open(cfgfile, "w") as f: + with open(cfgfile, "w", encoding="utf8") as f: os.fchmod(f.fileno(), 0o600) cfg.write(f, space_around_delimiters=False) diff --git a/stages/org.osbuild.nm.conn b/stages/org.osbuild.nm.conn index 1e9bcfc1..bf50c311 100755 --- a/stages/org.osbuild.nm.conn +++ b/stages/org.osbuild.nm.conn @@ -210,7 +210,7 @@ def main(tree, options): val = str(value) config.set(name, option, val) - with open(cfgfile, "w") as f: + with open(cfgfile, "w", encoding="utf8") as f: # need restrictive permissions os.fchmod(f.fileno(), 0o600) config.write(f, space_around_delimiters=False) diff --git a/stages/org.osbuild.oci-archive b/stages/org.osbuild.oci-archive index d490c3a4..16f12964 100755 --- a/stages/org.osbuild.oci-archive +++ b/stages/org.osbuild.oci-archive @@ -179,7 +179,7 @@ XATTRS_WANT = r"^(user.|security\.ima|security\.capability)" def sha256sum(path: str) -> str: ret = subprocess.run(["sha256sum", path], stdout=subprocess.PIPE, - encoding="utf-8", + encoding="utf8", check=True) return ret.stdout.strip().split(" ")[0] @@ -202,7 +202,7 @@ def blobs_add_file(blobs: str, path: str, mtype: str): def blobs_add_json(blobs: str, js: str, mtype: str): js_file = os.path.join(blobs, "temporary.js") - with open(js_file, "w", encoding="utf-8") as f: + with open(js_file, "w", encoding="utf8") as f: json.dump(js, f) return blobs_add_file(blobs, js_file, mtype) @@ -333,12 +333,12 @@ def create_oci_dir(inputs, output_dir, options, create_time): # index print("writing index") index_path = os.path.join(output_dir, "index.json") - with open(index_path, "w", encoding="utf-8") as f: + with open(index_path, "w", encoding="utf8") as f: json.dump(index, f) # oci-layout tag layout_path = os.path.join(output_dir, "oci-layout") - with open(layout_path, "w", encoding="utf-8") as f: + with open(layout_path, "w", encoding="utf8") as f: json.dump({"imageLayoutVersion": "1.0.0"}, f) diff --git a/stages/org.osbuild.oscap.remediation b/stages/org.osbuild.oscap.remediation index b68f3592..e54f2f30 100755 --- a/stages/org.osbuild.oscap.remediation +++ b/stages/org.osbuild.oscap.remediation @@ -131,7 +131,7 @@ def main(tree, options): cmd.append(datastream) - res = subprocess.run(cmd, encoding="utf-8", stdout=sys.stderr, check=False) + res = subprocess.run(cmd, encoding="utf8", stdout=sys.stderr, check=False) # oscap return values are: # 0 → success diff --git a/stages/org.osbuild.ostree b/stages/org.osbuild.ostree index 22edec80..33b0f34e 100755 --- a/stages/org.osbuild.ostree +++ b/stages/org.osbuild.ostree @@ -146,7 +146,7 @@ def ostree(*args, _input=None, **kwargs): args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()] print("ostree " + " ".join(args), file=sys.stderr) subprocess.run(["ostree"] + args, - encoding="utf-8", + encoding="utf8", stdout=sys.stderr, input=_input, check=True) @@ -177,7 +177,7 @@ def populate_var(sysroot): res = subprocess.run(["systemd-tmpfiles", "--create", "--boot", "--root=" + sysroot, "--prefix=/var/" + target], - encoding="utf-8", + encoding="utf8", stdout=sys.stderr, check=False) @@ -271,7 +271,7 @@ def main(tree, inputs, options): if not os.path.isfile(cfgfile): continue - with open(cfgfile, 'r') as f: + with open(cfgfile, 'r', encoding="utf8") as f: cfg = selinux.parse_config(f) se_policy = selinux.config_get_policy(cfg) diff --git a/stages/org.osbuild.ostree.commit b/stages/org.osbuild.ostree.commit index 722f1edc..cf527669 100755 --- a/stages/org.osbuild.ostree.commit +++ b/stages/org.osbuild.ostree.commit @@ -104,7 +104,7 @@ def main(inputs, output_dir, options, meta): stdout=sys.stderr, check=True) - with open(os.path.join(output_dir, "compose.json"), "r") as f: + with open(os.path.join(output_dir, "compose.json"), "r", encoding="utf8") as f: compose = json.load(f) api.metadata({"compose": compose}) diff --git a/stages/org.osbuild.ostree.config b/stages/org.osbuild.ostree.config index 4bd25c4f..c7b60532 100755 --- a/stages/org.osbuild.ostree.config +++ b/stages/org.osbuild.ostree.config @@ -56,7 +56,7 @@ def ostree(*args, _input=None, **kwargs): args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()] print("ostree " + " ".join(args), file=sys.stderr) subprocess.run(["ostree"] + args, - encoding="utf-8", + encoding="utf8", stdout=sys.stderr, input=_input, check=True) diff --git a/stages/org.osbuild.ostree.deploy b/stages/org.osbuild.ostree.deploy index b22020c3..2882568b 100755 --- a/stages/org.osbuild.ostree.deploy +++ b/stages/org.osbuild.ostree.deploy @@ -86,7 +86,7 @@ def ostree(*args, _input=None, **kwargs): args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()] print("ostree " + " ".join(args), file=sys.stderr) subprocess.run(["ostree"] + args, - encoding="utf-8", + encoding="utf8", stdout=sys.stderr, input=_input, check=True) diff --git a/stages/org.osbuild.ostree.fillvar b/stages/org.osbuild.ostree.fillvar index f12df4b2..c43d5324 100755 --- a/stages/org.osbuild.ostree.fillvar +++ b/stages/org.osbuild.ostree.fillvar @@ -57,7 +57,7 @@ def populate_var(sysroot): res = subprocess.run(["systemd-tmpfiles", "--create", "--boot", "--root=" + sysroot, "--prefix=/var/" + target], - encoding="utf-8", + encoding="utf8", stdout=sys.stderr, check=False) diff --git a/stages/org.osbuild.ostree.init-fs b/stages/org.osbuild.ostree.init-fs index 4e9b3383..502433d0 100755 --- a/stages/org.osbuild.ostree.init-fs +++ b/stages/org.osbuild.ostree.init-fs @@ -21,7 +21,7 @@ def ostree(*args, _input=None, **kwargs): args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()] print("ostree " + " ".join(args), file=sys.stderr) subprocess.run(["ostree"] + args, - encoding="utf-8", + encoding="utf8", stdout=sys.stderr, input=_input, check=True) diff --git a/stages/org.osbuild.ostree.os-init b/stages/org.osbuild.ostree.os-init index ffb34f3a..fd9f5c34 100755 --- a/stages/org.osbuild.ostree.os-init +++ b/stages/org.osbuild.ostree.os-init @@ -28,7 +28,7 @@ def ostree(*args, _input=None, **kwargs): args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()] print("ostree " + " ".join(args), file=sys.stderr) subprocess.run(["ostree"] + args, - encoding="utf-8", + encoding="utf8", stdout=sys.stderr, input=_input, check=True) diff --git a/stages/org.osbuild.ostree.passwd b/stages/org.osbuild.ostree.passwd index 8c6a19e6..0922df51 100755 --- a/stages/org.osbuild.ostree.passwd +++ b/stages/org.osbuild.ostree.passwd @@ -48,7 +48,7 @@ def ostree(*args, _input=None, **kwargs): args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()] print("ostree " + " ".join(args), file=sys.stderr) subprocess.run(["ostree"] + args, - encoding="utf-8", + encoding="utf8", stdout=sys.stderr, input=_input, check=True) diff --git a/stages/org.osbuild.ostree.pull b/stages/org.osbuild.ostree.pull index 3b910997..a65da126 100755 --- a/stages/org.osbuild.ostree.pull +++ b/stages/org.osbuild.ostree.pull @@ -54,7 +54,7 @@ def ostree(*args, _input=None, **kwargs): args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()] print("ostree " + " ".join(args), file=sys.stderr) subprocess.run(["ostree"] + args, - encoding="utf-8", + encoding="utf8", stdout=sys.stderr, input=_input, check=True) diff --git a/stages/org.osbuild.ostree.remotes b/stages/org.osbuild.ostree.remotes index 84cb5ba1..1bd22de6 100755 --- a/stages/org.osbuild.ostree.remotes +++ b/stages/org.osbuild.ostree.remotes @@ -71,7 +71,7 @@ def ostree(*args, _input=None, **kwargs): args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()] print("ostree " + " ".join(args), file=sys.stderr) subprocess.run(["ostree"] + args, - encoding="utf-8", + encoding="utf8", stdout=sys.stderr, input=_input, check=True) diff --git a/stages/org.osbuild.ostree.selinux b/stages/org.osbuild.ostree.selinux index e3427068..895867df 100755 --- a/stages/org.osbuild.ostree.selinux +++ b/stages/org.osbuild.ostree.selinux @@ -70,7 +70,7 @@ def main(tree, options): if not os.path.isfile(cfgfile): continue - with open(cfgfile, 'r') as f: + with open(cfgfile, 'r', encoding="utf8") as f: cfg = selinux.parse_config(f) se_policy = selinux.config_get_policy(cfg) diff --git a/stages/org.osbuild.pacman.conf b/stages/org.osbuild.pacman.conf index e0b28106..fa4f021d 100755 --- a/stages/org.osbuild.pacman.conf +++ b/stages/org.osbuild.pacman.conf @@ -75,7 +75,7 @@ LocalFileSigLevel = Optional os.makedirs(os.path.join(tree, "etc"), exist_ok=True) cfgpath = os.path.join(tree, "etc", "pacman.conf") - with open(cfgpath, "w", encoding="utf-8") as cfgfile: + with open(cfgpath, "w", encoding="utf8") as cfgfile: cfgfile.write(cfg) return 0 diff --git a/stages/org.osbuild.pacman.mirrorlist.conf b/stages/org.osbuild.pacman.mirrorlist.conf index 052d996c..95cb260c 100755 --- a/stages/org.osbuild.pacman.mirrorlist.conf +++ b/stages/org.osbuild.pacman.mirrorlist.conf @@ -35,7 +35,7 @@ def main(tree, options): os.makedirs(os.path.join(tree, *filepath.parts[:-1]), exist_ok=True) mirrorpath = os.path.join(tree, *filepath.parts) - with open(mirrorpath, "w", encoding="utf-8") as cfgfile: + with open(mirrorpath, "w", encoding="utf8") as cfgfile: cfgfile.write("\n".join(f"Server = {m}\n" for m in mirrors)) return 0 diff --git a/stages/org.osbuild.pam.limits.conf b/stages/org.osbuild.pam.limits.conf index cbb566d7..ec240533 100755 --- a/stages/org.osbuild.pam.limits.conf +++ b/stages/org.osbuild.pam.limits.conf @@ -103,7 +103,7 @@ def main(tree, options): cfg_line = f'{cfg_item["domain"]} {cfg_item["type"]} {cfg_item["item"]} {cfg_item["value"]}\n' cfg_lines.append(cfg_line) - with open(f"{limitsd_config_dir}/{filename}", "w") as f: + with open(f"{limitsd_config_dir}/{filename}", "w", encoding="utf8") as f: f.writelines(cfg_lines) return 0 diff --git a/stages/org.osbuild.parted b/stages/org.osbuild.parted index b01997bc..74f2728c 100755 --- a/stages/org.osbuild.parted +++ b/stages/org.osbuild.parted @@ -138,12 +138,12 @@ class PartitionTable: subprocess.run(["parted", "-a", "none", "-s", target, "--"] + commands, - encoding='utf-8', + encoding='utf8', check=True) subprocess.run(["parted", "-a", "none", "-s", target, "--", "print"], - encoding='utf-8', + encoding='utf8', check=True) diff --git a/stages/org.osbuild.pwquality.conf b/stages/org.osbuild.pwquality.conf index 27c435e0..a119a932 100755 --- a/stages/org.osbuild.pwquality.conf +++ b/stages/org.osbuild.pwquality.conf @@ -70,7 +70,7 @@ def main(tree, options): sys.stdout.write(f"{key} = {value}\n") continue sys.stdout.write(line) - with open(f"{tree}/etc/security/pwquality.conf", mode="a") as f: + with open(f"{tree}/etc/security/pwquality.conf", mode="a", encoding="utf8") as f: for key, value in changes.items(): f.write(f"{key} = {value}\n") diff --git a/stages/org.osbuild.resolv-conf b/stages/org.osbuild.resolv-conf index 01031de2..c902dfda 100755 --- a/stages/org.osbuild.resolv-conf +++ b/stages/org.osbuild.resolv-conf @@ -56,7 +56,7 @@ def main(tree, options): data += ["nameserver " + str(ns)] os.makedirs(os.path.join(tree, "etc"), exist_ok=True) - with open(fullpath, "w") as f: + with open(fullpath, "w", encoding="utf8") as f: f.write("\n".join(data) + "\n") return 0 diff --git a/stages/org.osbuild.rhsm b/stages/org.osbuild.rhsm index 7d191f75..95155be8 100755 --- a/stages/org.osbuild.rhsm +++ b/stages/org.osbuild.rhsm @@ -111,7 +111,7 @@ def configure_plugins(tree, path, plugins_options): plugin_conf = iniparse.SafeConfigParser() try: - with open(plugin_conf_path, "r") as f: + with open(plugin_conf_path, "r", encoding="utf8") as f: plugin_conf.readfp(f) except FileNotFoundError: print(f"Error: {plugin} configuration file '{plugin_conf_path}' does not exist.") @@ -129,7 +129,7 @@ def configure_plugins(tree, path, plugins_options): print(f"Error: unknown property {option} specified for {plugin} plugin.") return 1 - with open(plugin_conf_path, "w") as f: + with open(plugin_conf_path, "w", encoding="utf8") as f: plugin_conf.write(f) return 0 @@ -144,7 +144,7 @@ def configure_rhsm(tree, rhsm_configuration_options): rhsm_conf = iniparse.SafeConfigParser() try: - with open(rhsm_config_path, "r") as f: + with open(rhsm_config_path, "r", encoding="utf8") as f: rhsm_conf.readfp(f) except FileNotFoundError: print(f"Error: RHSM configuration file '{rhsm_config_path}' does not exist.") @@ -159,7 +159,7 @@ def configure_rhsm(tree, rhsm_configuration_options): value = str(value) rhsm_conf.set(config_section, option, value) - with open(rhsm_config_path, "w") as f: + with open(rhsm_config_path, "w", encoding="utf8") as f: rhsm_conf.write(f) return 0 diff --git a/stages/org.osbuild.rhsm.facts b/stages/org.osbuild.rhsm.facts index 9c177a24..4a6d1632 100755 --- a/stages/org.osbuild.rhsm.facts +++ b/stages/org.osbuild.rhsm.facts @@ -28,7 +28,7 @@ def main(tree, options): os.makedirs(path, exist_ok=True) - with open(file, "x", encoding="utf-8") as f: + with open(file, "x", encoding="utf8") as f: json.dump(options["facts"], f) os.makedirs(os.path.join(tree, "etc/rhsm/facts"), exist_ok=True) diff --git a/stages/org.osbuild.rpm b/stages/org.osbuild.rpm index 5b2de939..636a8972 100755 --- a/stages/org.osbuild.rpm +++ b/stages/org.osbuild.rpm @@ -204,7 +204,7 @@ def generate_package_metadata(tree, rpm_args): ] res = subprocess.run(cmd, stdout=subprocess.PIPE, - check=True, encoding="utf-8") + check=True, encoding="utf8") raw = res.stdout.strip() jsdata = '{"packages": [' + raw[:-1] + "]}" @@ -271,7 +271,7 @@ def create_machine_id_if_needed(tree): return False os.makedirs(f"{tree}/etc", exist_ok=True) - with open(path, "w", encoding="utf-8") as f: + with open(path, "w", encoding="utf8") as f: # create a fake machine ID to improve reproducibility f.write("ffffffffffffffffffffffffffffffff") os.fchmod(f.fileno(), 0o400) @@ -323,7 +323,7 @@ def main(tree, inputs, options): if options.get("ostree_booted", False): os.makedirs(f"{tree}/run", exist_ok=True) ostree_booted = f"{tree}/{OSTREE_BOOTED_MARKER}" - with open(ostree_booted, "w", encoding="utf-8") as f: + with open(ostree_booted, "w", encoding="utf8") as f: f.write("") extra_args = [] diff --git a/stages/org.osbuild.rpm.macros b/stages/org.osbuild.rpm.macros index 63df84fd..0573f590 100755 --- a/stages/org.osbuild.rpm.macros +++ b/stages/org.osbuild.rpm.macros @@ -57,7 +57,7 @@ def main(tree, options): path = os.path.join(tree, filename) os.makedirs(os.path.dirname(path), exist_ok=True) - with open(path, "w", encoding="utf-8") as f: + with open(path, "w", encoding="utf8") as f: for k, v in options["macros"].items(): value = make_value(k, v) line = f"%{k} {value}\n" diff --git a/stages/org.osbuild.selinux.config b/stages/org.osbuild.selinux.config index 113c39c5..f5637c77 100755 --- a/stages/org.osbuild.selinux.config +++ b/stages/org.osbuild.selinux.config @@ -39,7 +39,7 @@ def main(tree, options): selinux_type_key = "SELINUXTYPE" selinux_config_lines = [] - with open(f"{tree}{selinux_config_file}") as f: + with open(f"{tree}{selinux_config_file}", encoding="utf8") as f: selinux_config_lines = f.readlines() for idx, line in enumerate(selinux_config_lines): @@ -53,7 +53,7 @@ def main(tree, options): elif line_key == selinux_type_key and policy_type: selinux_config_lines[idx] = f"{selinux_type_key}={policy_type}\n" - with open(f"{tree}{selinux_config_file}", "w") as f: + with open(f"{tree}{selinux_config_file}", "w", encoding="utf8") as f: f.writelines(selinux_config_lines) return 0 diff --git a/stages/org.osbuild.sfdisk b/stages/org.osbuild.sfdisk index d3a2c664..1787406d 100755 --- a/stages/org.osbuild.sfdisk +++ b/stages/org.osbuild.sfdisk @@ -165,7 +165,7 @@ class PartitionTable: subprocess.run(["sfdisk", "-q", "--no-tell-kernel", target], input=command, - encoding='utf-8', + encoding='utf8', check=True) if sync: @@ -175,7 +175,7 @@ class PartitionTable: """Update and fill in missing information from disk""" r = subprocess.run(["sfdisk", "--json", target], stdout=subprocess.PIPE, - encoding='utf-8', + encoding='utf8', check=True) disk_table = json.loads(r.stdout)["partitiontable"] disk_parts = disk_table["partitions"] @@ -214,7 +214,7 @@ def main(devices, options): pt.write_to(device) subprocess.run(["sfdisk", "--json", device], - encoding='utf-8', + encoding='utf8', check=False) diff --git a/stages/org.osbuild.sgdisk b/stages/org.osbuild.sgdisk index 3875d957..21a8f20c 100755 --- a/stages/org.osbuild.sgdisk +++ b/stages/org.osbuild.sgdisk @@ -162,7 +162,7 @@ class PartitionTable: command += cmd subprocess.run(command, - encoding='utf-8', + encoding='utf8', check=True) @@ -189,7 +189,7 @@ def main(devices, options): pt.write_to(device) subprocess.run(["sgdisk", "-p", device], - encoding='utf-8', + encoding='utf8', check=False) diff --git a/stages/org.osbuild.sshd.config b/stages/org.osbuild.sshd.config index e357d053..b54ee642 100755 --- a/stages/org.osbuild.sshd.config +++ b/stages/org.osbuild.sshd.config @@ -101,7 +101,7 @@ def main(tree, options): sys.stdout.write(f"{key} {entry['value']}\n") continue sys.stdout.write(line) - with open(f"{tree}/etc/ssh/sshd_config", mode="a") as f: + with open(f"{tree}/etc/ssh/sshd_config", mode="a", encoding="utf8") as f: for entry in changes.values(): f.write(f"{entry['key']} {entry['value']}\n") diff --git a/stages/org.osbuild.sysconfig b/stages/org.osbuild.sysconfig index 185fd9e1..73451b50 100755 --- a/stages/org.osbuild.sysconfig +++ b/stages/org.osbuild.sysconfig @@ -168,7 +168,7 @@ def configure_kernel(tree, kernel_options): if not kernel_options: return - with open(f"{tree}/etc/sysconfig/kernel", 'w') as kernel_file: + with open(f"{tree}/etc/sysconfig/kernel", 'w', encoding="utf8") as kernel_file: for option, value in kernel_options.items(): if option == "update_default": kernel_file.write(f"UPDATEDEFAULT={bool_to_string(value)}\n") @@ -183,7 +183,7 @@ def configure_network(tree, network_options): if not network_options: return - with open(f"{tree}/etc/sysconfig/network", 'w') as network_file: + with open(f"{tree}/etc/sysconfig/network", 'w', encoding="utf8") as network_file: for option, value in network_options.items(): if option == "networking": network_file.write(f"NETWORKING={bool_to_string(value)}\n") @@ -230,7 +230,7 @@ def configure_network_scripts_ifcfg(tree, network_scripts_ifcfg_options): "config.") if lines: - with open(f"{tree}/etc/sysconfig/network-scripts/ifcfg-{ifname}", 'w') as ifcfg_file: + with open(f"{tree}/etc/sysconfig/network-scripts/ifcfg-{ifname}", 'w', encoding="utf8") as ifcfg_file: ifcfg_file.writelines(lines) diff --git a/stages/org.osbuild.sysctld b/stages/org.osbuild.sysctld index 32d64632..4282207c 100755 --- a/stages/org.osbuild.sysctld +++ b/stages/org.osbuild.sysctld @@ -94,7 +94,7 @@ def main(tree, options): cfg_line = f"{key} = {value}\n" if value else f"{key}\n" cfg_lines.append(cfg_line) - with open(f"{sysctld_config_dir}/{filename}", "w") as f: + with open(f"{sysctld_config_dir}/{filename}", "w", encoding="utf8") as f: f.writelines(cfg_lines) return 0 diff --git a/stages/org.osbuild.systemd-logind b/stages/org.osbuild.systemd-logind index 2ccd5fa3..84a8df7e 100755 --- a/stages/org.osbuild.systemd-logind +++ b/stages/org.osbuild.systemd-logind @@ -73,7 +73,7 @@ def main(tree, options): for option, value in opts.items(): config.set(section, option, str(value)) - with open(f"{dropins_dir}/{dropin_file}", "w") as f: + with open(f"{dropins_dir}/{dropin_file}", "w", encoding="utf8") as f: config.write(f, space_around_delimiters=False) return 0 diff --git a/stages/org.osbuild.systemd.unit b/stages/org.osbuild.systemd.unit index b7ff8b16..690643b6 100755 --- a/stages/org.osbuild.systemd.unit +++ b/stages/org.osbuild.systemd.unit @@ -79,7 +79,7 @@ def main(tree, options): for option, value in opts.items(): config.set(section, option, str(value)) - with open(f"{unit_dropins_dir}/{dropin_file}", "w") as f: + with open(f"{unit_dropins_dir}/{dropin_file}", "w", encoding="utf8") as f: config.write(f, space_around_delimiters=False) return 0 diff --git a/stages/org.osbuild.test b/stages/org.osbuild.test index 32ee006f..6c4719fb 100755 --- a/stages/org.osbuild.test +++ b/stages/org.osbuild.test @@ -42,7 +42,7 @@ StandardOutput=file:/dev/vport0p1 ExecStart={script} ExecStopPost=/usr/bin/systemctl poweroff """ - with open(f"{tree}/etc/systemd/system/osbuild-test.service", "w") as f: + with open(f"{tree}/etc/systemd/system/osbuild-test.service", "w", encoding="utf8") as f: f.write(unit) os.symlink("../osbuild-test.service", diff --git a/stages/org.osbuild.tmpfilesd b/stages/org.osbuild.tmpfilesd index 36288f51..53db3c84 100755 --- a/stages/org.osbuild.tmpfilesd +++ b/stages/org.osbuild.tmpfilesd @@ -109,7 +109,7 @@ def main(tree, options): cfg_line += "\n" cfg_lines.append(cfg_line) - with open(f"{tmpfilesd_config_dir}/{filename}", "w") as f: + with open(f"{tmpfilesd_config_dir}/{filename}", "w", encoding="utf8") as f: f.writelines(cfg_lines) return 0 diff --git a/stages/org.osbuild.tuned b/stages/org.osbuild.tuned index 0bfb2d2c..371d17c8 100755 --- a/stages/org.osbuild.tuned +++ b/stages/org.osbuild.tuned @@ -90,11 +90,11 @@ def main(tree, options): raise ValueError(f"TuneD profile '{profile}' does not exist") # Set the active profile - with open(f"{tree}{active_profile_file}", "w") as f: + with open(f"{tree}{active_profile_file}", "w", encoding="utf8") as f: f.write(" ".join(profiles) + "\n") # Mode needs to be set to "manual" if set explicitly - with open(f"{tree}{profile_mode_file}", "w") as f: + with open(f"{tree}{profile_mode_file}", "w", encoding="utf8") as f: f.write("manual\n") return 0 diff --git a/stages/org.osbuild.udev.rules b/stages/org.osbuild.udev.rules index eb57c4e1..4fec2841 100755 --- a/stages/org.osbuild.udev.rules +++ b/stages/org.osbuild.udev.rules @@ -304,7 +304,7 @@ def main(tree, options): rules = options["rules"] path = os.path.join(tree, filename.lstrip("/")) - with open(path, "w", encoding="utf-8") as f: + with open(path, "w", encoding="utf8") as f: for rule in rules: if isinstance(rule, dict): comment = rule.get("comment") diff --git a/stages/org.osbuild.users b/stages/org.osbuild.users index 364564b6..2929ece3 100755 --- a/stages/org.osbuild.users +++ b/stages/org.osbuild.users @@ -74,7 +74,7 @@ SCHEMA = """ def getpwnam(root, name): """Similar to pwd.getpwnam, but takes a @root parameter""" - with open(f"{root}/etc/passwd") as f: + with open(f"{root}/etc/passwd", encoding="utf8") as f: for line in f: passwd = line.split(":") if passwd[0] == name: @@ -131,7 +131,7 @@ def add_ssh_key(root, user, key): os.mkdir(ssh_dir, 0o700) os.chown(ssh_dir, int(uid), int(gid)) - with open(authorized_keys, "a") as f: + with open(authorized_keys, "a", encoding="utf8") as f: f.write(f"{key}\n") os.chown(authorized_keys, int(uid), int(gid)) diff --git a/stages/org.osbuild.vagrant b/stages/org.osbuild.vagrant index 42727c16..77201f4a 100755 --- a/stages/org.osbuild.vagrant +++ b/stages/org.osbuild.vagrant @@ -79,8 +79,8 @@ Vagrant.configure("2") do |config| end end """ - open(f"{tree}/Vagrantfile", "w").write(vagrantfile) - with open(f"{tree}/metadata.json", "w") as fp: + open(f"{tree}/Vagrantfile", "w", encoding="utf8").write(vagrantfile) + with open(f"{tree}/metadata.json", "w", encoding="utf8") as fp: json.dump(metadata, fp) diff --git a/stages/org.osbuild.waagent.conf b/stages/org.osbuild.waagent.conf index 54ee96c4..ddc17e19 100755 --- a/stages/org.osbuild.waagent.conf +++ b/stages/org.osbuild.waagent.conf @@ -73,7 +73,7 @@ def main(tree, options): sys.stdout.write(f"{key}={entry['value']}\n") continue sys.stdout.write(line) - with open(f"{tree}/etc/waagent.conf", mode="a") as f: + with open(f"{tree}/etc/waagent.conf", mode="a", encoding="utf8") as f: for entry in changes.values(): f.write(f"{entry['key']}={entry['value']}\n") diff --git a/stages/org.osbuild.xz b/stages/org.osbuild.xz index e4643fd6..a1c1144e 100755 --- a/stages/org.osbuild.xz +++ b/stages/org.osbuild.xz @@ -53,7 +53,7 @@ def main(inputs, output, options): source = parse_input(inputs) target = os.path.join(output, filename) - with open(target, "w") as f: + with open(target, "w", encoding="utf8") as f: env = { "XZ_OPT": "--threads 0" diff --git a/stages/org.osbuild.yum.config b/stages/org.osbuild.yum.config index fa929aee..8c3ade3b 100755 --- a/stages/org.osbuild.yum.config +++ b/stages/org.osbuild.yum.config @@ -62,7 +62,7 @@ def configure_plugins(tree, plugins_options): plugin_conf = iniparse.SafeConfigParser() try: - with open(plugin_conf_path, "r") as f: + with open(plugin_conf_path, "r", encoding="utf8") as f: plugin_conf.readfp(f) except FileNotFoundError: print(f"Warning: {plugin} configuration file '{plugin_conf_path}' does not exist, will create it.") @@ -83,7 +83,7 @@ def configure_plugins(tree, plugins_options): print(f"Error: unknown property {option} specified for {plugin} plugin.") return 1 - with open(plugin_conf_path, "w") as f: + with open(plugin_conf_path, "w", encoding="utf8") as f: plugin_conf.write(f) return 0 @@ -98,7 +98,7 @@ def main(tree, options): if config_options: try: - with open(yum_config_path, "r") as f: + with open(yum_config_path, "r", encoding="utf8") as f: yum_config.readfp(f) except FileNotFoundError: print(f"Warning: YUM configuration file '{yum_config_path}' does not exist, will create it.") @@ -110,7 +110,7 @@ def main(tree, options): for option, value in config_options.items(): yum_config.set("main", option, value) - with open(yum_config_path, "w") as f: + with open(yum_config_path, "w", encoding="utf8") as f: yum_config.write(f) if configure_plugins(tree, plugins_options): diff --git a/stages/org.osbuild.yum.repos b/stages/org.osbuild.yum.repos index 14eca48c..1c50571b 100755 --- a/stages/org.osbuild.yum.repos +++ b/stages/org.osbuild.yum.repos @@ -181,7 +181,7 @@ def main(tree, options): parser.set(repo_id, key, option_value_to_str(value)) # ensure that we won't overwrite an existing file - with open(f"{yum_repos_dir}/{filename}", "x") as f: + with open(f"{yum_repos_dir}/{filename}", "x", encoding="utf8") as f: parser.write(f, space_around_delimiters=False) return 0 diff --git a/stages/org.osbuild.zipl b/stages/org.osbuild.zipl index 3e8dd748..32fde5dd 100755 --- a/stages/org.osbuild.zipl +++ b/stages/org.osbuild.zipl @@ -34,7 +34,7 @@ def main(tree, options): new_zipl_conf = "\n".join(config) + "\n" os.makedirs(f"{tree}/etc", exist_ok=True) - with open(f"{tree}/etc/zipl.conf", "w") as f: + with open(f"{tree}/etc/zipl.conf", "w", encoding="utf8") as f: f.write(new_zipl_conf) return 0 diff --git a/stages/org.osbuild.zipl.inst b/stages/org.osbuild.zipl.inst index f5c9721d..3291a288 100755 --- a/stages/org.osbuild.zipl.inst +++ b/stages/org.osbuild.zipl.inst @@ -55,7 +55,7 @@ SCHEMA_2 = r""" def parse_blsfile(blsfile): params = {} - with open(blsfile, "r") as bls: + with open(blsfile, "r", encoding="utf8") as bls: for line in bls: key, value = line.split(' ', 1) params[key] = value.strip()