-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb1f335
commit e180369
Showing
15 changed files
with
647 additions
and
411 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
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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import pymongo | ||
|
||
|
||
def connect_to_mongodb(config, network_id): | ||
""" | ||
|
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,71 @@ | ||
import os | ||
import uuid | ||
|
||
class LocalFileSystemModelRepository: | ||
def __init__(self, directory='./fedn-files'): | ||
self.directory = directory | ||
if not os.path.exists(directory): | ||
os.makedirs(directory) | ||
|
||
def get_model_path(self, model_id): | ||
return os.path.join(self.directory, model_id) | ||
|
||
def get_model(self, model_id): | ||
model_path = self.get_model_path(model_id) | ||
if os.path.exists(model_path): | ||
with open(model_path, 'rb') as file: | ||
return file.read() | ||
else: | ||
raise FileNotFoundError(f"Model with ID {model_id} not found.") | ||
|
||
def get_model_stream(self, model_id): | ||
model_path = self.get_model_path(model_id) | ||
if os.path.exists(model_path): | ||
return open(model_path, 'rb') | ||
else: | ||
raise FileNotFoundError(f"Model with ID {model_id} not found.") | ||
|
||
def set_model(self, model, is_file=True): | ||
model_id = str(uuid.uuid4()) | ||
model_path = self.get_model_path(model_id) | ||
|
||
if is_file: | ||
# If model is a file path, copy the file content. | ||
with open(model, 'rb') as src, open(model_path, 'wb') as dst: | ||
dst.write(src.read()) | ||
else: | ||
# If model is a binary content, write it directly. | ||
with open(model_path, 'wb') as file: | ||
file.write(model) | ||
|
||
return model_id | ||
|
||
# Methods for compute_package can be similarly implemented | ||
def set_compute_package(self, name, compute_package, is_file=True): | ||
package_path = self.get_model_path(name) | ||
if is_file: | ||
print("MMMMMMMMMMMMMMMMMMM") | ||
print(package_path) | ||
print(compute_package) | ||
with open(compute_package, 'rb') as src, open(package_path, 'wb') as dst: | ||
dst.write(src.read()) | ||
else: | ||
with open(package_path, 'wb') as file: | ||
file.write(compute_package) | ||
|
||
def get_compute_package(self, compute_package): | ||
print("GETTING COMPUTE PACKAGE") | ||
package_path = self.get_model_path(compute_package) | ||
print(package_path) | ||
if os.path.exists(package_path): | ||
with open(package_path, 'rb') as file: | ||
return file.read() | ||
else: | ||
raise FileNotFoundError(f"Compute package {compute_package} not found.") | ||
|
||
def delete_compute_package(self, compute_package): | ||
package_path = self.get_model_path(compute_package) | ||
if os.path.exists(package_path): | ||
os.remove(package_path) | ||
else: | ||
raise FileNotFoundError(f"Compute package {compute_package} not found.") |
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
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
Oops, something went wrong.