-
Notifications
You must be signed in to change notification settings - Fork 0
/
generatedata.py
37 lines (28 loc) · 776 Bytes
/
generatedata.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
#!/bin/python
import sys
import os
pwd = os.path.dirname(os.path.abspath(__file__))
out = pwd+'/data.js'
if len(sys.argv) > 1: pwd = str(sys.argv[1])
def getpredata(pwd):
r = 'var data = { "title": "'+pwd+'", "parent": { "name": "'+pwd+'", "sons": ['
return r
def getpostdata():
r = ' ] } };'
return r
def getpathdata(name):
if name != '/' and name[-1:] == '/': name = name[:-1]
r = '{"name": "'+os.path.basename(name)+'", "sons": ['
for el in [ n for n in os.listdir(name) if os.path.isdir(os.path.join(name, n)) and n[:1] != '.' ]:
r += getpathdata(name+'/'+el)
r += ' ] },'
return r
def getdata(pwd):
r = getpredata(pwd)
r += getpathdata(pwd)
r += getpostdata()
return r
r = getdata(pwd)
out_file = open(out, 'w')
out_file.write(r)
out_file.close()