2022-03-07 11:56:09 +03:00
|
|
|
import configparser
|
|
|
|
|
import os
|
|
|
|
|
import json, pprint
|
|
|
|
|
|
|
|
|
|
config = configparser.ConfigParser() # создаём объекта парсера INI
|
|
|
|
|
allLibs_esp8266_4mb = ""
|
|
|
|
|
allLibs_esp32_4mb = ""
|
2022-03-07 21:56:15 +03:00
|
|
|
|
2022-03-07 11:56:09 +03:00
|
|
|
allMenuItems = json.loads('[]')
|
2022-03-07 21:56:15 +03:00
|
|
|
allMenuItemsCount = 1
|
|
|
|
|
|
|
|
|
|
allAPI_head = ""
|
|
|
|
|
allAPI_exec = ""
|
2022-03-07 11:56:09 +03:00
|
|
|
|
2022-05-18 15:12:20 +03:00
|
|
|
excludeDirs = ""
|
|
|
|
|
|
2022-03-07 11:56:09 +03:00
|
|
|
|
|
|
|
|
def getDirs(path):
|
2022-05-18 15:12:20 +03:00
|
|
|
global excludeDirs
|
2022-03-07 11:56:09 +03:00
|
|
|
for file in os.listdir(path):
|
2022-05-18 15:12:20 +03:00
|
|
|
maybeDir = os.path.join(path, file)
|
|
|
|
|
if os.path.isdir(maybeDir):
|
|
|
|
|
config.clear()
|
|
|
|
|
if config.read(maybeDir + "/platformio.ini"):
|
|
|
|
|
if config.getboolean("iotm", "exclude", fallback=False):
|
|
|
|
|
print("Excluded: " + maybeDir)
|
|
|
|
|
maybeDir = maybeDir.replace("src/", "")
|
|
|
|
|
excludeDirs = excludeDirs + "\n-<" + maybeDir + ">"
|
|
|
|
|
else:
|
|
|
|
|
yield file
|
2022-03-07 11:56:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def getPIOLibs(patch):
|
|
|
|
|
global allLibs_esp8266_4mb, allLibs_esp32_4mb
|
|
|
|
|
for dir in getDirs(patch):
|
2022-05-18 15:12:20 +03:00
|
|
|
config.clear()
|
2022-03-07 11:56:09 +03:00
|
|
|
if (config.read(patch + dir + "/platformio.ini")):
|
|
|
|
|
print(patch + dir + "/platformio.ini")
|
|
|
|
|
allLibs_esp8266_4mb = allLibs_esp8266_4mb + config["env:esp8266_4mb"]["lib_deps"]
|
|
|
|
|
allLibs_esp32_4mb = allLibs_esp32_4mb + config["env:esp32_4mb"]["lib_deps"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getMenuItems(patch):
|
|
|
|
|
global allMenuItems, allMenuItemsCount
|
|
|
|
|
with open(patch + "items.json", "r") as read_file:
|
|
|
|
|
allMenuItems = allMenuItems + json.load(read_file)
|
|
|
|
|
|
|
|
|
|
for dir in getDirs(patch):
|
|
|
|
|
with open(patch + dir + "/items.json", "r") as read_file:
|
|
|
|
|
print(patch + dir + "/items.json")
|
|
|
|
|
data = json.load(read_file)
|
|
|
|
|
for item in data:
|
|
|
|
|
item["name"] = str(allMenuItemsCount) + ". " + item["name"]
|
|
|
|
|
item["num"] = allMenuItemsCount
|
|
|
|
|
allMenuItemsCount = allMenuItemsCount + 1
|
|
|
|
|
allMenuItems = allMenuItems + data
|
|
|
|
|
|
|
|
|
|
|
2022-03-07 21:56:15 +03:00
|
|
|
def getAPI(patch):
|
|
|
|
|
global allAPI_head, allAPI_exec
|
|
|
|
|
for dir in getDirs(patch):
|
|
|
|
|
print(patch + dir)
|
|
|
|
|
allAPI_head = allAPI_head + "\nvoid* getAPI_" + dir + "(String subtype, String params);"
|
|
|
|
|
allAPI_exec = allAPI_exec + "\nif ((tmpAPI = getAPI_" + dir + "(subtype, params)) != nullptr) return tmpAPI;"
|
|
|
|
|
|
|
|
|
|
|
2022-03-07 11:56:09 +03:00
|
|
|
|
|
|
|
|
# читаем и запоминаем все либы мз каждого модуля
|
|
|
|
|
getPIOLibs("src/modules/system/")
|
|
|
|
|
getPIOLibs("src/modules/exec/")
|
|
|
|
|
getPIOLibs("src/modules/sensors/")
|
|
|
|
|
getPIOLibs("src/modules/lcd/")
|
|
|
|
|
|
|
|
|
|
# сохраняем собранные либы в настройках PIO
|
2022-05-18 15:12:20 +03:00
|
|
|
config.clear()
|
2022-03-07 11:56:09 +03:00
|
|
|
config.read("platformio.ini")
|
|
|
|
|
config["env:esp8266_4mb_fromitems"]["lib_deps"] = allLibs_esp8266_4mb
|
|
|
|
|
config["env:esp32_4mb_fromitems"]["lib_deps"] = allLibs_esp32_4mb
|
2022-05-18 15:12:20 +03:00
|
|
|
config["env:esp8266_4mb_fromitems"]["src_filter"] = excludeDirs
|
|
|
|
|
config["env:esp32_4mb_fromitems"]["src_filter"] = excludeDirs
|
2022-03-07 11:56:09 +03:00
|
|
|
with open("platformio.ini", 'w') as configfile:
|
|
|
|
|
config.write(configfile)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# готовим первый элемент меню
|
|
|
|
|
with open("src/modules/items.json", "r") as read_file:
|
|
|
|
|
allMenuItems = allMenuItems + json.load(read_file)
|
|
|
|
|
|
|
|
|
|
# читаем и запоминаем пункты меню модуелей
|
|
|
|
|
getMenuItems("src/modules/system/")
|
|
|
|
|
getMenuItems("src/modules/exec/")
|
|
|
|
|
getMenuItems("src/modules/sensors/")
|
|
|
|
|
getMenuItems("src/modules/lcd/")
|
|
|
|
|
|
|
|
|
|
# сохраняем пункты меню в общий файл
|
|
|
|
|
with open('data_svelte/items.json', 'w') as f:
|
2022-03-07 21:56:15 +03:00
|
|
|
json.dump(allMenuItems, f, ensure_ascii=False, indent=4, sort_keys=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# собираем списки API для интеграции вызовов модулей
|
|
|
|
|
getAPI("src/modules/system/")
|
|
|
|
|
getAPI("src/modules/exec/")
|
|
|
|
|
getAPI("src/modules/sensors/")
|
|
|
|
|
getAPI("src/modules/lcd/")
|
|
|
|
|
|
|
|
|
|
# сохраняем все API в API.cpp
|
|
|
|
|
apicpp = '#include "ESPConfiguration.h"\n'
|
|
|
|
|
apicpp = apicpp + allAPI_head
|
|
|
|
|
apicpp = apicpp + '\n\nvoid* getAPI(String subtype, String params) {\nvoid* tmpAPI;'
|
|
|
|
|
apicpp = apicpp + allAPI_exec
|
|
|
|
|
apicpp = apicpp + 'return nullptr;\n}'
|
|
|
|
|
with open('src/modules/API.cpp', 'w') as f:
|
|
|
|
|
f.write(apicpp)
|