56 строки
1.9 KiB
Python
Исполняемый файл
56 строки
1.9 KiB
Python
Исполняемый файл
#!/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)
|