mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-06 10:23:06 +03:00
[525] Cleanup Script
This commit is contained in:
parent
340c9818fc
commit
33f8e9c837
@ -7,6 +7,7 @@ Copyright (c) EDCD, All Rights Reserved
|
|||||||
Licensed under the GNU General Public License.
|
Licensed under the GNU General Public License.
|
||||||
See LICENSE file.
|
See LICENSE file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
from os import chdir
|
from os import chdir
|
||||||
@ -15,82 +16,87 @@ import mistune
|
|||||||
|
|
||||||
def get_changelog() -> tuple[str, str]:
|
def get_changelog() -> tuple[str, str]:
|
||||||
"""Pull the last full changelog details in MD."""
|
"""Pull the last full changelog details in MD."""
|
||||||
|
try:
|
||||||
with open("../CHANGELOG.md", encoding="utf-8") as changelog_file:
|
with open("../CHANGELOG.md", encoding="utf-8") as changelog_file:
|
||||||
content = changelog_file.read()
|
content = changelog_file.read()
|
||||||
changelog_list: list = content.split("---", maxsplit=2)
|
except FileNotFoundError as exc:
|
||||||
changelog = changelog_list[2]
|
raise FileNotFoundError("Changelog file not found.") from exc
|
||||||
changelog_list = changelog.split("===", maxsplit=2)
|
|
||||||
changelog_list[0] = changelog_list[0].rstrip()
|
changelog_list = content.split("---", maxsplit=2)
|
||||||
changelog_list[0] = changelog_list[0].lstrip()
|
if len(changelog_list) < 3:
|
||||||
changelog_list[0] += "\n==="
|
raise ValueError("Changelog format is incorrect.")
|
||||||
changelog_list[1] = changelog_list[1].rstrip()
|
|
||||||
changelog_list[1] = "\n".join(changelog_list[1].split("\n")[:-2])
|
changelog = changelog_list[2].split("===", maxsplit=2)
|
||||||
changelog = changelog_list[0] + changelog_list[1]
|
if len(changelog) < 2:
|
||||||
changelog = changelog.rstrip()
|
raise ValueError("Changelog format is incorrect.")
|
||||||
version = changelog.split("\n")[0]
|
|
||||||
|
changelog[0] = changelog[0].strip()
|
||||||
|
changelog[1] = "\n".join(changelog[1].strip().split("\n")[:-2])
|
||||||
|
version = changelog[0]
|
||||||
version = version.split(" ")[1]
|
version = version.split(" ")[1]
|
||||||
|
changelog = changelog[1].strip()
|
||||||
|
|
||||||
return changelog, version
|
return changelog, version
|
||||||
|
|
||||||
|
|
||||||
def build_html(md_changelog) -> str:
|
def build_html(md_changelog: str, version: str) -> str:
|
||||||
html_out = mistune.html(md_changelog)
|
"""Convert markdown changelog to HTML."""
|
||||||
html_out = re.sub("h1", "h2", html_out)
|
html_out = f"<h2>Release {version}</h2>\n"
|
||||||
html_out += "\n<hr>"
|
html_out += mistune.html(md_changelog)
|
||||||
|
html_out = re.sub(r"h1", "h2", html_out) + "\n<hr>"
|
||||||
|
|
||||||
with open("script_output/html_changelog.txt", "w", encoding="utf-8") as html_file:
|
with open("script_output/html_changelog.txt", "w", encoding="utf-8") as html_file:
|
||||||
html_file.write(html_out)
|
html_file.write(html_out)
|
||||||
|
|
||||||
return html_out
|
return html_out
|
||||||
|
|
||||||
|
|
||||||
|
def format_fdev(md_log: str) -> str:
|
||||||
|
"""Format changelog for FDEV forums."""
|
||||||
|
md_log = re.sub(r"<p>|</p>", "", md_log)
|
||||||
|
md_log = re.sub(r"<strong>", "\n[HEADING=3]", md_log)
|
||||||
|
md_log = re.sub(r"</strong>", "[/HEADING]", md_log)
|
||||||
|
md_log = re.sub(r"<ul>", "[LIST]", md_log)
|
||||||
|
md_log = re.sub(r"<li>", "[*]", md_log)
|
||||||
|
md_log = re.sub(r"</li>", "", md_log)
|
||||||
|
md_log = re.sub(r"<code>", "[ICODE]", md_log)
|
||||||
|
md_log = re.sub(r"</code>", "[/ICODE]", md_log)
|
||||||
|
md_log = re.sub(r"</ul>\n", "[/LIST]", md_log)
|
||||||
|
md_log = re.sub(r"<hr>", "", md_log)
|
||||||
|
md_log = re.sub(r"Changes and Enhancements", "What's Changed", md_log)
|
||||||
|
return md_log
|
||||||
|
|
||||||
|
|
||||||
def build_fdev(
|
def build_fdev(
|
||||||
vt_signed: str,
|
vt_signed: str, vt_unsigned: str, version: str, gh_link: str, html: str
|
||||||
vt_unsigned: str,
|
|
||||||
version: str,
|
|
||||||
gh_link: str,
|
|
||||||
html: str,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
|
"""Build changelog for FDEV forums."""
|
||||||
fdev_out = (
|
fdev_out = (
|
||||||
"[HEADING=2][URL='"
|
f"[HEADING=2][URL='{gh_link}'][SIZE=7]Release {version}[/SIZE][/URL][/HEADING]\n"
|
||||||
+ gh_link
|
f"[URL='{vt_signed}']Pre-emptive upload to VirusTotal[/URL]. "
|
||||||
+ "'][SIZE=7]Release "
|
f"([URL='{vt_unsigned}']Unsigned Installer[/URL])\n\n"
|
||||||
+ 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"):
|
if version.startswith(("Pre-Release", "Beta")):
|
||||||
fdev_out += f'This is a release candidate for {version}. It has been pushed to the "Beta" track for updates!'
|
|
||||||
fdev_out += (
|
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']"
|
"[URL='https://github.com/EDCD/EDMarketConnector/wiki/Participating-in-Open-Betas-of-EDMC']"
|
||||||
"This Wiki Article[/URL]. Questions and comments are welcome!\n\n"
|
"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 = html.split("\n", maxsplit=1)[1]
|
||||||
md_log = re.sub("<p>", "", md_log)
|
md_log = format_fdev(md_log)
|
||||||
md_log = re.sub("</p>", "", md_log)
|
|
||||||
md_log = re.sub("<strong>", "\n[HEADING=3]", md_log)
|
|
||||||
md_log = re.sub("</strong>", "[/HEADING]", md_log)
|
|
||||||
md_log = re.sub("<ul>", "[LIST]", md_log)
|
|
||||||
md_log = re.sub("<li>", "[*]", md_log)
|
|
||||||
md_log = re.sub("</li>", "", md_log)
|
|
||||||
md_log = re.sub("<code>", "[ICODE]", md_log)
|
|
||||||
md_log = re.sub("</code>", "[/ICODE]", md_log)
|
|
||||||
md_log = re.sub("</ul>\n", "[/LIST]", md_log)
|
|
||||||
fdev_out += md_log
|
fdev_out += md_log
|
||||||
|
|
||||||
with open("script_output/fdev_changelog.txt", "w", encoding="utf-8") as fdev_file:
|
with open("script_output/fdev_changelog.txt", "w", encoding="utf-8") as fdev_file:
|
||||||
fdev_file.write(fdev_out)
|
fdev_file.write(fdev_out)
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def build_reddit(
|
def build_reddit(
|
||||||
md_changelog: str, vt_signed: str, vt_unsigned: str, version: str, gh_link: str
|
md_changelog: str, vt_signed: str, vt_unsigned: str, version: str, gh_link: str
|
||||||
) -> None:
|
) -> None:
|
||||||
|
"""Build changelog for Reddit."""
|
||||||
reddit_start = """# What Is Elite Dangerous Market Connector?
|
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.
|
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,8 +113,7 @@ 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](
|
**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.**
|
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]("""
|
[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})\n\n"
|
||||||
updated = f"# [Release {version}]({gh_link})"
|
md_changelog = re.sub(r"===\n", "", md_changelog)
|
||||||
md_changelog = re.sub("===\n", "", md_changelog)
|
md_changelog = re.sub(f"Release {version}", updated, md_changelog)
|
||||||
md_changelog = re.sub(versionsearch, updated, md_changelog)
|
|
||||||
reddit_end = f"""
|
reddit_end = f"""
|
||||||
|
|
||||||
**Linux**
|
**Linux**
|
||||||
@ -133,9 +137,11 @@ If you're running on Linux, try the [Flatpak](https://flathub.org/apps/io.edcd.E
|
|||||||
+ reddit_mid_1
|
+ reddit_mid_1
|
||||||
+ vt_unsigned
|
+ vt_unsigned
|
||||||
+ reddit_mid_2
|
+ reddit_mid_2
|
||||||
|
+ updated
|
||||||
+ md_changelog
|
+ md_changelog
|
||||||
+ reddit_end
|
+ reddit_end
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(
|
with open(
|
||||||
"script_output/reddit_changelog.txt", "w", encoding="utf-8"
|
"script_output/reddit_changelog.txt", "w", encoding="utf-8"
|
||||||
) as reddit_file:
|
) 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:
|
def main() -> None:
|
||||||
|
"""Run the Changelog Generator"""
|
||||||
md_changelog, version = get_changelog()
|
md_changelog, version = get_changelog()
|
||||||
print(f"Detected version {version} in the changelog. Continuing...")
|
print(f"Detected version {version} in the changelog. Continuing...")
|
||||||
gh_link = input(f"Please enter the GitHub link for {version}: ")
|
gh_link = input(f"Please enter the GitHub link for {version}: ")
|
||||||
vt_signed = input("Please enter the VirusTotal URL for the Signed Installer: ")
|
vt_signed = input("Please enter the VirusTotal URL for the Signed Installer: ")
|
||||||
vt_unsigned = input("Please enter the VirusTotal URL for the Unsigned Installer: ")
|
vt_unsigned = input("Please enter the VirusTotal URL for the Unsigned Installer: ")
|
||||||
build_reddit(md_changelog, vt_signed, vt_unsigned, version, gh_link)
|
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)
|
build_fdev(vt_signed, vt_unsigned, version, gh_link, html)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user