From 744ad860e1faa2182105e5b9fcfee9ca3ca6ee45 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Wed, 7 Oct 2020 12:23:18 +0200 Subject: [PATCH] new command: sg_mbp_new_version --- README.md | 25 +++++++++- pyproject.toml | 4 +- work_helpers/_natural_sort.py | 3 +- work_helpers/excel2changelog.py | 4 +- work_helpers/sg_mbp_release.py | 87 ++++++++++++++++++++++++++++++++- 5 files changed, 114 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b208ad6..f919057 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,27 @@ work-helpers Some helper scripts for the day to day work with Ubuntu in WSL2 - - - **xls2changelog**: reformat copied excel data to the safeguard changelog format + - **sg_mbp_new_version**: creates a new version folder, new excel changes files and modifies the overall changelog - **sg_mbp_release**: collect and annotate all files used for a safeguard workbook release + - **xls2changelog**: reformat copied excel data to the safeguard changelog format + + +Proposed workflow for Safeguard projects +---------------------------------------- + +1. create a new version in the issues repo folder "E:\Safeguard-MBP-issues" with `sg_mbp_new_version` +2. make your required edits in the workbooks and record the changes in the excel changelog files using `xls2changelog` +3. edit the changelog file in "E:\Safeguard-MBP-issues" +4. pack everything together for a release with `sg_mbp_release` + + +sg_mbp_release +-------------- + +Before running this command: + - make the required edits to the workbooks + - create a new versions folder in "E:\Safeguard-MBP-issues", e.g. "v3.9.49" (try the new `sg_mbp_new_version` command for this) + - note the changes in the excel changelogs in the created version folder + - edit the changelog in "E:\Safeguard-MBP-issues" + +The command will collect all data into one folder on the Desktop to be published \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index b46dd80..bb1924b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,9 +14,11 @@ license = "Beerware" requires = [ "pyperclip >=1.8.0", "click >= 7.1.2", + "black", ] [tool.flit.scripts] xls2changelog = "work_helpers.excel2changelog:cli" -sg_mbp_release = "work_helpers.sg_mbp_release:cli" +sg_mbp_release = "work_helpers.sg_mbp_release:sg_mbp_release" +sg_mbp_new_version = "work_helpers.sg_mbp_release:sg_mbp_new_version" diff --git a/work_helpers/_natural_sort.py b/work_helpers/_natural_sort.py index 4f0ac21..84cc098 100644 --- a/work_helpers/_natural_sort.py +++ b/work_helpers/_natural_sort.py @@ -21,8 +21,7 @@ def _nartural_sort_convert(text): def _nartural_sort_alphanum_key(text): return tuple( - _nartural_sort_convert(part) - for part in _NATURAL_SORT_REGEX_DIGITS.split(text) + _nartural_sort_convert(part) for part in _NATURAL_SORT_REGEX_DIGITS.split(text) ) diff --git a/work_helpers/excel2changelog.py b/work_helpers/excel2changelog.py index 3d5a4c0..e52bebf 100644 --- a/work_helpers/excel2changelog.py +++ b/work_helpers/excel2changelog.py @@ -9,7 +9,6 @@ for prefix in a2z: EXCEL_COLUMNS.extend(further) - sheet = "Input_Data_*" col_start = "A" row_start = 8 @@ -32,7 +31,7 @@ def text_to_changelog(raw_text, sheet, start_column, start_row): if not cell: continue output.append(f"{sheet}\t{column}{row}\t{cell}") - + iterator = iter(output) prev = next(iterator) yield prev @@ -58,7 +57,6 @@ def clipboard_to_changelog(sheet, start_column, start_row): last_line = next(l for l in result[::-1] if l.strip()) print(last_line) - pyperclip.copy("\r\n".join(result)) diff --git a/work_helpers/sg_mbp_release.py b/work_helpers/sg_mbp_release.py index 10d8691..72c38bf 100644 --- a/work_helpers/sg_mbp_release.py +++ b/work_helpers/sg_mbp_release.py @@ -13,6 +13,21 @@ PATH_WIN_DESKTOP = Path("/mnt/c/Users/Holgi/Desktop") TODAY = datetime.now().strftime("%y%m%d") +CRLF = "\r\n" + +EXCEL_CHANGELOGS = { + "changes_hyb_workbook": "J1", + "changes_qc_cy5_workbook": "J1", + "changes_qc_dry_workbook": "L1", + "changes_qc_workbook": "J1", +} + +EXCEL_CHANGELOG_HEADERS = [ + "Sheet\tWell\tContents\tComment", + "-----\t----\t--------\t-------", + "", +] + def _folder_content(folder): nondotted = (i for i in folder.iterdir() if not i.stem.startswith(".")) @@ -30,6 +45,55 @@ def get_latest_version(parent=PATH_ISSUES): return versions[-1] +def get_next_version(parent=PATH_ISSUES, echo_current=True): + latest = get_latest_version(parent) + if echo_current: + print("current version:", latest) + + try: + head, tail = latest.rsplit(".", 1) + next_minor = int(tail) + 1 + next_version = f"{head}.{next_minor}" + except: + next_version = "" + + return next_version + + +def create_new_version_folder(new_version, parent=PATH_ISSUES): + new_folder_path = parent / new_version + if new_folder_path.exists(): + print(f"Folder for version {new_version} already exists, aborting") + return + new_folder_path.mkdir() + return new_folder_path + + +def create_excel_changelogs(new_version, parent): + for name, cell in EXCEL_CHANGELOGS.items(): + new_file = parent / f"{name}_{new_version}.txt" + with new_file.open("w") as fh: + data_line = "\t".join(["Settings", cell, new_version, ""]) + content_lines = EXCEL_CHANGELOG_HEADERS + [data_line, "", ""] + fh.write(CRLF.join(content_lines)) + + +def create_changelog_entry(new_version, parent=PATH_ISSUES): + textfiles = _files_in_folder(parent, ".txt") + changelog = next(f for f in textfiles if f.stem.lower().startswith("change")) + content = [] + with changelog.open("r") as fh: + stripped_lines = (line.rstrip() for line in fh) + for line in stripped_lines: + content.append(line) + if line.startswith("----"): + content.append("") + content.append(f"{new_version}, work in progress:") + content.append(" - describe your changes here") + with changelog.open("w") as fh: + fh.write(CRLF.join(content)) + + def copy_changelog(destination, date, latest): textfiles = _files_in_folder(PATH_ISSUES, ".txt") changelog = next(f for f in textfiles if f.stem.lower().startswith("change")) @@ -60,7 +124,28 @@ def copy_workbooks(destination, date, latest): @click.command() -def cli(): +@click.option( + "-v", + "--version", + required=True, + prompt="new version", + default=get_next_version, + show_default="next minor version", +) +def sg_mbp_new_version(version): + """ + creates a new version folder, new excel changes files and modifies the overall changelog + in "E:\Safeguard-MBP-issues" + """ + + folder = create_new_version_folder(version) + if folder is not None: + create_excel_changelogs(version, folder) + create_changelog_entry(version) + + +@click.command() +def sg_mbp_release(): """ Before running this command: