-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-block-id.py
55 lines (45 loc) · 1.78 KB
/
init-block-id.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import subprocess
import re
import threading
import queue
import streamlit as st
# Command to start the Polkadot node
command = "./polkadot/target/release/polkadot --alice --validator --base-path ./tmp/relay/alice --chain rococo-custom-3-raw.json --port 30333 --ws-port 9944"
# Define the regular expression pattern to search for the local node ID
pattern = re.compile(r"Local node identity is: (\S+)")
# Start the node process and capture its output
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, shell=True)
# Create a queue to hold the output lines
q = queue.Queue()
# Function to capture the output of a running process
def capture_output(proc, q):
for line in proc.stdout:
q.put(line)
match = pattern.search(line)
if match:
local_node_id = match.group(1)
print("Local node identity (Parachain):", local_node_id)
proc.terminate()
st.title("Initialization")
clicked = st.button("Initialize BlockID")
# Read the output line by line until the local node ID is found
if clicked:
# Start the thread to capture output
t = threading.Thread(target=capture_output, args=(proc, q))
t.start()
while not q.empty():
print("here")
line = q.get()
print(line, end='')
# while proc.stdout.readline():
# line = proc.stdout.readline()
# if not line:
# break
# print(line, end='') # Print the output for debugging purposes
# match = pattern.search(line)
# if match:
# local_node_id = match.group(1)
# print("Local node identity:", local_node_id)
# break
# At this point, you have the local node ID stored in `local_node_id`
# You can add code here to use it as needed