-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update and modify files for the project
- Loading branch information
1 parent
6044a4c
commit be1a6c6
Showing
9 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3 |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"BEE_POSTAGE": "061dfc1fc656410f1901e06f5b413039a6923e2747ca7d8cfe23391cd7b86c20", | ||
"BEE_PEER_POSTAGE": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"private_key": "634fb5a872396d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd", | ||
"public_key": "03c32bb011339667a487b6c1c35061f15f7edc36aa9a0f8648aba07a4b8bd741b4", | ||
"address": "8d3766440f0d7b949a5e32995d09619a7f86e632" | ||
} |