mirror of https://github.com/nucypher/nucypher.git
Merge pull request #2681 from ghostmonk/proper-cleanup-demo-ursula-db-2232
Cleaned up each DB on shutdown, and removed reactor.run to give user console controlpull/2696/head^2
commit
f04d564a1c
|
@ -16,11 +16,12 @@
|
|||
"""
|
||||
|
||||
import os
|
||||
from contextlib import suppress
|
||||
import shutil
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
|
||||
from twisted.internet import reactor
|
||||
from contextlib import suppress
|
||||
|
||||
from nucypher.characters.lawful import Ursula
|
||||
from nucypher.config.constants import APP_DIR, TEMPORARY_DOMAIN
|
||||
|
@ -28,6 +29,7 @@ from nucypher.utilities.networking import LOOPBACK_ADDRESS
|
|||
|
||||
FLEET_POPULATION = 12
|
||||
DEMO_NODE_STARTING_PORT = 11500
|
||||
USER_CACHE = Path(APP_DIR.user_cache_dir)
|
||||
|
||||
ursula_maker = partial(Ursula, rest_host=LOOPBACK_ADDRESS,
|
||||
federated_only=True,
|
||||
|
@ -38,7 +40,7 @@ def spin_up_federated_ursulas(quantity: int = FLEET_POPULATION):
|
|||
# Ports
|
||||
starting_port = DEMO_NODE_STARTING_PORT
|
||||
ports = list(map(str, range(starting_port, starting_port + quantity)))
|
||||
sage_dir = str(Path(APP_DIR.user_cache_dir) / 'sage.db')
|
||||
sage_dir = str(USER_CACHE / 'sage.db')
|
||||
ursulas = []
|
||||
|
||||
if not os.path.exists(sage_dir):
|
||||
|
@ -52,23 +54,23 @@ def spin_up_federated_ursulas(quantity: int = FLEET_POPULATION):
|
|||
rest_port=port,
|
||||
seed_nodes=[sage.seed_node_metadata()],
|
||||
start_learning_now=True,
|
||||
db_filepath=f"{Path(APP_DIR.user_cache_dir) / port}.db",
|
||||
db_filepath=f"{USER_CACHE / port}.db",
|
||||
)
|
||||
ursulas.append(u)
|
||||
|
||||
for u in ursulas:
|
||||
deployer = u.get_deployer()
|
||||
deployer.addServices()
|
||||
deployer.catalogServers(deployer.hendrix)
|
||||
deployer.start()
|
||||
print(f"{u}: {deployer._listening_message()}")
|
||||
|
||||
try:
|
||||
reactor.run() # GO!
|
||||
reactor.run()
|
||||
finally:
|
||||
with suppress(FileNotFoundError):
|
||||
os.remove("sage.db")
|
||||
for u in ursulas[1:]:
|
||||
for u in ursulas:
|
||||
with suppress(FileNotFoundError):
|
||||
os.remove(f"{u.rest_interface.port}.db")
|
||||
shutil.rmtree(u.datastore.db_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
examples/run_demo_ursula_fleet.py - Clean up each DB on shutdown.
|
Loading…
Reference in New Issue