-
Notifications
You must be signed in to change notification settings - Fork 2
/
compile.py
61 lines (50 loc) · 1.53 KB
/
compile.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
import sys, os, subprocess, re, json
from pprint import pprint
os.chdir(os.path.split(os.path.abspath( __file__ ))[0])
def readf(p):
f = open(p, 'r')
c = f.read()
f.close()
return c
def getpaths():
paths = os.listdir(".")
for p in paths:
try:
if p.startswith('.'):
continue
subpaths = os.listdir(p)
for sp in subpaths:
if sp.startswith('.'):
continue
sp2 = p + '/' + sp
yield (sp2, p, sp)
except Exception:
pass
allthings = {}
for sp2, p, sp in getpaths():
selector = p
identifier = sp.split('.')[0]
extension = sp.split('.')[1]
k = selector + '/' + identifier
if k not in allthings:
allthings[k] = {
'displayname': identifier.capitalize(),
'identifier': identifier,
'selector': selector,
'files': [],
}
if len(sp.split('.')) == 2:
# json
allthings[k]['definition'] = json.loads(readf(sp2))
if 'displayname' in allthings[k]['definition']:
allthings[k]['displayname'] = allthings[k]['definition']['displayname']
elif len(sp.split('.')) == 3:
# file
allthings[k]['files'].append({
'extension': extension,
'template': readf(sp2),
})
else:
print "WOULD YOU CARE FOR SOME TEA?"
continue
open('boilerplate.json', 'w').write(json.dumps(allthings) + '\n')