1
0
mirror of https://github.com/240596448/onec_codetemplate_parser.git synced 2025-11-23 21:34:39 +02:00
This commit is contained in:
Vladimir Nadulich
2025-10-30 01:23:37 +03:00
committed by Vladimir Nadulich
parent fd3af97957
commit c6a8d860df
7 changed files with 46 additions and 7 deletions

View File

@@ -0,0 +1,3 @@
from .api import parse_to_src, render_from_src
__all__ = ["parse_to_src", "render_from_src"]

View File

@@ -0,0 +1,4 @@
from .cli import app
if __name__ == "__main__":
app()

View File

@@ -0,0 +1,15 @@
from .core import parse_skobkofile as parser
from .core import Root
from pathlib import Path
def parse_to_src(path: str, src: str):
"""Парсит шаблон 1С-файла и сохраняет структуру файлов в папку"""
root = parser(path)
root.to_files(src)
def render_from_src(src: str, path: str):
"""Генерирует код шаблона из исходников"""
root = Root.from_files(src)
text = root.compile()
Path(path).write_text(text, encoding='utf-8-sig')

View File

@@ -0,0 +1,18 @@
import typer
from .api import parse_to_src, render_from_src
app = typer.Typer(help="Парсер шаблонов 1С")
@app.command()
def parse(path: str, src: str):
"""Разобрать шаблон из 1с-файла *.st в исходники src"""
result = parse_to_src(path, src)
typer.echo(result)
@app.command()
def render(src: str, path: str):
"""Собрать шаблон из исходников src в 1с-файл *.st"""
render_from_src(src, path)
if __name__ == "__main__":
app()

View File

@@ -176,7 +176,7 @@ class Root(Node):
def from_files(cls, path):
assert not os.path.isfile(path), f"Путь '{path}' является файлом, а не директорией"
assert os.path.exists(path), f"Дирректория '{path}' не существует"
assert os.path.exists(path), f"Директория '{path}' не существует"
#прочитать все файлы и собрать обратно в дерево
entries = sorted(os.listdir(path))

View File

@@ -1,5 +1,4 @@
import pytest
from onec_codetemplate_parser import main
from pathlib import Path
TEST_FILE = 'Documents/1C/1c-text-tempates/Надулич.st'

View File

@@ -1,4 +1,4 @@
from onec_codetemplate_parser import main
from onec_codetemplate_parser import core
from tests.common import check_files_sequential
class Test_Read_Skobkofile:
@@ -7,12 +7,12 @@ class Test_Read_Skobkofile:
assert test_file_path.exists()
def test_01_parse_eq_compile(self, test_data):
root = main.parse_skobkofile(test_data)
root = core.parse_skobkofile(test_data)
new_data = root.compile()
assert new_data == test_data
def test_02_save_and_read(self, test_data, tmp_path):
root = main.parse_skobkofile(test_data)
root = core.parse_skobkofile(test_data)
new_data = root.compile()
tmp_file = tmp_path / 'tmp.st'
@@ -24,7 +24,7 @@ class Test_Read_Skobkofile:
class Test_Write_To_Files:
def test_00_to_file(self, test_data, temp_src):
root = main.parse_skobkofile(test_data)
root = core.parse_skobkofile(test_data)
root.to_files(temp_src)
def test_01_to_files(self, temp_src):
@@ -39,7 +39,7 @@ class Test_Write_To_Files:
def test_02_sequential_name(self, temp_src):
d = temp_src / "001.0_Надулич" / "002.0_Комментарии"
subfiles = [p.name for p in d.iterdir() if p.is_dir()]
subfiles = [p.name for p in d.iterdir()]
check_files_sequential(subfiles)