80 lines
2.9 KiB
Python
80 lines
2.9 KiB
Python
from generation.sectionGeneratedActionShouldLoad import *
|
|
|
|
def generateServiceSectionGeneratedActions(c):
|
|
base = f"{c.dir}/templates/service-section-generated-action"
|
|
fmtBusModel = c.readFile(f"{base}-bus-model")
|
|
fmtCommon = c.readFile(base)
|
|
fmtInstant = c.readFile(f"{base}-instant")
|
|
fmtRelay = c.readFile(f"{base}-relay")
|
|
fmtInstantDelay = c.readFile(f"{base}-instant-delay")
|
|
fmtInstantRelay = c.readFile(f"{base}-instant-relay")
|
|
fmtInstantModel = c.readFile(f"{base}-instant-model")
|
|
fmtInstantShouldResetCore = c.readFile(f"{base}-instant-shouldResetCore")
|
|
fmtModel = c.readFile(f"{base}-model")
|
|
fmtShouldResetCore = c.readFile(f"{base}-shouldResetCore")
|
|
|
|
canRelay = "🚀model" in c.structure.service.actions
|
|
if canRelay:
|
|
c.serviceSectionGeneratedActions += "\n".join(fmtRelay + [''])
|
|
|
|
for key in c.structure.service.actions:
|
|
value = c.structure.service.actions[key]
|
|
|
|
# Шаблонные действия.
|
|
if value == "":
|
|
# busModel.
|
|
if key == "busModel":
|
|
c.serviceSectionGeneratedActions += "\n".join(fmtBusModel) + "\n"
|
|
continue
|
|
|
|
# instant model.
|
|
if key == "🚀model":
|
|
c.serviceSectionGeneratedActions += "\n".join(fmtInstantModel) + "\n"
|
|
continue
|
|
|
|
# model.
|
|
if key == "model":
|
|
c.serviceSectionGeneratedActions += "\n".join(fmtModel) + "\n"
|
|
continue
|
|
|
|
# shouldLoad*.
|
|
shouldLoad = "shouldLoad"
|
|
if key.startswith(shouldLoad):
|
|
c.serviceSectionGeneratedActions += sectionGeneratedActionShouldLoad(key, "service", c)
|
|
continue
|
|
|
|
# instant shouldResetCore.
|
|
if key == "🚀shouldResetCore":
|
|
c.serviceSectionGeneratedActions += "\n".join(fmtInstantShouldResetCore) + "\n"
|
|
continue
|
|
|
|
# shouldResetCore.
|
|
if key == "shouldResetCore":
|
|
c.serviceSectionGeneratedActions += "\n".join(fmtShouldResetCore) + "\n"
|
|
continue
|
|
|
|
continue
|
|
|
|
output = ""
|
|
|
|
action = key
|
|
template = fmtCommon
|
|
# Действие без receive(on:)
|
|
if action.startswith("🚀"):
|
|
action = action[1:]
|
|
template = fmtInstantRelay if canRelay else fmtInstant
|
|
|
|
# Действие c .delay(on:)
|
|
if action.startswith("⏳"):
|
|
action = action[1:]
|
|
template = fmtInstantDelay
|
|
|
|
for fmt in template:
|
|
ln = fmt \
|
|
.replace("%SHOULD%", action) \
|
|
.replace("%SINK%", value) \
|
|
.replace("%MODULE%", c.module)
|
|
output += ln + "\n"
|
|
|
|
c.serviceSectionGeneratedActions += output
|