From d4b7173cf4a36a90d3fa3c1092b13fc3edc2c85f Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Jun 2024 20:50:30 -0400 Subject: [PATCH 1/3] [525] Update Reddit and HTML Changelog --- .gitignore | 3 +- requirements-dev.txt | 2 +- scripts/build_changelog.py | 107 +++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 scripts/build_changelog.py diff --git a/.gitignore b/.gitignore index 778820c6..1df2f666 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,9 @@ build dist.win32/ dist.* -# Ignore generated ChangeLog.html file +# Ignore generated ChangeLog files ChangeLog.html +/scripts/script_output # Ignore files dump diff --git a/requirements-dev.txt b/requirements-dev.txt index 7c8e1ef5..05c5ad29 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -31,7 +31,7 @@ autopep8==2.2.0 pre-commit==3.7.1 # HTML changelogs -grip==4.6.2 +mistune==3.0.2 # Packaging # We only need py2exe on windows. diff --git a/scripts/build_changelog.py b/scripts/build_changelog.py new file mode 100644 index 00000000..ce266fd7 --- /dev/null +++ b/scripts/build_changelog.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 +# flake8: noqa +""" +build_changelog.py - Read the latest changelog file and format for the Forums and Reddit. + +Copyright (c) EDCD, All Rights Reserved +Licensed under the GNU General Public License. +See LICENSE file. +""" +import pathlib +import re +from os import chdir +import mistune + + +def get_changelog() -> str: + """Pull the last full changelog details in MD.""" + with open("../CHANGELOG.md", encoding="utf-8") as changelog_file: + content = changelog_file.read() + changelog_list: list = content.split("---", maxsplit=2) + changelog = changelog_list[2] + changelog_list = changelog.split("===", maxsplit=2) + changelog_list[0] = changelog_list[0].rstrip() + changelog_list[0] = changelog_list[0].lstrip() + changelog_list[0] += "\n===" + changelog_list[1] = changelog_list[1].rstrip() + changelog_list[1] = "\n".join(changelog_list[1].split("\n")[:-2]) + changelog = changelog_list[0] + changelog_list[1] + changelog = changelog.rstrip() + return changelog + + +def build_html(md_changelog) -> None: + html_out = mistune.html(md_changelog) + html_out = re.sub("h1", "h2", html_out) + html_out += "\n
" + with open("script_output/html_changelog.txt", "w", encoding="utf-8") as html_file: + html_file.write(html_out) + + +def build_reddit( + md_changelog: str, vt_signed: str, vt_unsigned: str, version: str, gh_link: str +) -> None: + reddit_start = """# What Is Elite Dangerous Market Connector? + +Elite Dangerous Market Connector ("EDMC") is a third-party application for use with Frontier Developments' game "Elite Dangerous". Its purpose is to facilitate supplying certain game data to, and in some cases retrieving it from, a number of websites and other tools. + +To achieve this it utilizes the Journal Files written by the game when played on a PC. It also makes use of Frontier's Companion API ("Frontier's CAPI"), accessible once you've authorized this application. + +EDMC has a plugin system that many other developers have made use of to extend its functionality. + +Find out more on the [EDMC Wiki](https://github.com/EDCD/EDMarketConnector/wiki). + +~~----------------------------------------------------~~ + +You can also view the Elite: Dangerous Forum thread [HERE](https://forums.frontier.co.uk/threads/elite-dangerous-market-connector-edmc.618708/). + +~~----------------------------------------------------~~ + +**As has become routine now, various anti-virus software are reporting a false positive on our installer and/or files it contains. We've pre-emptively uploaded the installer to** [VirusTotal]( +""" + reddit_mid_1 = """) **if you want to check what it's saying. Please see our** [Troubleshooting/AV-false-positives FAQ](https://github.com/EDCD/EDMarketConnector/wiki/Troubleshooting#installer-and-or-executables-flagged-as-malicious-viruses) **for further information.** + +[Unsigned Installer](""" + + reddit_mid_2 = """) if you don't want to use the code-signed option. + +~~----------------------------------------------------~~ +""" + versionsearch = f"Release {version}" + updated = f"# [Release {version}]({gh_link})" + md_changelog = re.sub("===\n", "", md_changelog) + md_changelog = re.sub(versionsearch, updated, md_changelog) + reddit_end = f""" + +**Linux** + +If you're running on Linux, try the [Flatpak](https://flathub.org/apps/io.edcd.EDMarketConnector) build of EDMC! (Update to {version} coming soon.)""" + + reddit_out = ( + reddit_start + + vt_signed + + reddit_mid_1 + + vt_unsigned + + reddit_mid_2 + + md_changelog + + reddit_end + ) + with open( + "script_output/reddit_changelog.txt", "w", encoding="utf-8" + ) as reddit_file: + reddit_file.write(reddit_out) + + +def main() -> None: + vt_signed = input("Please enter the VirusTotal URL for the Signed Installer: ") + vt_unsigned = input("Please enter the VirusTotal URL for the Unsigned Installer: ") + version = input("Please enter the version of EDMC: ") + gh_link = input(f"Please enter the GitHub link for {version}: ") + md_changelog = get_changelog() + build_reddit(md_changelog, vt_signed, vt_unsigned, version, gh_link) + build_html(md_changelog) + + +if __name__ == "__main__": + chdir(pathlib.Path(__file__).parent) + main() From 340c9818fcecc60af66f14f405342d50f79c8cbf Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Jun 2024 21:22:24 -0400 Subject: [PATCH 2/3] [525] Add FDEV Forum Post --- scripts/build_changelog.py | 65 ++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/scripts/build_changelog.py b/scripts/build_changelog.py index ce266fd7..c4772a83 100644 --- a/scripts/build_changelog.py +++ b/scripts/build_changelog.py @@ -13,7 +13,7 @@ from os import chdir import mistune -def get_changelog() -> str: +def get_changelog() -> tuple[str, str]: """Pull the last full changelog details in MD.""" with open("../CHANGELOG.md", encoding="utf-8") as changelog_file: content = changelog_file.read() @@ -27,15 +27,65 @@ def get_changelog() -> str: changelog_list[1] = "\n".join(changelog_list[1].split("\n")[:-2]) changelog = changelog_list[0] + changelog_list[1] changelog = changelog.rstrip() - return changelog + version = changelog.split("\n")[0] + version = version.split(" ")[1] + return changelog, version -def build_html(md_changelog) -> None: +def build_html(md_changelog) -> str: html_out = mistune.html(md_changelog) html_out = re.sub("h1", "h2", html_out) html_out += "\n
" with open("script_output/html_changelog.txt", "w", encoding="utf-8") as html_file: html_file.write(html_out) + return html_out + + +def build_fdev( + vt_signed: str, + vt_unsigned: str, + version: str, + gh_link: str, + html: str, +) -> None: + fdev_out = ( + "[HEADING=2][URL='" + + gh_link + + "'][SIZE=7]Release " + + version + + "[/SIZE][/URL][/HEADING]\n[URL='" + + vt_signed + ) + fdev_out += ( + "']Pre-emptive upload to VirusTotal[/URL]. ([URL='" + + vt_unsigned + + "']Unsigned Installer[/URL])\n\n" + ) + + if version.startswith("Pre-Release") or version.startswith("Beta"): + fdev_out += f'This is a release candidate for {version}. It has been pushed to the "Beta" track for updates!' + fdev_out += ( + '\n\nFor more information on the "Beta" update track, please read ' + "[URL='https://github.com/EDCD/EDMarketConnector/wiki/Participating-in-Open-Betas-of-EDMC']" + "This Wiki Article[/URL]. Questions and comments are welcome!\n\n" + ) + changelog_trim = html.split("\n", maxsplit=1) + md_log = changelog_trim[1] + md_log = re.sub("

", "", md_log) + md_log = re.sub("

", "", md_log) + md_log = re.sub("", "\n[HEADING=3]", md_log) + md_log = re.sub("", "[/HEADING]", md_log) + md_log = re.sub("\n", "[/LIST]", md_log) + fdev_out += md_log + + with open("script_output/fdev_changelog.txt", "w", encoding="utf-8") as fdev_file: + fdev_file.write(fdev_out) + return def build_reddit( @@ -93,13 +143,14 @@ If you're running on Linux, try the [Flatpak](https://flathub.org/apps/io.edcd.E def main() -> None: + md_changelog, version = get_changelog() + print(f"Detected version {version} in the changelog. Continuing...") + gh_link = input(f"Please enter the GitHub link for {version}: ") vt_signed = input("Please enter the VirusTotal URL for the Signed Installer: ") vt_unsigned = input("Please enter the VirusTotal URL for the Unsigned Installer: ") - version = input("Please enter the version of EDMC: ") - gh_link = input(f"Please enter the GitHub link for {version}: ") - md_changelog = get_changelog() build_reddit(md_changelog, vt_signed, vt_unsigned, version, gh_link) - build_html(md_changelog) + html = build_html(md_changelog) + build_fdev(vt_signed, vt_unsigned, version, gh_link, html) if __name__ == "__main__": From 33f8e9c83707431ca5e4cd1f16120d0220ad1d1f Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Sun, 9 Jun 2024 21:51:56 -0400 Subject: [PATCH 3/3] [525] Cleanup Script --- scripts/build_changelog.py | 125 ++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 59 deletions(-) diff --git a/scripts/build_changelog.py b/scripts/build_changelog.py index c4772a83..f0c01994 100644 --- a/scripts/build_changelog.py +++ b/scripts/build_changelog.py @@ -7,6 +7,7 @@ Copyright (c) EDCD, All Rights Reserved Licensed under the GNU General Public License. See LICENSE file. """ + import pathlib import re from os import chdir @@ -15,82 +16,87 @@ import mistune def get_changelog() -> tuple[str, str]: """Pull the last full changelog details in MD.""" - with open("../CHANGELOG.md", encoding="utf-8") as changelog_file: - content = changelog_file.read() - changelog_list: list = content.split("---", maxsplit=2) - changelog = changelog_list[2] - changelog_list = changelog.split("===", maxsplit=2) - changelog_list[0] = changelog_list[0].rstrip() - changelog_list[0] = changelog_list[0].lstrip() - changelog_list[0] += "\n===" - changelog_list[1] = changelog_list[1].rstrip() - changelog_list[1] = "\n".join(changelog_list[1].split("\n")[:-2]) - changelog = changelog_list[0] + changelog_list[1] - changelog = changelog.rstrip() - version = changelog.split("\n")[0] - version = version.split(" ")[1] - return changelog, version + try: + with open("../CHANGELOG.md", encoding="utf-8") as changelog_file: + content = changelog_file.read() + except FileNotFoundError as exc: + raise FileNotFoundError("Changelog file not found.") from exc + + changelog_list = content.split("---", maxsplit=2) + if len(changelog_list) < 3: + raise ValueError("Changelog format is incorrect.") + + changelog = changelog_list[2].split("===", maxsplit=2) + if len(changelog) < 2: + raise ValueError("Changelog format is incorrect.") + + changelog[0] = changelog[0].strip() + changelog[1] = "\n".join(changelog[1].strip().split("\n")[:-2]) + version = changelog[0] + version = version.split(" ")[1] + changelog = changelog[1].strip() + + return changelog, version -def build_html(md_changelog) -> str: - html_out = mistune.html(md_changelog) - html_out = re.sub("h1", "h2", html_out) - html_out += "\n
" +def build_html(md_changelog: str, version: str) -> str: + """Convert markdown changelog to HTML.""" + html_out = f"

Release {version}

\n" + html_out += mistune.html(md_changelog) + html_out = re.sub(r"h1", "h2", html_out) + "\n
" + with open("script_output/html_changelog.txt", "w", encoding="utf-8") as html_file: html_file.write(html_out) + return html_out +def format_fdev(md_log: str) -> str: + """Format changelog for FDEV forums.""" + md_log = re.sub(r"

|

", "", md_log) + md_log = re.sub(r"", "\n[HEADING=3]", md_log) + md_log = re.sub(r"", "[/HEADING]", md_log) + md_log = re.sub(r"
    ", "[LIST]", md_log) + md_log = re.sub(r"
  • ", "[*]", md_log) + md_log = re.sub(r"
  • ", "", md_log) + md_log = re.sub(r"", "[ICODE]", md_log) + md_log = re.sub(r"", "[/ICODE]", md_log) + md_log = re.sub(r"
\n", "[/LIST]", md_log) + md_log = re.sub(r"
", "", md_log) + md_log = re.sub(r"Changes and Enhancements", "What's Changed", md_log) + return md_log + + def build_fdev( - vt_signed: str, - vt_unsigned: str, - version: str, - gh_link: str, - html: str, + vt_signed: str, vt_unsigned: str, version: str, gh_link: str, html: str ) -> None: + """Build changelog for FDEV forums.""" fdev_out = ( - "[HEADING=2][URL='" - + gh_link - + "'][SIZE=7]Release " - + version - + "[/SIZE][/URL][/HEADING]\n[URL='" - + vt_signed - ) - fdev_out += ( - "']Pre-emptive upload to VirusTotal[/URL]. ([URL='" - + vt_unsigned - + "']Unsigned Installer[/URL])\n\n" + f"[HEADING=2][URL='{gh_link}'][SIZE=7]Release {version}[/SIZE][/URL][/HEADING]\n" + f"[URL='{vt_signed}']Pre-emptive upload to VirusTotal[/URL]. " + f"([URL='{vt_unsigned}']Unsigned Installer[/URL])\n\n" ) - if version.startswith("Pre-Release") or version.startswith("Beta"): - fdev_out += f'This is a release candidate for {version}. It has been pushed to the "Beta" track for updates!' + if version.startswith(("Pre-Release", "Beta")): fdev_out += ( - '\n\nFor more information on the "Beta" update track, please read ' + f'This is a release candidate for {version}. It has been pushed to the "Beta" track for updates!\n\n' + 'For more information on the "Beta" update track, please read ' "[URL='https://github.com/EDCD/EDMarketConnector/wiki/Participating-in-Open-Betas-of-EDMC']" "This Wiki Article[/URL]. Questions and comments are welcome!\n\n" ) - changelog_trim = html.split("\n", maxsplit=1) - md_log = changelog_trim[1] - md_log = re.sub("

", "", md_log) - md_log = re.sub("

", "", md_log) - md_log = re.sub("", "\n[HEADING=3]", md_log) - md_log = re.sub("", "[/HEADING]", md_log) - md_log = re.sub("
    ", "[LIST]", md_log) - md_log = re.sub("
  • ", "[*]", md_log) - md_log = re.sub("
  • ", "", md_log) - md_log = re.sub("", "[ICODE]", md_log) - md_log = re.sub("", "[/ICODE]", md_log) - md_log = re.sub("
\n", "[/LIST]", md_log) + + md_log = html.split("\n", maxsplit=1)[1] + md_log = format_fdev(md_log) fdev_out += md_log with open("script_output/fdev_changelog.txt", "w", encoding="utf-8") as fdev_file: fdev_file.write(fdev_out) - return def build_reddit( md_changelog: str, vt_signed: str, vt_unsigned: str, version: str, gh_link: str ) -> None: + """Build changelog for Reddit.""" reddit_start = """# What Is Elite Dangerous Market Connector? Elite Dangerous Market Connector ("EDMC") is a third-party application for use with Frontier Developments' game "Elite Dangerous". Its purpose is to facilitate supplying certain game data to, and in some cases retrieving it from, a number of websites and other tools. @@ -107,9 +113,8 @@ You can also view the Elite: Dangerous Forum thread [HERE](https://forums.fronti ~~----------------------------------------------------~~ -**As has become routine now, various anti-virus software are reporting a false positive on our installer and/or files it contains. We've pre-emptively uploaded the installer to** [VirusTotal]( -""" - reddit_mid_1 = """) **if you want to check what it's saying. Please see our** [Troubleshooting/AV-false-positives FAQ](https://github.com/EDCD/EDMarketConnector/wiki/Troubleshooting#installer-and-or-executables-flagged-as-malicious-viruses) **for further information.** +**As has become routine now, various anti-virus software are reporting a false positive on our installer and/or files it contains. We've pre-emptively uploaded the installer to** [VirusTotal](""" + reddit_mid_1 = """) **if you want to check what it's saying. Please see our** [Troubleshooting/AV-false-positives FAQ](https://github.com/EDCD/EDMarketConnector/wiki/Troubleshooting#installer-and-or-executables-flagged-as-malicious-viruses) **for further information.** [Unsigned Installer](""" @@ -117,10 +122,9 @@ You can also view the Elite: Dangerous Forum thread [HERE](https://forums.fronti ~~----------------------------------------------------~~ """ - versionsearch = f"Release {version}" - updated = f"# [Release {version}]({gh_link})" - md_changelog = re.sub("===\n", "", md_changelog) - md_changelog = re.sub(versionsearch, updated, md_changelog) + updated = f"# [Release {version}]({gh_link})\n\n" + md_changelog = re.sub(r"===\n", "", md_changelog) + md_changelog = re.sub(f"Release {version}", updated, md_changelog) reddit_end = f""" **Linux** @@ -133,9 +137,11 @@ If you're running on Linux, try the [Flatpak](https://flathub.org/apps/io.edcd.E + reddit_mid_1 + vt_unsigned + reddit_mid_2 + + updated + md_changelog + reddit_end ) + with open( "script_output/reddit_changelog.txt", "w", encoding="utf-8" ) as reddit_file: @@ -143,13 +149,14 @@ If you're running on Linux, try the [Flatpak](https://flathub.org/apps/io.edcd.E def main() -> None: + """Run the Changelog Generator""" md_changelog, version = get_changelog() print(f"Detected version {version} in the changelog. Continuing...") gh_link = input(f"Please enter the GitHub link for {version}: ") vt_signed = input("Please enter the VirusTotal URL for the Signed Installer: ") vt_unsigned = input("Please enter the VirusTotal URL for the Unsigned Installer: ") build_reddit(md_changelog, vt_signed, vt_unsigned, version, gh_link) - html = build_html(md_changelog) + html = build_html(md_changelog, version) build_fdev(vt_signed, vt_unsigned, version, gh_link, html)