-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpackData.py
80 lines (67 loc) · 2.37 KB
/
packData.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import pickle
import RouteFinderLib
import os
import config
mode = input("Read Airports' data?(y/n strictly):")
cycle = input("Input Data Version (such as 2206):")
if mode == "y":
airport_data = {}
for home, dirs, files in os.walk(os.path.join(config.LOCAL_ASDATA_PATH, "proc")):
for filename in files:
print(filename)
fullpath = os.path.join(home, filename)
file = open(fullpath, "r")
airport_data[filename.replace(".txt", "")] = file.read()
file.close()
apfile = open(os.path.join(config.LOCAL_ASDATA_PATH, "Airports.txt"), "r")
airport_data["GLOBAL"] = apfile.readlines()
apfile.close()
packedFile = open("airport_" + cycle + ".air", "wb")
pickle.dump(airport_data, packedFile)
print("数据生成完毕")
packedFile.close()
else:
obj = RouteFinderLib.RTFCALC({}, [], None)
obj.ReadASData(config.LOCAL_ASDATA_PATH)
print("nodeList占用内存大小:" + str(int(obj.nodeList.__sizeof__() / 1024)) + " KB")
print("数据读取完毕,开始生成序列化航路文件")
packedFile = open("navidata_" + cycle + ".map", "wb")
pickle.dump(obj.nodeList, packedFile)
print("数据生成完毕")
packedFile.close()
# Automatically update config.py
print("正在更新config.py配置文件")
if mode == "y":
config.SET_APDAT_PATH = "airport_" + cycle + ".air"
else:
config.SET_NAVDAT_PATH = "navidata_" + cycle + ".map"
with open(os.path.join(config.LOCAL_ASDATA_PATH, "Cycle.txt"), "r+") as f:
config.NAVDAT_CYCLE = f.read()
content = """# Global Settings.If finished deployments,just reset the items below.
# LOCAL_ASDATA_PATH should be a Navigraph data of Aerosoft.
LOCAL_ASDATA_PATH = "{}"
# Website function settings.
LISTEN_PORT = {}
METAR_UPDATE_MINUTE = {}
YourBingMapsKey = "{}"
BackstageKey = "{}"
# Settings below would be automatically updated after running the packData.py.
# There is no need to manually modify them if they are correct.
SET_NAVDAT_PATH = "{}"
SET_APDAT_PATH = "{}"
NAVDAT_CYCLE = "{}"
""".format(
config.LOCAL_ASDATA_PATH,
config.LISTEN_PORT,
config.METAR_UPDATE_MINUTE,
config.YourBingMapsKey,
config.BackstageKey,
config.SET_NAVDAT_PATH,
config.SET_APDAT_PATH,
config.NAVDAT_CYCLE,
)
confFile = open("./config.py", "w+")
confFile.write(content)
confFile.close()
print(content)
print("更新成功")