diff --git a/binharness/localenvironment.py b/binharness/localenvironment.py index d95864f..af197de 100644 --- a/binharness/localenvironment.py +++ b/binharness/localenvironment.py @@ -5,7 +5,7 @@ import subprocess import tempfile from pathlib import Path -from typing import TYPE_CHECKING, Sequence +from typing import TYPE_CHECKING, AnyStr, Sequence from binharness.types.environment import Environment from binharness.types.process import Process @@ -66,6 +66,10 @@ def get_tempdir(self: LocalEnvironment) -> Path: """Get a Path for a temporary directory.""" return Path(tempfile.gettempdir()) + def open_file(self: Environment, path: Path, mode: str) -> IO[AnyStr]: + """Open a file in the environment. Follows the same semantics as `open`.""" + return Path.open(path, mode) + class LocalProcess(Process): """A process running in a local environment.""" diff --git a/binharness/types/environment.py b/binharness/types/environment.py index 9208c84..4c9f12e 100644 --- a/binharness/types/environment.py +++ b/binharness/types/environment.py @@ -2,12 +2,12 @@ from __future__ import annotations from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, Sequence +from typing import TYPE_CHECKING, AnyStr, Sequence if TYPE_CHECKING: from pathlib import Path - from binharness import BusyboxInjection, Process + from binharness import IO, BusyboxInjection, Process class BusyboxInjectionNotInstalledError(Exception): @@ -86,3 +86,8 @@ def retrieve_files( def get_tempdir(self: Environment) -> Path: """Get a Path for a temporary directory.""" raise NotImplementedError + + @abstractmethod + def open_file(self: Environment, path: Path, mode: str) -> IO[AnyStr]: + """Open a file in the environment. Follows the same semantics as `open`.""" + raise NotImplementedError