forked from boy-hack/airbug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
53 lines (43 loc) · 1.61 KB
/
build.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
# API生成工具,通过此工具生成json文件的API
import os
import re
import datetime
import json
class direct:
root = os.path.dirname(os.path.realpath(__file__))
hardware = os.path.join(root, "hardware")
cms = os.path.join(root, "cms")
system = os.path.join(root, "system")
common = os.path.join(root, "common")
def getType(dirpath):
path = dirpath.replace(os.path.join(direct.root), "").lstrip('/')
try:
index = path.index("/")
return path[:index]
except ValueError:
return path
result = []
walk_directorys = [direct.cms, direct.hardware, direct.system, direct.common]
for walk_direct in walk_directorys:
for dirpath, dirnames, filenames in os.walk(walk_direct):
for file in filenames:
fullpath = os.path.join(dirpath, file)
if fullpath.endswith(".py"):
_fullpath = fullpath.replace(direct.root, "")
typec = getType(dirpath)
pattern = '/{}/(\w+)/'.format(typec)
m = re.match(pattern, _fullpath)
if m:
name = m.group(1)
# print(_fullpath)
timestamp = os.path.getmtime(fullpath)
date = datetime.datetime.fromtimestamp(timestamp)
_temp = {
"name": name,
"type": typec,
"filepath": _fullpath,
"time": date.strftime('%Y-%m-%d %H:%M:%S')
}
result.append(_temp)
with open("API.json", "w") as f:
json.dump(result, f, indent=4)