Skip to content

Commit

Permalink
Update and modify files for the project
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviksaikat committed Nov 28, 2023
1 parent 6044a4c commit be1a6c6
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/bee_py/utils/collection_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pathlib import Path
from typing import Union

from bee_py.types.type import Collection, CollectionEntry


def make_collection_from_fs(directory: Union[str, Path]) -> Collection:
if isinstance(directory, str):
directory = Path(directory)
if not isinstance(directory, Path):
msg = "directory has to be a string or a Path object!"
raise TypeError(msg)
if directory.name == "":
msg = "Directory must not be empty!"
raise TypeError(msg)

return build_collection_relative(directory, Path(""))


def build_collection_relative(directory: Path, relative_path: Path) -> Collection:
dirname = directory / relative_path
collection = Collection(entries=[])

for entry in dirname.iterdir():
full_path = directory / relative_path / entry.name
entry_path = relative_path / entry.name

if entry.is_file():
with open(full_path, "rb") as f:
data = f.read()
collection.entries.append(CollectionEntry(path=str(entry_path), data=data))
elif entry.is_dir():
collection.entries += build_collection_relative(directory, entry_path).entries

return collection
1 change: 1 addition & 0 deletions tests/data/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions tests/data/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
Empty file added tests/data/empty
Empty file.
1 change: 1 addition & 0 deletions tests/data/sub/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Empty file added tests/data/sub/é
Empty file.
Empty file added tests/data/sub/😎
Empty file.
4 changes: 4 additions & 0 deletions tests/test_files/bee_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"BEE_POSTAGE": "061dfc1fc656410f1901e06f5b413039a6923e2747ca7d8cfe23391cd7b86c20",
"BEE_PEER_POSTAGE": ""
}
5 changes: 5 additions & 0 deletions tests/test_files/test_account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"private_key": "634fb5a872396d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd",
"public_key": "03c32bb011339667a487b6c1c35061f15f7edc36aa9a0f8648aba07a4b8bd741b4",
"address": "8d3766440f0d7b949a5e32995d09619a7f86e632"
}

0 comments on commit be1a6c6

Please sign in to comment.