Merged #679 - Fix #109 Wrapper to create files inside installation

Added a wrapper to create files inside the installation
This commit is contained in:
Anton Hvornum 2021-11-06 09:50:12 +00:00 committed by GitHub
commit d363bad27c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 0 deletions

View File

@ -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):