Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-11-06 09:50:12 +0000
committerGitHub <noreply@github.com>2021-11-06 09:50:12 +0000
commitd363bad27c047cbefd60c1b93181067df74c6188 (patch)
tree7c86893ab3776a6806241a74a75052e448c6cad3 /archinstall/lib
parent17fe62c641607cc460e6c6590192ad8de0a21b1a (diff)
parent129326b93fc58a00d15ed89fe4e701d07b0385bf (diff)
Merged #679 - Fix #109 Wrapper to create files inside installation
Added a wrapper to create files inside the installation
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/installer.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
index b400e741..c2c30f7c 100644
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -1,4 +1,5 @@
import time
+from typing import Union
import logging
import os
import shutil
@@ -24,6 +25,31 @@ from .exceptions import DiskError, ServiceException, RequirementError, HardwareI
__packages__ = ["base", "base-devel", "linux-firmware", "linux", "linux-lts", "linux-zen", "linux-hardened"]
+class InstallationFile:
+ 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, *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:
"""
`Installer()` is the wrapper for most basic installation steps.
@@ -658,6 +684,12 @@ class Installer:
SysCommand(f"/usr/bin/arch-chroot {self.target} sh -c \"chsh -s {shell} {user}\"")
+ 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):