1 | #!/usr/bin/env python
|
---|
2 |
|
---|
3 | import sys
|
---|
4 |
|
---|
5 | if sys.version_info < (2, 7):
|
---|
6 | print("This script requires at least Python 2.7.")
|
---|
7 | print("Please, update to a newer version: http://www.python.org/download/releases/")
|
---|
8 | exit()
|
---|
9 |
|
---|
10 | import argparse
|
---|
11 | import json
|
---|
12 | import os
|
---|
13 | import re
|
---|
14 | import shutil
|
---|
15 | import tempfile
|
---|
16 |
|
---|
17 |
|
---|
18 | def main(argv=None):
|
---|
19 |
|
---|
20 | parser = argparse.ArgumentParser()
|
---|
21 | parser.add_argument('--include', action='append', required=True)
|
---|
22 | parser.add_argument('--output', default='sublimetext2/threejs.sublime-completions')
|
---|
23 |
|
---|
24 | args = parser.parse_args()
|
---|
25 |
|
---|
26 | output = args.output
|
---|
27 |
|
---|
28 | # parsing
|
---|
29 |
|
---|
30 | print(' * Generating ' + output)
|
---|
31 |
|
---|
32 | fd, path = tempfile.mkstemp()
|
---|
33 | tmp = open(path, 'w')
|
---|
34 | tmp.write('{\n\t"scope": "source.js,source.js.embedded.html,source.coffee",\n\t"version": "r55",\n\t"completions":\n\t[\n')
|
---|
35 |
|
---|
36 | for include in args.include:
|
---|
37 | with open('../build/includes/' + include + '.json','r') as f: files = json.load(f)
|
---|
38 | for filename in files:
|
---|
39 | filename = '../../' + filename;
|
---|
40 | with open(filename, 'r') as f:
|
---|
41 | string = f.read()
|
---|
42 | match = re.search('THREE.(\w+)[\ ]+?=[\ ]+?function[\ ]+\(([\w\,\ ]+)?\)', string)
|
---|
43 | if match:
|
---|
44 | name = match.group(1)
|
---|
45 | parameters = match.group(2)
|
---|
46 | if parameters is None:
|
---|
47 | parameters = ''
|
---|
48 | else:
|
---|
49 | array = parameters.split( ',' )
|
---|
50 | for i in range(len(array)):
|
---|
51 | array[i] = '${'+str(i+1)+':'+array[i].strip()+'}' # ${1:param}
|
---|
52 | parameters = ' '+', '.join(array)+' '
|
---|
53 | tmp.write('\t\t{ "trigger": "THREE.'+name+'", "contents": "THREE.'+name+'('+parameters+')$0" },\n' )
|
---|
54 |
|
---|
55 | tmp.write("\t\t\"THREE\"\n\t]\n}")
|
---|
56 | tmp.close()
|
---|
57 |
|
---|
58 | # save
|
---|
59 |
|
---|
60 | shutil.copy(path, output)
|
---|
61 | os.chmod(output, 0o664); # temp files would usually get 0600
|
---|
62 |
|
---|
63 |
|
---|
64 | if __name__ == "__main__":
|
---|
65 | main()
|
---|