mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
feat/561-added autonat service
This commit is contained in:
committed by
Paul Robinson
parent
fd893afba6
commit
9655c88788
36
libp2p/host/autonat/pb/generate_proto.py
Executable file
36
libp2p/host/autonat/pb/generate_proto.py
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
|
||||
|
||||
def generate_proto() -> None:
|
||||
proto_file = "autonat.proto"
|
||||
output_dir = "."
|
||||
|
||||
# Ensure protoc is installed
|
||||
try:
|
||||
subprocess.run(["protoc", "--version"], check=True, capture_output=True)
|
||||
except subprocess.CalledProcessError:
|
||||
print("Error: protoc is not installed. Please install protobuf compiler.")
|
||||
return
|
||||
except FileNotFoundError:
|
||||
print("Error: protoc is not found in PATH. Please install protobuf compiler.")
|
||||
return
|
||||
|
||||
# Generate Python code
|
||||
cmd = [
|
||||
"protoc",
|
||||
"--python_out=" + output_dir,
|
||||
"--grpc_python_out=" + output_dir,
|
||||
"-I.",
|
||||
proto_file,
|
||||
]
|
||||
|
||||
try:
|
||||
subprocess.run(cmd, check=True)
|
||||
print("Successfully generated protobuf code for " + proto_file)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Error generating protobuf code: " + str(e))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
generate_proto()
|
||||
Reference in New Issue
Block a user