Skip to content

Commit efb624c

Browse files
committed
readded init command, added help for wipe-config command, added block param to network and node start/stop, dropped logs sent to a .txt file, not an ndjson file, version bump -> 1.3.0-beta.8
1 parent 5f8e661 commit efb624c

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "koi-net"
3-
version = "1.3.0-beta.7"
3+
version = "1.3.0-beta.8"
44
description = "Implementation of KOI-net protocol in Python"
55
authors = [
66
{name = "Luke Miller", email = "luke@block.science"}

src/koi_net/interface/network.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ def wipe_logs(self):
154154
for node in self.nodes:
155155
if node.exists():
156156
node.wipe_logs()
157+
158+
def wipe_config(self):
159+
for node in self.nodes:
160+
if node.exists():
161+
node.wipe_config()
157162

158163
def run(self):
159164
try:
@@ -170,15 +175,15 @@ def run(self):
170175
finally:
171176
self.stop()
172177

173-
def start(self):
178+
def start(self, block: bool = True):
174179
for name in self.config.nodes:
175180
node = self.resolve_node(name)
176181
if node.state() == NodeState.IDLE:
177-
node.start()
182+
node.start(block=block)
178183

179-
def stop(self):
184+
def stop(self, block: bool = True):
180185
for name in reversed(self.config.nodes):
181186
node = self.resolve_node(name)
182187
if node.state() == NodeState.RUNNING:
183-
node.stop()
188+
node.stop(block=block)
184189

src/koi_net/interface/node.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def create(self):
6363
if self.initialized:
6464
self.console.print(f"Created node '{self.node.identity.rid}'")
6565
else:
66+
# self.console.print("Failed to initialize, run `node init <name>` to try again")
6667
self.delete()
6768

6869
def exists(self):
@@ -132,18 +133,18 @@ def run(self):
132133
finally:
133134
self.stop()
134135

135-
def start(self):
136+
def start(self, block: bool = True):
136137
if self.state() == NodeState.IDLE:
137138
print(f"Starting {self.name}...", end=" ", flush=True)
138-
self.node.start()
139+
self.node.start(block=block)
139140
print("Done")
140141
else:
141142
print("Node already started")
142143

143-
def stop(self):
144+
def stop(self, block: bool = True):
144145
if self.state() == NodeState.RUNNING:
145146
print(f"Stopping {self.name}...", end=" ", flush=True)
146-
self.node.stop()
147+
self.node.stop(block=block)
147148
print("Done")
148149
else:
149150
print("Node already stopped")

src/koi_net/interface/shell.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def do_help(self, subcmd: str):
7878
cmd_help = [
7979
("add", r"<module ref> \[name]", "adds a new node of type <module ref> to the network, if unset, name defaults to <module ref>"),
8080
("rm", "<name>", "removes a node from the network"),
81-
# ("init", "<name>", "initializes a node"),
81+
("init", "<name>", "initializes a node"),
82+
("wipe-config", "", "wipes a node's configuration, including private key"),
8283
("wipe-cache", "<name>", "wipes a node's RID cache"),
8384
("wipe-logs", "<name>", "wipes a node's logs"),
8485

@@ -91,12 +92,12 @@ def do_help(self, subcmd: str):
9192
("start", "<name>", "starts a node in the background"),
9293
("stop", "<name>", "stops a running background node"),
9394

94-
("list", "", "lists all nodes in the network"),
95-
("modules", "", "lists all available node modules and their aliases"),
95+
("list", "", "lists all nodes in the network")
9696
]
9797
case "network":
9898
cmd_help = [
9999
("sync", "", "synchronizes the local environment with the network configuration"),
100+
("wipe-config", "", "wipes configuration, including private key, of all network nodes"),
100101
("wipe-cache", "", "wipes RID cache of all network nodes"),
101102
("wipe-logs", "", "wipes logs of all network nodes"),
102103
("status", "", "lists the current state of all network nodes"),
@@ -135,10 +136,10 @@ def do_node(self, sub_cmd: str, *args):
135136
self.node_add(*args)
136137
case "rm":
137138
self.node_rm(*args)
139+
case "init":
140+
self.node_init(*args)
138141
case "list":
139142
self.node_list(*args)
140-
case "modules":
141-
self.module_list(*args)
142143
case "config-get":
143144
self.node_config_get(*args)
144145
case "config-set":
@@ -230,6 +231,11 @@ def node_rm(self, node: NodeInterface):
230231
return
231232

232233
self.network.remove_node(node)
234+
235+
@validate_args
236+
@load_node
237+
def node_init(self, node: NodeInterface):
238+
node.init()
233239

234240
@validate_args
235241
def node_list(self):
@@ -309,6 +315,10 @@ def network_wipe_cache(self):
309315
@validate_args
310316
def network_wipe_logs(self):
311317
self.network.wipe_logs()
318+
319+
@validate_args
320+
def network_wipe_config(self):
321+
self.network.wipe_config()
312322

313323
@validate_args
314324
def network_status(self):

src/koi_net/log_system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(
4444
)
4545

4646
self.dropped_log_handler = RotatingFileHandler(
47-
filename="dropped_logs.ndjson",
47+
filename="dropped_logs.txt",
4848
maxBytes=self.max_log_file_size,
4949
backupCount=self.max_log_file_backups,
5050
encoding=self.log_file_encoding,
@@ -109,7 +109,7 @@ def __new__(
109109
use_file_handler: bool = True,
110110
use_console_handler: bool = True,
111111
file_handler_log_level: int = logging.DEBUG,
112-
console_handler_log_level: int = logging.INFO
112+
console_handler_log_level: int = logging.DEBUG
113113
):
114114
"""Only instantiable once, other calls will return the first object."""
115115
if not cls._instance:

0 commit comments

Comments
 (0)