-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjsonParser.py
65 lines (56 loc) · 1.72 KB
/
jsonParser.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
import argparse
import sys
import wget
import os
import json
sys.path = ["../"] + sys.path
import CppHeaderParser
def sapphire2json( cppHeader ):
opCodeJson = []
for x in cppHeader.enums:
channel = {}
channel[ "opcodes" ] = []
for value in x["values"]:
channel[ "opcodes" ].append( { "name" : value[ "name" ], "code" : value[ "value" ] } )
channel[ "channel" ] = x[ "name" ]
opCodeJson.append( channel )
print json.dumps( opCodeJson, sort_keys=True )
def json2sapphire():
print( "do things" )
# implement handling of your mode here
def handleMode( mode, branch ):
if mode == "sapphire2json":
sapphire2json( getCppEnumStruct( branch ) )
elif mode == "json2sapphire":
json2sapphire()
else:
print( "unknown mode" )
def getCppEnumStruct( branch ):
try:
filePath = "Ipcs.h"
if os.path.exists( filePath ):
print( "Removing current Ipcs.h..." )
os.remove( filePath )
url = 'https://raw.githubusercontent.com/SapphireServer/Sapphire/' + branch + '/src/common/Network/PacketDef/Ipcs.h'
print( "Downloading Ipcs.h from " + url )
filename = wget.download(url)
cppHeader = CppHeaderParser.CppHeader( "Ipcs.h" )
except CppHeaderParser.CppParseError as e:
print( e )
sys.exit( 1 )
return cppHeader
# entry point
def main():
parser = argparse.ArgumentParser()
parser.add_argument( '--mode', help='sapphire2json|json2sapphire' )
parser.add_argument( '--branch', help='Which sapphire branch to pull from' )
args = parser.parse_args()
if args.mode == None:
print( "Mode not set!")
parser.print_help()
sys.exit(1)
if args.branch == None:
print( "No source branch for Ipc.h given!" )
sys.exit(1)
handleMode( args.mode, args.branch )
main()