Files
check-ios-bus/Utilities/_platform/2/generate
Михаил Капелько 49cee91239 d
2024-01-29 18:09:14 +03:00

56 lines
1.9 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import os
import sys
from argparse import ArgumentParser
from generation.generateStructure import *
from generation.shortenName import *
from generation.Result import *
from parsing.parseLines import *
from parsing.Structure import *
DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
# Импорт из общей для всех генераторов директории.
sys.path.append(f"{DIR}/../common")
from modulePaths import *
from readFile import *
parser = ArgumentParser(prog='generate v2')
parser.add_argument('module', type=str,
help='the name of the module to generate')
parser.add_argument('-i', '--input', type=str,
help='The path and name of the input file')
parser.add_argument('-o', '--output', type=str,
help='The path of the output files')
parser.add_argument('-s', '--source', type=str,
help='The path of the source files')
args = parser.parse_args()
(PATH, MODULE) = modulePaths(args.module)
print(f"Generating platform for module '{PATH}'...")
FILE_IN = args.input or f"{DIR}/../../../Modules/{PATH}/{MODULE}.yml"
DIR_OUT = args.output or f"{DIR}/../../../Modules/{PATH}/src/"
FILE_OUT = os.path.join(DIR_OUT, f"{MODULE}.Generated.swift")
FILE_OUT_V1 = os.path.join(DIR_OUT, f"{MODULE}.SectionGenerated.swift")
MODULE_SRC = args.source or f"{DIR}/../../../Modules/{PATH}/src"
# Удаляем первую версию генерированного файла при его наличии.
if os.path.isfile(FILE_OUT_V1):
os.remove(FILE_OUT_V1)
# Читаем файл и разбираем его на ключи-значения.
lines = readFile(FILE_IN)
structure = Structure()
parseLines(lines, structure)
# Генерируем код.
result = Result(DIR, PATH, MODULE, readFile, shortenName, MODULE_SRC, structure)
generateStructure(result)
# Сохраняем файл.
with open(FILE_OUT, "w") as file:
file.write(result.file)