Added mimic function for file operations
This commit is contained in:
parent
0c1139ffaf
commit
97a91aab60
|
|
@ -1,4 +1,5 @@
|
||||||
import time
|
import time
|
||||||
|
from typing import Union
|
||||||
from .disk import *
|
from .disk import *
|
||||||
from .hardware import *
|
from .hardware import *
|
||||||
from .locale_helpers import verify_keyboard_layout, verify_x11_keyboard_layout
|
from .locale_helpers import verify_keyboard_layout, verify_x11_keyboard_layout
|
||||||
|
|
@ -15,17 +16,30 @@ __packages__ = ["base", "base-devel", "linux-firmware", "linux", "linux-lts", "l
|
||||||
|
|
||||||
|
|
||||||
class InstallationFile:
|
class InstallationFile:
|
||||||
def __init__(self, installation, filename, owner):
|
def __init__(self, installation, filename, owner, mode="w"):
|
||||||
self.installation = installation
|
self.installation = installation
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
|
self.mode = mode
|
||||||
|
self.fh = None
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
self.fh = open(self.filename, self.mode)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self):
|
def __exit__(self, *args):
|
||||||
|
self.fh.close()
|
||||||
self.installation.chown(self.owner, self.filename)
|
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:
|
class Installer:
|
||||||
"""
|
"""
|
||||||
`Installer()` is the wrapper for most basic installation steps.
|
`Installer()` is the wrapper for most basic installation steps.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue