forked from AndySchroder/lnd-grpc-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuild_protos.py
65 lines (47 loc) · 1.8 KB
/
rebuild_protos.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
56
57
58
59
60
61
62
63
64
65
from pathlib import Path
import shutil
import sh
import sys
import re
import os
lnd_dir = Path(os.getenv("APP_DIR"))
tapd_dir = Path(os.getenv("TAPP_DIR"))
grpc_client_dir = Path(os.getenv("CLIENT_DIR"))
os.chdir(grpc_client_dir)
if not all([lnd_dir.exists(),tapd_dir.exists(), grpc_client_dir.exists()]):
print("Error: Double check that the paths exist!")
sys.exit(1)
for proto in list(lnd_dir.rglob("**/*.proto")):
print(proto)
shutil.copy(proto, grpc_client_dir.joinpath("lndgrpc/compiled/"))
print(f"Copied: {proto.name}")
for proto in list(tapd_dir.rglob("**/*.proto")):
print(proto)
shutil.copy(proto, grpc_client_dir.joinpath("lndgrpc/compiled/"))
print(f"Copied: {proto.name}")
# Modify paths so python imports work right in generated files.
for proto in list(grpc_client_dir.joinpath("lndgrpc/compiled/").rglob("*.proto")):
with open(proto, 'r+') as f:
text = f.read()
text = re.sub('lightning.proto', 'lndgrpc/compiled/lightning.proto', text)
text = re.sub('verrpc/verrpc.proto', 'lndgrpc/compiled/verrpc.proto', text)
text = re.sub('signrpc/signer.proto', 'lndgrpc/compiled/signer.proto', text)
# also needed for taproot assets
text = re.sub('routerrpc/router.proto', 'lndgrpc/compiled/router.proto', text)
text = re.sub('rfqrpc/rfq.proto', 'lndgrpc/compiled/rfq.proto', text)
text = re.sub('taprootassets.proto', 'lndgrpc/compiled/taprootassets.proto', text)
f.seek(0)
f.write(text)
f.truncate()
protos = list(Path(".").joinpath("lndgrpc/compiled/").glob("*.proto"))
args = [
"-m",
"grpc_tools.protoc",
"--proto_path=.",
"--python_out=.",
"--grpc_python_out=.",
]
for protofile in protos:
args.append(str(protofile) )
# Generate the compiled protofiles
sh.python3(args)