Skip to content

Commit

Permalink
Add open_file method environment
Browse files Browse the repository at this point in the history
  • Loading branch information
twizmwazin committed Oct 10, 2023
1 parent eb1cc29 commit a323e1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion binharness/localenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
9 changes: 7 additions & 2 deletions binharness/types/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit a323e1d

Please sign in to comment.