Browse Source

new command: sg_mbp_new_version

master
Holger Frey 4 years ago
parent
commit
744ad860e1
  1. 25
      README.md
  2. 4
      pyproject.toml
  3. 3
      work_helpers/_natural_sort.py
  4. 2
      work_helpers/excel2changelog.py
  5. 87
      work_helpers/sg_mbp_release.py

25
README.md

@ -3,6 +3,27 @@ work-helpers
Some helper scripts for the day to day work with Ubuntu in WSL2 Some helper scripts for the day to day work with Ubuntu in WSL2
- **sg_mbp_new_version**: creates a new version folder, new excel changes files and modifies the overall changelog
- **xls2changelog**: reformat copied excel data to the safeguard changelog format
- **sg_mbp_release**: collect and annotate all files used for a safeguard workbook release - **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

4
pyproject.toml

@ -14,9 +14,11 @@ license = "Beerware"
requires = [ requires = [
"pyperclip >=1.8.0", "pyperclip >=1.8.0",
"click >= 7.1.2", "click >= 7.1.2",
"black",
] ]
[tool.flit.scripts] [tool.flit.scripts]
xls2changelog = "work_helpers.excel2changelog:cli" 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"

3
work_helpers/_natural_sort.py

@ -21,8 +21,7 @@ def _nartural_sort_convert(text):
def _nartural_sort_alphanum_key(text): def _nartural_sort_alphanum_key(text):
return tuple( return tuple(
_nartural_sort_convert(part) _nartural_sort_convert(part) for part in _NATURAL_SORT_REGEX_DIGITS.split(text)
for part in _NATURAL_SORT_REGEX_DIGITS.split(text)
) )

2
work_helpers/excel2changelog.py

@ -9,7 +9,6 @@ for prefix in a2z:
EXCEL_COLUMNS.extend(further) EXCEL_COLUMNS.extend(further)
sheet = "Input_Data_*" sheet = "Input_Data_*"
col_start = "A" col_start = "A"
row_start = 8 row_start = 8
@ -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()) last_line = next(l for l in result[::-1] if l.strip())
print(last_line) print(last_line)
pyperclip.copy("\r\n".join(result)) pyperclip.copy("\r\n".join(result))

87
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") 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): def _folder_content(folder):
nondotted = (i for i in folder.iterdir() if not i.stem.startswith(".")) 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] 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): def copy_changelog(destination, date, latest):
textfiles = _files_in_folder(PATH_ISSUES, ".txt") textfiles = _files_in_folder(PATH_ISSUES, ".txt")
changelog = next(f for f in textfiles if f.stem.lower().startswith("change")) 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() @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: Before running this command:

Loading…
Cancel
Save