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/ChangeLog.md b/ChangeLog.md index 1c2ac9c2..30023566 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,18 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are in the source (not distributed with the Windows installer) for the currently used version. --- +Release 5.11.2 +=== + +This release fixes a bug where minimizing to the system tray could cause the program to not un-minimize. + +**Changes and Enhancements** +* Updated Translations +* Added a developer utility to help speed up changelog development + +**Bug Fixes** +* Fixed a bug where minimizing to the system tray could cause the program to not un-minimize. + Release 5.11.1 === diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 609cc2e9..1cfbce09 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -456,7 +456,7 @@ class AppWindow: if sys.platform == 'win32': from simplesystray import SysTrayIcon - def open_window(systray: 'SysTrayIcon') -> None: + def open_window(systray: 'SysTrayIcon', *args) -> None: self.w.deiconify() menu_options = (("Open", None, open_window),) diff --git a/L10n/en.template b/L10n/en.template index 1c1e110f..34734787 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -813,3 +813,6 @@ /* ttkHyperlinkLabel.py: Open Element In Selected Provider; */ "Open in {URL}" = "Open in {URL}"; + +/* ttkHyperlinkLabel.py: Copy the Inara SLEF Format of the active ship to the clipboard; */ +"Copy Inara SLEF" = "Copy Inara SLEF"; diff --git a/config/__init__.py b/config/__init__.py index 8dfcf46b..4fe565e4 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -52,7 +52,7 @@ appcmdname = 'EDMC' # # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.11.1' +_static_appversion = '5.11.2' _cached_version: semantic_version.Version | None = None copyright = '© 2015-2019 Jonathan Harris, 2020-2024 EDCD' diff --git a/coriolis-update-files.py b/coriolis-update-files.py index f31a2e32..6dfcc0c9 100755 --- a/coriolis-update-files.py +++ b/coriolis-update-files.py @@ -51,7 +51,8 @@ if __name__ == "__main__": for m in list(data['Ships'].values()): name = coriolis_ship_map.get(m['properties']['name'], str(m['properties']['name'])) assert name in reverse_ship_map, name - ships[name] = {'hullMass': m['properties']['hullMass']} + ships[name] = {'hullMass': m['properties']['hullMass'], + 'reserveFuelCapacity': m['properties']['reserveFuelCapacity']} for i, bulkhead in enumerate(bulkheads): modules['_'.join([reverse_ship_map[name], 'armour', bulkhead])] = {'mass': m['bulkheads'][i]['mass']} diff --git a/debug_webserver.py b/debug_webserver.py index eeedce97..1471ec7d 100644 --- a/debug_webserver.py +++ b/debug_webserver.py @@ -16,7 +16,7 @@ logger = get_main_logger() output_lock = threading.Lock() output_data_path = pathlib.Path(config.app_dir_path / 'logs' / 'http_debug') -SAFE_TRANSLATE = str.maketrans({x: '_' for x in "!@#$%^&*()./\\\r\n[]-+='\";:?<>,~`"}) +SAFE_TRANSLATE = str.maketrans(dict.fromkeys("!@#$%^&*()./\\\r\n[]-+='\";:?<>,~`", '_')) class LoggingHandler(server.BaseHTTPRequestHandler): diff --git a/monitor.py b/monitor.py index 9d33f5eb..b11301b8 100644 --- a/monitor.py +++ b/monitor.py @@ -21,9 +21,10 @@ from time import gmtime, localtime, mktime, sleep, strftime, strptime, time from typing import TYPE_CHECKING, Any, BinaryIO, MutableMapping import semantic_version import util_ships -from config import config -from edmc_data import edmc_suit_shortnames, edmc_suit_symbol_localised +from config import config, appname, appversion +from edmc_data import edmc_suit_shortnames, edmc_suit_symbol_localised, ship_name_map from EDMCLogging import get_main_logger +from edshipyard import ships if TYPE_CHECKING: import tkinter @@ -109,6 +110,7 @@ class EDLogs(FileSystemEventHandler): self.group: str | None = None self.cmdr: str | None = None self.started: int | None = None # Timestamp of the LoadGame event + self.slef: str | None = None self._navroute_retries_remaining = 0 self._last_navroute_journal_timestamp: float | None = None @@ -701,6 +703,34 @@ class EDLogs(FileSystemEventHandler): module.pop('AmmoInHopper') self.state['Modules'][module['Slot']] = module + # SLEF + initial_dict: dict[str, dict[str, Any]] = { + "header": {"appName": appname, "appVersion": str(appversion())} + } + data_dict = {} + for module in entry['Modules']: + if module.get('Slot') == 'FuelTank': + cap = module['Item'].split('size') + cap = cap[1].split('_') + cap = 2 ** int(cap[0]) + ship = ship_name_map[entry["Ship"]] + fuel = {'Main': cap, 'Reserve': ships[ship]['reserveFuelCapacity']} + data_dict.update({"FuelCapacity": fuel}) + data_dict.update({ + 'Ship': entry["Ship"], + 'ShipName': entry['ShipName'], + 'ShipIdent': entry['ShipIdent'], + 'HullValue': entry['HullValue'], + 'ModulesValue': entry['ModulesValue'], + 'Rebuy': entry['Rebuy'], + 'MaxJumpRange': entry['MaxJumpRange'], + 'UnladenMass': entry['UnladenMass'], + 'CargoCapacity': entry['CargoCapacity'], + 'Modules': entry['Modules'], + }) + initial_dict.update({'data': data_dict}) + output = json.dumps(initial_dict, indent=4) + self.slef = str(f"[{output}]") elif event_type == 'modulebuy': self.state['Modules'][entry['Slot']] = { diff --git a/requirements-dev.txt b/requirements-dev.txt index 7c8e1ef5..fe145993 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,10 +8,10 @@ wheel setuptools==70.0.0 # Static analysis tools -flake8==7.0.0 +flake8==7.1.0 flake8-annotations-coverage==0.0.6 flake8-cognitive-complexity==0.1.0 -flake8-comprehensions==3.14.0 +flake8-comprehensions==3.15.0 flake8-docstrings==1.7.0 flake8-json==24.4.0 flake8-noqa==1.4.0 @@ -19,7 +19,7 @@ flake8-polyfill==1.0.2 flake8-use-fstring==1.4 mypy==1.10.0 -pep8-naming==0.13.3 +pep8-naming==0.14.1 safety==3.2.0 types-requests==2.31.0.20240311 types-pkg-resources==0.1.3 @@ -31,14 +31,14 @@ 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. py2exe==0.13.0.1; sys_platform == 'win32' # Testing -pytest==8.2.0 +pytest==8.2.2 pytest-cov==5.0.0 # Pytest code coverage support coverage[toml]==7.5.0 # pytest-cov dep. This is here to ensure that it includes TOML support for pyproject.toml configs coverage-conditional-plugin==0.9.0 diff --git a/requirements.txt b/requirements.txt index 22f0a360..87795065 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ requests==2.32.3 pillow==10.3.0 -watchdog==4.0.0 +watchdog==4.0.1 simplesystray==0.1.0; sys_platform == 'win32' semantic-version==2.10.0 diff --git a/scripts/build_changelog.py b/scripts/build_changelog.py new file mode 100644 index 00000000..6b050774 --- /dev/null +++ b/scripts/build_changelog.py @@ -0,0 +1,165 @@ +#!/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() -> tuple[str, str]: + """Pull the last full changelog details in MD.""" + 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] + final_changelog = changelog[1].strip() + + return final_changelog, version + + +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"\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 +) -> None: + """Build changelog for FDEV forums.""" + fdev_out = ( + 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", "Beta")): + fdev_out += ( + 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" + ) + + 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) + + +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. + +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. + +~~----------------------------------------------------~~ +""" + 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** + +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 + + updated + + 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: + """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, version) + build_fdev(vt_signed, vt_unsigned, version, gh_link, html) + + +if __name__ == "__main__": + chdir(pathlib.Path(__file__).parent) + main() diff --git a/ships.json b/ships.json index 65a2989e..ac05d5d8 100644 --- a/ships.json +++ b/ships.json @@ -1,119 +1,158 @@ { "Adder": { - "hullMass": 35 + "hullMass": 35, + "reserveFuelCapacity": 0.36 }, "Alliance Challenger": { - "hullMass": 450 + "hullMass": 450, + "reserveFuelCapacity": 0.77 }, "Alliance Chieftain": { - "hullMass": 400 + "hullMass": 400, + "reserveFuelCapacity": 0.77 }, "Alliance Crusader": { - "hullMass": 500 + "hullMass": 500, + "reserveFuelCapacity": 0.77 }, "Anaconda": { - "hullMass": 400 + "hullMass": 400, + "reserveFuelCapacity": 1.07 }, "Asp Explorer": { - "hullMass": 280 + "hullMass": 280, + "reserveFuelCapacity": 0.63 }, "Asp Scout": { - "hullMass": 150 + "hullMass": 150, + "reserveFuelCapacity": 0.47 }, "Beluga Liner": { - "hullMass": 950 + "hullMass": 950, + "reserveFuelCapacity": 0.81 }, "Cobra MkIII": { - "hullMass": 180 + "hullMass": 180, + "reserveFuelCapacity": 0.49 }, "Cobra MkIV": { - "hullMass": 210 + "hullMass": 210, + "reserveFuelCapacity": 0.51 }, "Diamondback Explorer": { - "hullMass": 260 + "hullMass": 260, + "reserveFuelCapacity": 0.52 }, "Diamondback Scout": { - "hullMass": 170 + "hullMass": 170, + "reserveFuelCapacity": 0.49 }, "Dolphin": { - "hullMass": 140 + "hullMass": 140, + "reserveFuelCapacity": 0.5 }, "Eagle": { - "hullMass": 50 + "hullMass": 50, + "reserveFuelCapacity": 0.34 }, "Federal Assault Ship": { - "hullMass": 480 + "hullMass": 480, + "reserveFuelCapacity": 0.72 }, "Federal Corvette": { - "hullMass": 900 + "hullMass": 900, + "reserveFuelCapacity": 1.13 }, "Federal Dropship": { - "hullMass": 580 + "hullMass": 580, + "reserveFuelCapacity": 0.83 }, "Federal Gunship": { - "hullMass": 580 + "hullMass": 580, + "reserveFuelCapacity": 0.82 }, "Fer-de-Lance": { - "hullMass": 250 + "hullMass": 250, + "reserveFuelCapacity": 0.67 }, "Hauler": { - "hullMass": 14 + "hullMass": 14, + "reserveFuelCapacity": 0.25 }, "Imperial Clipper": { - "hullMass": 400 + "hullMass": 400, + "reserveFuelCapacity": 0.74 }, "Imperial Courier": { - "hullMass": 35 + "hullMass": 35, + "reserveFuelCapacity": 0.41 }, "Imperial Cutter": { - "hullMass": 1100 + "hullMass": 1100, + "reserveFuelCapacity": 1.16 }, "Imperial Eagle": { - "hullMass": 50 + "hullMass": 50, + "reserveFuelCapacity": 0.37 }, "Keelback": { - "hullMass": 180 + "hullMass": 180, + "reserveFuelCapacity": 0.39 }, "Krait MkII": { - "hullMass": 320 + "hullMass": 320, + "reserveFuelCapacity": 0.63 }, "Krait Phantom": { - "hullMass": 270 + "hullMass": 270, + "reserveFuelCapacity": 0.63 }, "Mamba": { - "hullMass": 250 + "hullMass": 250, + "reserveFuelCapacity": 0.5 }, "Orca": { - "hullMass": 290 + "hullMass": 290, + "reserveFuelCapacity": 0.79 }, "Python": { - "hullMass": 350 + "hullMass": 350, + "reserveFuelCapacity": 0.83 }, "Python Mk II": { - "hullMass": 450 + "hullMass": 450, + "reserveFuelCapacity": 0.83 }, "Sidewinder": { - "hullMass": 25 + "hullMass": 25, + "reserveFuelCapacity": 0.3 }, "Type-10 Defender": { - "hullMass": 1200 + "hullMass": 1200, + "reserveFuelCapacity": 0.77 }, "Type-6 Transporter": { - "hullMass": 155 + "hullMass": 155, + "reserveFuelCapacity": 0.39 }, "Type-7 Transporter": { - "hullMass": 350 + "hullMass": 350, + "reserveFuelCapacity": 0.52 }, "Type-9 Heavy": { - "hullMass": 850 + "hullMass": 850, + "reserveFuelCapacity": 0.77 }, "Viper MkIII": { - "hullMass": 50 + "hullMass": 50, + "reserveFuelCapacity": 0.41 }, "Viper MkIV": { - "hullMass": 190 + "hullMass": 190, + "reserveFuelCapacity": 0.46 }, "Vulture": { - "hullMass": 230 + "hullMass": 230, + "reserveFuelCapacity": 0.57 } } \ No newline at end of file diff --git a/ttkHyperlinkLabel.py b/ttkHyperlinkLabel.py index 6266d9fb..9f445690 100644 --- a/ttkHyperlinkLabel.py +++ b/ttkHyperlinkLabel.py @@ -194,6 +194,10 @@ class HyperlinkLabel(tk.Label or ttk.Label): # type: ignore menu.add_command(label=tr.tl('Copy'), command=self.copy) # As in Copy and Paste if self.name == 'ship': + # LANG: Copy the Inara SLEF Format of the active ship to the clipboard + menu.add_command(label=tr.tl('Copy Inara SLEF'), command=self.copy_slef, state=tk.DISABLED) + menu.entryconfigure(1, state=monitor.slef and tk.NORMAL or tk.DISABLED) + menu.add_separator() for url in plug.provides('shipyard_url'): menu.add_command( @@ -224,3 +228,8 @@ class HyperlinkLabel(tk.Label or ttk.Label): # type: ignore """Copy the current text to the clipboard.""" self.clipboard_clear() self.clipboard_append(self['text']) + + def copy_slef(self) -> None: + """Copy the current text to the clipboard.""" + self.clipboard_clear() + self.clipboard_append(monitor.slef)