Browse Source

first version of excel to changelog script

master
Holger Frey 5 years ago
parent
commit
8d15bee1ee
  1. 2
      .gitignore
  2. 3
      linux_helpers/__init__.py
  3. 76
      linux_helpers/excel2changelog.py
  4. 21
      pyproject.toml

2
.gitignore vendored

@ -118,3 +118,5 @@ $RECYCLE.BIN/ @@ -118,3 +118,5 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk
# Editors
.vscode

3
linux_helpers/__init__.py

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
""" Some helper scripts for the day to day work with Ubuntu in WSL2 """
__version__ = "0.0.1"

76
linux_helpers/excel2changelog.py

@ -0,0 +1,76 @@ @@ -0,0 +1,76 @@
import click
import re
import pyperclip
a2z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
EXCEL_COLUMNS = list(a2z)
for prefix in a2z:
further = [prefix + c for c in a2z]
EXCEL_COLUMNS.extend(further)
sheet = "Input_Data_*"
col_start = "A"
row_start = 8
def text_to_changelog(raw_text, sheet, start_column, start_row):
cells = [line.split("\t") for line in raw_text.splitlines()]
output = []
current_row = 1
columns_start_index = EXCEL_COLUMNS.index(start_column)
columns_used = EXCEL_COLUMNS[columns_start_index:]
for row, line in enumerate(cells, start=start_row):
if row != current_row:
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}")
iterator = iter(output)
prev = next(iterator)
yield prev
for current in iterator:
if current != prev:
yield current
prev = current
def clipboard_to_changelog(sheet, start_column, start_row):
xls = pyperclip.paste()
result = list(text_to_changelog(xls, sheet, start_column, start_row))
line_count = len(result)
if line_count == 1:
print(f"Copied one line to the clipboard")
print(result[0])
else:
print(f"Copied {line_count} lines to the clipboard")
first_line = next(l for l in result if l.strip())
print(first_line)
print("...")
last_line = next(l for l in result[::-1] if l.strip())
print(last_line)
pyperclip.copy("\r\n".join(result))
@click.command()
@click.option("-s", "--sheet", prompt=True, required=True)
@click.option("-w", "--well", prompt=True, required=True)
def cli(sheet, well):
regex_well = r"(?P<column>[A-Z]{1,2})(?P<row>\d+)"
match = re.match(regex_well, well.upper())
if match is None:
raise ValueError(f"No Excel Well: {well}")
regex_result = match.groupdict()
start_column = regex_result["column"]
start_row = int(regex_result["row"])
clipboard_to_changelog(sheet, start_column, start_row)

21
pyproject.toml

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"
[tool.flit.metadata]
module = "linux_helpers"
author = "Holger Frey"
author-email = "frey@imtek.de"
home-page = "https://git.cpi.imtek.uni-freiburg.de/holgi/linux-helpers"
description-file = "README.md"
license = "Beerware"
requires = [
"pyperclip >=1.8.0",
"click >= 7.1.2",
]
[tool.flit.scripts]
xls2changelog = "linux_helpers.excel2changelog:cli"
Loading…
Cancel
Save