Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e9d104f53a | |||
| b8f1e590e7 | |||
| 06b52b1efc |
@@ -14,7 +14,15 @@ def convert_generic_v1(data):
|
|||||||
|
|
||||||
def convert_usecase_v1(filename, data):
|
def convert_usecase_v1(filename, data):
|
||||||
split_raw_lines_from_file = [i.split(" | ") for i in data.split("\n") if i]
|
split_raw_lines_from_file = [i.split(" | ") for i in data.split("\n") if i]
|
||||||
split_raw_lines = [["ID", filename.upper()]] + split_raw_lines_from_file
|
|
||||||
|
if '/' in filename:
|
||||||
|
use_case_name = filename.rsplit("/", 1)[1].upper()
|
||||||
|
elif '\\' in filename:
|
||||||
|
use_case_name = filename.rsplit("\\", 1)[1].upper()
|
||||||
|
else:
|
||||||
|
use_case_name = filename.upper()
|
||||||
|
|
||||||
|
split_raw_lines = [["ID", use_case_name]] + split_raw_lines_from_file
|
||||||
|
|
||||||
merged_lines = []
|
merged_lines = []
|
||||||
for i in split_raw_lines:
|
for i in split_raw_lines:
|
||||||
@@ -59,7 +67,9 @@ if __name__=="__main__":
|
|||||||
write_to_stdout = AUTO
|
write_to_stdout = AUTO
|
||||||
usecase_formatting = AUTO
|
usecase_formatting = AUTO
|
||||||
verbose = AUTO
|
verbose = AUTO
|
||||||
|
process_table_files = AUTO
|
||||||
|
|
||||||
|
# 1 pass (argument harvest)
|
||||||
for i in sys.argv[1:]:
|
for i in sys.argv[1:]:
|
||||||
if i.startswith("-"):
|
if i.startswith("-"):
|
||||||
# записувати таблицю в файл
|
# записувати таблицю в файл
|
||||||
@@ -86,8 +96,18 @@ if __name__=="__main__":
|
|||||||
elif i in ["-nv", "--no-verbose"]:
|
elif i in ["-nv", "--no-verbose"]:
|
||||||
verbose = NO
|
verbose = NO
|
||||||
|
|
||||||
else:
|
elif i in ["-t", "--process-table"]:
|
||||||
files.append(i)
|
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:
|
if len(files) < 1:
|
||||||
print("You need to pass at least one file as CLI argument", file=sys.stderr)
|
print("You need to pass at least one file as CLI argument", file=sys.stderr)
|
||||||
@@ -96,7 +116,7 @@ if __name__=="__main__":
|
|||||||
|
|
||||||
if len(files) == 1:
|
if len(files) == 1:
|
||||||
name = files[0]
|
name = files[0]
|
||||||
data = open(name).read()
|
data = open(name, encoding = "utf-8").read()
|
||||||
|
|
||||||
if usecase_formatting == YES:
|
if usecase_formatting == YES:
|
||||||
if verbose == YES:
|
if verbose == YES:
|
||||||
@@ -113,14 +133,14 @@ if __name__=="__main__":
|
|||||||
print(formatted_table_data)
|
print(formatted_table_data)
|
||||||
|
|
||||||
if write_to_file > AUTO:
|
if write_to_file > AUTO:
|
||||||
open(name + ".table", 'w').write(data+"\n")
|
open(name + ".table", 'w', encoding = "utf-8").write(formatted_table_data+"\n")
|
||||||
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
for no, name in enumerate(sys.argv[1:]):
|
for no, name in enumerate(files):
|
||||||
print(f"Converting {no+1}/{len(sys.argv)}")
|
print(f"Converting {no+1}/{len(files)}")
|
||||||
|
|
||||||
data = open(name).read()
|
data = open(name, encoding = "utf-8").read()
|
||||||
|
|
||||||
if usecase_formatting == YES:
|
if usecase_formatting == YES:
|
||||||
if verbose >= AUTO:
|
if verbose >= AUTO:
|
||||||
@@ -137,4 +157,4 @@ if __name__=="__main__":
|
|||||||
print(formatted_table_data)
|
print(formatted_table_data)
|
||||||
|
|
||||||
if write_to_file >= AUTO:
|
if write_to_file >= AUTO:
|
||||||
open(name + ".table", 'w').write(data+"\n")
|
open(name + ".table", 'w', encoding = "utf-8").write(formatted_table_data+"\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user