-
Notifications
You must be signed in to change notification settings - Fork 18
/
update_protos.sh
executable file
·30 lines (30 loc) · 1.39 KB
/
update_protos.sh
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
#!/usr/bin/env bash
echo "Updating proto sources..."
git submodule update --remote
cp github.com/openconfig/gnmi/proto/gnmi/*.proto src/cisco_gnmi/proto/
cp github.com/openconfig/gnmi/proto/gnmi_ext/*.proto src/cisco_gnmi/proto/
echo "Fixing proto imports..."
python -c "
with open('src/cisco_gnmi/proto/gnmi.proto', 'r') as gnmi_fd:
file_content = gnmi_fd.read()
file_content = file_content.replace('github.com/openconfig/gnmi/proto/gnmi_ext/', '', 1)
with open('src/cisco_gnmi/proto/gnmi.proto', 'w') as gnmi_fd:
gnmi_fd.write(file_content)
"
echo "Compiling protos..."
pipenv run python -m grpc_tools.protoc --proto_path=src/cisco_gnmi/proto --python_out=src/cisco_gnmi/proto --grpc_python_out=src/cisco_gnmi/proto gnmi.proto gnmi_ext.proto
echo "Fixing compiled Python imports..."
python -c "
with open('src/cisco_gnmi/proto/gnmi_pb2_grpc.py', 'r') as gnmi_fd:
file_content = gnmi_fd.read()
file_content = file_content.replace('import gnmi_pb2', 'from . import gnmi_pb2', 1)
with open('src/cisco_gnmi/proto/gnmi_pb2_grpc.py', 'w') as gnmi_fd:
gnmi_fd.write(file_content)
with open('src/cisco_gnmi/proto/gnmi_pb2.py', 'r') as gnmi_fd:
file_content = gnmi_fd.read()
file_content = file_content.replace('import gnmi_ext_pb2', 'from . import gnmi_ext_pb2', 1)
with open('src/cisco_gnmi/proto/gnmi_pb2.py', 'w') as gnmi_fd:
gnmi_fd.write(file_content)
"
echo "Cleaning up..."
rm src/cisco_gnmi/proto/*.proto