-
Notifications
You must be signed in to change notification settings - Fork 6
/
SublimeApiGenerator.py
46 lines (41 loc) · 1.69 KB
/
SublimeApiGenerator.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
import json, os, re, io, sys, traceback, cPickle
API_SIMPLIFIER = re.compile('chrome\.(?:experimental\.)?(.*)')
def processApiJson(inputFilename, outputFilename):
completions = []
obj = json.loads(open(inputFilename, 'r').read())
for api in obj:
if API_SIMPLIFIER.match(api):
if 'functions' in obj[api]:
simpleApiName=API_SIMPLIFIER.match(api).groups(0)[0]
for method in obj[api]['functions']:
paramStr=""
if 'parameters' in method:
for param in method['parameters']:
paramStr+=param['name']
if 'last' not in param or not param['last']:
paramStr+=", "
completion=(
"%s.%s" % (api, method['name']),
"%s\tChrome %s" % (method['name'], simpleApiName),
"%s.%s(%s)" % (api, method['name'], paramStr))
completions.append(completion)
if 'events' in obj[api]:
simpleApiName=API_SIMPLIFIER.match(api).groups(0)[0]
for method in obj[api]['events']:
paramStr=""
if 'parameters' in method:
for param in method['parameters']:
paramStr+=param['name']
if 'last' not in param or not param['last']:
paramStr+=", "
completion=(
"%s.%s.addListener" % (api, method['name']),
"%s\tChrome %s" % (method['name'], simpleApiName),
"%s.%s.addListener(function( %s ) {\n\n});" % (api, method['name'], paramStr))
completions.append(completion)
with open(outputFilename, 'w') as out:
cPickle.dump(completions, out)
def main(argv=[None]):
processApiJson(argv[0], argv[1])
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))