From 05f9376a908f74c86c9c8d9f42feafd4f3650001 Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Thu, 4 Apr 2024 16:11:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B12:=20=D0=B4=D0=BE=D0=B4=D0=B0?= =?UTF-8?q?=D0=B2=20=D0=BF=D1=96=D0=B4=D1=82=D1=80=D0=B8=D0=BC=D0=BA=D1=83?= =?UTF-8?q?=20=D0=B0=D1=80=D0=B3=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D1=83=20--d?= =?UTF-8?q?estination=20=D1=83=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D1=83=20=D0=B4=D0=BB=D1=8F=20=D0=B3=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D1=96=D1=97=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D1=8C=20=D1=82=D0=B0=20=D0=BF=D0=BE=D0=BA=D1=80=D0=B0?= =?UTF-8?q?=D1=89=D0=B8=D0=B2=20=D1=97=D1=97=20=D0=B2=D0=B8=D0=B2=D1=96?= =?UTF-8?q?=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/table-generator/convert.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/utils/table-generator/convert.py b/utils/table-generator/convert.py index edb798d..6fbce50 100755 --- a/utils/table-generator/convert.py +++ b/utils/table-generator/convert.py @@ -1,6 +1,7 @@ #!/bin/python3 import sys +import os # magic values NO = 0 @@ -26,7 +27,7 @@ def convert_usecase_v1(filename, data): merged_lines = [] for i in split_raw_lines: - if i[0] == "": + if i[0].replace(" ", "") == "": merged_lines[-1][1] += "
" + i[1] else: merged_lines.append(i) @@ -68,9 +69,10 @@ if __name__=="__main__": usecase_formatting = AUTO verbose = AUTO process_table_files = AUTO + file_output_path = None # 1 pass (argument harvest) - for i in sys.argv[1:]: + for n, i in enumerate(sys.argv[1:]): if i.startswith("-"): # записувати таблицю в файл if i in ["-f", "--file"]: @@ -96,11 +98,17 @@ if __name__=="__main__": elif i in ["-nv", "--no-verbose"]: verbose = NO + # дозволити обробку файлів .table elif i in ["-t", "--process-table"]: process_table_files = YES elif i in ["-nt", "--no-process-table"]: process_table_files = NO + # задає папку, в яку необхідно зберігати конвертовані таблиці + elif i in ["-d", "--destination"]: + file_output_path = sys.argv[n+2] + sys.argv.remove(sys.argv[n+2]) + # 2 pass (filename harvest) for i in sys.argv[1:]: if not i.startswith("-"): @@ -133,12 +141,17 @@ if __name__=="__main__": print(formatted_table_data) if write_to_file > AUTO: - open(name + ".table", 'w', encoding = "utf-8").write(formatted_table_data+"\n") + if file_output_path: + open(os.path.join(file_output_path, os.path.basename(name)) \ + + ".table", 'w', encoding = "utf-8") \ + .write(formatted_table_data+"\n") + else: + open(name + ".table", 'w', encoding = "utf-8").write(formatted_table_data+"\n") exit(0) for no, name in enumerate(files): - print(f"Converting {no+1}/{len(files)}") + print(f"Converting {no+1:02d}/{len(files)}: {name}") data = open(name, encoding = "utf-8").read() @@ -157,4 +170,9 @@ if __name__=="__main__": print(formatted_table_data) if write_to_file >= AUTO: - open(name + ".table", 'w', encoding = "utf-8").write(formatted_table_data+"\n") + if file_output_path: + open(os.path.join(file_output_path, os.path.basename(name)) \ + + ".table", 'w', encoding = "utf-8") \ + .write(formatted_table_data+"\n") + else: + open(name + ".table", 'w', encoding = "utf-8").write(formatted_table_data+"\n")