diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-05-23 23:45:12 -0400 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-05-23 23:45:12 -0400 |
commit | f53768612b1e2268697b5444e502032ef9f3fb3c (patch) | |
tree | 4ed49b73e6bd3c2f8fceffa9643973033f87af95 /extension/examples/filesystem/real.py | |
download | sncontinue-f53768612b1e2268697b5444e502032ef9f3fb3c.tar.gz sncontinue-f53768612b1e2268697b5444e502032ef9f3fb3c.tar.bz2 sncontinue-f53768612b1e2268697b5444e502032ef9f3fb3c.zip |
copying from old repo
Diffstat (limited to 'extension/examples/filesystem/real.py')
-rw-r--r-- | extension/examples/filesystem/real.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/extension/examples/filesystem/real.py b/extension/examples/filesystem/real.py new file mode 100644 index 00000000..ec7aa693 --- /dev/null +++ b/extension/examples/filesystem/real.py @@ -0,0 +1,34 @@ +import os +from typing import List +from filesystem.filesystem import FileSystem + + +class RealFileSystem(FileSystem): + """A filesystem that reads/writes from the actual filesystem.""" + + def read(self, path) -> str: + with open(path, "r") as f: + return f.read() + + def readlines(self, path) -> List[str]: + with open(path, "r") as f: + return f.readlines() + + def write(self, path, content): + with open(path, "w") as f: + f.write(content) + + def exists(self, path) -> bool: + return os.path.exists(path) + + def rename_file(self, filepath: str, new_filepath: str): + os.rename(filepath, new_filepath) + + def rename_directory(self, path: str, new_path: str): + os.rename(path, new_path) + + def delete_file(self, filepath: str): + os.remove(filepath) + + def add_directory(self, path: str): + os.makedirs(path) |