Browse Source

added compact output to xls2changelog

master
Holger Frey 4 years ago
parent
commit
5579f84fd7
  1. 18
      work_helpers/excel2changelog.py

18
work_helpers/excel2changelog.py

@ -14,9 +14,11 @@ col_start = "A" @@ -14,9 +14,11 @@ col_start = "A"
row_start = 8
def text_to_changelog(raw_text, sheet, start_column, start_row):
def text_to_changelog(raw_text, sheet, start_column, start_row, compact=False):
cells = [line.split("\t") for line in raw_text.splitlines()]
xls_sep = "!" if compact else "\t"
output = []
current_row = 1
columns_start_index = EXCEL_COLUMNS.index(start_column)
@ -24,13 +26,14 @@ def text_to_changelog(raw_text, sheet, start_column, start_row): @@ -24,13 +26,14 @@ def text_to_changelog(raw_text, sheet, start_column, start_row):
for row, line in enumerate(cells, start=start_row):
if row != current_row:
output.append("")
if not compact:
output.append("")
current_row = row
for column, cell in zip(columns_used, line):
cell = cell.strip()
if not cell:
continue
output.append(f"{sheet}\t{column}{row}\t{cell}")
output.append(f"{sheet}{xls_sep}{column}{row}\t{cell}")
iterator = iter(output)
prev = next(iterator)
@ -42,9 +45,9 @@ def text_to_changelog(raw_text, sheet, start_column, start_row): @@ -42,9 +45,9 @@ def text_to_changelog(raw_text, sheet, start_column, start_row):
prev = current
def clipboard_to_changelog(sheet, start_column, start_row):
def clipboard_to_changelog(sheet, start_column, start_row, compact=False):
xls = pyperclip.paste()
result = list(text_to_changelog(xls, sheet, start_column, start_row))
result = list(text_to_changelog(xls, sheet, start_column, start_row, compact))
line_count = len(result)
if line_count == 1:
print(f"Copied one line to the clipboard")
@ -63,7 +66,8 @@ def clipboard_to_changelog(sheet, start_column, start_row): @@ -63,7 +66,8 @@ def clipboard_to_changelog(sheet, start_column, start_row):
@click.command()
@click.option("-s", "--sheet", prompt=True, required=True, default="Input_Data_*")
@click.option("-w", "--well", prompt=True, required=True, default="A1")
def cli(sheet, well):
@click.option("-c", "--compact", is_flag=True)
def cli(sheet, well, compact):
regex_well = r"(?P<column>[A-Z]{1,2})(?P<row>\d+)"
match = re.match(regex_well, well.upper())
if match is None:
@ -71,4 +75,4 @@ def cli(sheet, well): @@ -71,4 +75,4 @@ def cli(sheet, well):
regex_result = match.groupdict()
start_column = regex_result["column"]
start_row = int(regex_result["row"])
clipboard_to_changelog(sheet, start_column, start_row)
clipboard_to_changelog(sheet, start_column, start_row, compact)

Loading…
Cancel
Save