From e9d104f53a8b1782d01efcb7280593b21ef1b8fb Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Sun, 24 Mar 2024 16:35:21 +0200 Subject: [PATCH] =?UTF-8?q?utils/table-generator/convert.py:=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=D0=B2=20=D0=B7=D0=B0=D1=85=D0=B8=D1=81=D1=82?= =?UTF-8?q?=20=D0=B2=D1=96=D0=B4=20=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=BE=D1=97=20=D0=BE=D0=B1=D1=80=D0=BE=D0=B1=D0=BA=D0=B8?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=D1=96=D0=B2=20=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D1=86=D1=8C=20=D1=82=D0=B0=20=D0=B2=D0=B8=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=B8=D0=B2=20=D0=B4=D0=B5=D0=BA=D1=96=D0=BB?= =?UTF-8?q?=D1=8C=D0=BA=D0=B0=20=D0=BF=D0=BE=D0=BC=D0=B8=D0=BB=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/table-generator/convert.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/utils/table-generator/convert.py b/utils/table-generator/convert.py index 1bec61d..edb798d 100755 --- a/utils/table-generator/convert.py +++ b/utils/table-generator/convert.py @@ -67,7 +67,9 @@ if __name__=="__main__": write_to_stdout = AUTO usecase_formatting = AUTO verbose = AUTO + process_table_files = AUTO + # 1 pass (argument harvest) for i in sys.argv[1:]: if i.startswith("-"): # записувати таблицю в файл @@ -94,8 +96,18 @@ if __name__=="__main__": elif i in ["-nv", "--no-verbose"]: verbose = NO - else: - files.append(i) + elif i in ["-t", "--process-table"]: + process_table_files = YES + elif i in ["-nt", "--no-process-table"]: + process_table_files = NO + + # 2 pass (filename harvest) + for i in sys.argv[1:]: + if not i.startswith("-"): + if i.endswith(".table") and process_table_files <= AUTO: + print(f"[Warning]: Excluding {i} to prevent processing of an already processed file (pass --process-table to override this behaviour)") + else: + files.append(i) if len(files) < 1: print("You need to pass at least one file as CLI argument", file=sys.stderr) @@ -121,12 +133,12 @@ if __name__=="__main__": print(formatted_table_data) if write_to_file > AUTO: - open(name + ".table", 'w', encoding = "utf-8").write(data+"\n") + open(name + ".table", 'w', encoding = "utf-8").write(formatted_table_data+"\n") exit(0) - for no, name in enumerate(sys.argv[1:]): - print(f"Converting {no+1}/{len(sys.argv)}") + for no, name in enumerate(files): + print(f"Converting {no+1}/{len(files)}") data = open(name, encoding = "utf-8").read() @@ -145,4 +157,4 @@ if __name__=="__main__": print(formatted_table_data) if write_to_file >= AUTO: - open(name + ".table", 'w', encoding = "utf-8").write(data+"\n") + open(name + ".table", 'w', encoding = "utf-8").write(formatted_table_data+"\n")