From 0d691fc487e561de93033d4e537f42a4e4c91a13 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 1 Nov 2021 10:42:04 +0000 Subject: Added a wrapper to create files inside the installation as/for a specified used --- archinstall/lib/installer.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'archinstall') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 0bdddb2e..bf892826 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -14,6 +14,18 @@ from .exceptions import DiskError, ServiceException __packages__ = ["base", "base-devel", "linux-firmware", "linux", "linux-lts", "linux-zen", "linux-hardened"] +class InstallationFile: + def __init__(self, installation, filename, owner): + self.installation = installation + self.filename = filename + self.owner = owner + + def __enter__(self): + return self + + def __exit__(self): + self.installation.chown(owner, self.filename) + class Installer: """ `Installer()` is the wrapper for most basic installation steps. @@ -623,6 +635,12 @@ class Installer: o = b''.join(SysCommand(f"/usr/bin/arch-chroot {self.target} sh -c \"chsh -s {shell} {user}\"")) pass + def chown(self, owner, path, options=[]): + return SysCommand(f"/usr/bin/arch-chroot {self.target} sh -c 'chown {' '.join(options)} {owner} {path}") + + def create_file(self, filename, owner=None): + return InstallationFile(self, filename, owner) + def set_keyboard_language(self, language: str) -> bool: if len(language.strip()): if not verify_keyboard_layout(language): -- cgit v1.2.3-70-g09d2 From 0c1139ffaf5f62b3f927d90e3371e3fa6e0c5134 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sat, 6 Nov 2021 09:42:54 +0100 Subject: Update installer.py --- archinstall/lib/installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index bf892826..aa26abf3 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -24,7 +24,7 @@ class InstallationFile: return self def __exit__(self): - self.installation.chown(owner, self.filename) + self.installation.chown(self.owner, self.filename) class Installer: """ -- cgit v1.2.3-70-g09d2 From 97a91aab6019d6efb500de1240bc58b4165ab02d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sat, 6 Nov 2021 09:48:42 +0100 Subject: Added mimic function for file operations --- archinstall/lib/installer.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index aa26abf3..9cff1f7a 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1,4 +1,5 @@ import time +from typing import Union from .disk import * from .hardware import * from .locale_helpers import verify_keyboard_layout, verify_x11_keyboard_layout @@ -15,16 +16,29 @@ __packages__ = ["base", "base-devel", "linux-firmware", "linux", "linux-lts", "l class InstallationFile: - def __init__(self, installation, filename, owner): + def __init__(self, installation, filename, owner, mode="w"): self.installation = installation self.filename = filename self.owner = owner + self.mode = mode + self.fh = None def __enter__(self): + self.fh = open(self.filename, self.mode) return self - def __exit__(self): + def __exit__(self, *args): + self.fh.close() self.installation.chown(self.owner, self.filename) + + def write(self, data :Union[str, bytes]): + return self.fh.write(data) + + def read(self, *args): + return self.fh.read(*args) + + def poll(self, *args): + return self.fh.poll(*args) class Installer: """ -- cgit v1.2.3-70-g09d2