Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python script to generate proto3 definitions #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build/
s2clientprotocol/__init__.py
dist/
s2clientprotocol.egg-info/
/s2clientprotocol_proto3
39 changes: 39 additions & 0 deletions convert_proto3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python3
import glob,os

# this will create a folder "s2clientprotocol_proto3" with the converted proto3 definition files
# just for current .proto files, it is not a generic proto2 to proto3 converter!
def convert_proto3():
files = glob.glob("s2clientprotocol/*.proto")

out_dir = "s2clientprotocol_proto3"

if not os.path.exists(out_dir):
os.makedirs(out_dir)

for fle in files:
with open(fle) as f:
outf = open(out_dir +"/" + fle[17:], "w");
text = f.readlines()
prevline = ""

for line in text:

if ( line.strip().find("optional ") == 0): # remove optional
outf.write(line.replace("optional ","",1))
elif (line.find("syntax =") == 0): # change version declaration
outf.write('syntax = "proto3";\n')
else: # add dummy element to enum with starting value 0
enumpos = prevline.find("enum ") # for correct indentation
if (prevline.strip().find("enum ") == 0 and
line[line.find("=")+1:line.find(";")].strip() == "1"):
outf.write((" "*enumpos) +" "+ prevline.strip().split()[1]+"_UNSET = 0;\n" )
outf.write(line)
else:
outf.write(line)
prevline = line
outf.close()



convert_proto3()