1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-15 08:40:34 +03:00

Merge pull request #2214 from HullSeals/enhancement/1801/FDEV-ID-Updater

[1801] FDEV ID Local Updater
This commit is contained in:
Phoebe 2024-05-14 23:22:20 +02:00 committed by GitHub
commit f7350fb46d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 44 additions and 43 deletions

1
.gitignore vendored
View File

@ -56,3 +56,4 @@ pylint.txt
# Ignore Submodule data directory # Ignore Submodule data directory
coriolis-data/ coriolis-data/
FDevIDs/

3
.gitmodules vendored
View File

@ -1,6 +1,3 @@
[submodule "coriolis-data"] [submodule "coriolis-data"]
path = coriolis-data path = coriolis-data
url = https://github.com/EDCD/coriolis-data.git url = https://github.com/EDCD/coriolis-data.git
[submodule "FDevIDs"]
path = FDevIDs
url = https://github.com/EDCD/FDevIDs.git

View File

@ -42,7 +42,7 @@ import stats
from commodity import COMMODITY_DEFAULT from commodity import COMMODITY_DEFAULT
from config import appcmdname, appversion, config from config import appcmdname, appversion, config
from monitor import monitor from monitor import monitor
from update import EDMCVersion, Updater from update import EDMCVersion, Updater, check_for_fdev_updates
sys.path.append(config.internal_plugin_dir) sys.path.append(config.internal_plugin_dir)
# This import must be after the sys.path.append. # This import must be after the sys.path.append.
@ -497,6 +497,10 @@ def main(): # noqa: C901, CCR001
if __name__ == '__main__': if __name__ == '__main__':
main() try:
check_for_fdev_updates(silent=True)
main()
except KeyboardInterrupt:
logger.info("Ctrl+C Detected, Attempting Clean Shutdown")
logger.debug('Exiting') logger.debug('Exiting')
sys.exit(EXIT_SUCCESS) sys.exit(EXIT_SUCCESS)

View File

@ -2282,35 +2282,6 @@ sys.path: {sys.path}'''
) )
config.set('plugins_not_py3_last', int(time())) config.set('plugins_not_py3_last', int(time()))
def check_fdev_ids():
"""Display message about missing FDEVID files."""
fdev_files = {'commodity.csv', 'rare_commodity.csv'}
for file in fdev_files:
fdevid_file = pathlib.Path(config.respath_path / 'FDevIDs' / file)
if fdevid_file.is_file():
continue
# LANG: Popup-text about missing FDEVID Files
popup_text = tr.tl(
"FDevID Files not found! Some functionality regarding commodities "
r"may be disabled.\r\n\r\n Do you want to open the Wiki page on "
"how to set up submodules?"
)
# And now we do need these to be actual \r\n
popup_text = popup_text.replace('\\n', '\n')
popup_text = popup_text.replace('\\r', '\r')
openwikipage = tk.messagebox.askquestion(
# LANG: Popup window title for missing FDEVID files
tr.tl('FDevIDs: Missing Commodity Files'),
popup_text
)
if openwikipage == "yes":
webbrowser.open(
"https://github.com/EDCD/EDMarketConnector/wiki/Running-from-source"
"#obtain-a-copy-of-the-application-source"
)
break
# UI Transparency # UI Transparency
ui_transparency = config.get_int('ui_transparency') ui_transparency = config.get_int('ui_transparency')
if ui_transparency == 0: if ui_transparency == 0:
@ -2323,8 +2294,6 @@ sys.path: {sys.path}'''
root.after(1, messagebox_not_py3) root.after(1, messagebox_not_py3)
# Show warning popup for killswitches matching current version # Show warning popup for killswitches matching current version
root.after(2, show_killswitch_poppup, root) root.after(2, show_killswitch_poppup, root)
# Check for FDEV IDs
root.after(3, check_fdev_ids)
# Start the main event loop # Start the main event loop
try: try:
root.mainloop() root.mainloop()

@ -1 +0,0 @@
Subproject commit 9b3f40612017b43a8b826017e1e2befebd9074f2

View File

@ -216,12 +216,6 @@
/* EDMarketConnector.py: Popup-text about 'active' plugins without Python 3.x support; In files: EDMarketConnector.py:2253:2259; */ /* EDMarketConnector.py: Popup-text about 'active' plugins without Python 3.x support; In files: EDMarketConnector.py:2253:2259; */
"One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name."; "One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name.";
/* EDMarketConnector.py: Popup-text about missing FDEVID Files; In files: EDMarketConnector.py:2329; */
"FDevID Files not found! Some functionality regarding commodities may be disabled.\r\n\r\n Do you want to open the Wiki page on how to set up submodules?" = "FDevID Files not found! Some functionality regarding commodities may be disabled.\r\n\r\n Do you want to open the Wiki page on how to set up submodules?";
/* EDMarketConnector.py: Popup window title for missing FDEVID files; In files: EDMarketConnector.py:2340; */
"FDevIDs: Missing Commodity Files" = "FDevIDs: Missing Commodity Files";
/* EDMarketConnector.py: Settings > Plugins tab; prefs.py: Label on Settings > Plugins tab; In files: EDMarketConnector.py:2263; prefs.py:986; */ /* EDMarketConnector.py: Settings > Plugins tab; prefs.py: Label on Settings > Plugins tab; In files: EDMarketConnector.py:2263; prefs.py:986; */
"Plugins" = "Plugins"; "Plugins" = "Plugins";

View File

@ -21,6 +21,7 @@ from config import (
_static_appversion, _static_appversion,
update_interval update_interval
) )
from update import check_for_fdev_updates
def iss_build(template_path: str, output_file: str) -> None: def iss_build(template_path: str, output_file: str) -> None:
@ -207,4 +208,5 @@ def build() -> None:
if __name__ == "__main__": if __name__ == "__main__":
check_for_fdev_updates()
build() build()

View File

@ -7,6 +7,7 @@ See LICENSE file.
""" """
from __future__ import annotations from __future__ import annotations
import pathlib
import sys import sys
import threading import threading
from traceback import print_exc from traceback import print_exc
@ -25,6 +26,38 @@ if TYPE_CHECKING:
logger = get_main_logger() logger = get_main_logger()
def check_for_fdev_updates(silent: bool = False) -> None: # noqa: CCR001
"""Check for and download FDEV ID file updates."""
files_urls = [
('commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/commodity.csv'),
('rare_commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/rare_commodity.csv')
]
for file, url in files_urls:
fdevid_file = pathlib.Path(config.respath_path / 'FDevIDs' / file)
fdevid_file.parent.mkdir(parents=True, exist_ok=True)
try:
with open(fdevid_file, newline='', encoding='utf-8') as f:
local_content = f.read()
except FileNotFoundError:
local_content = None
response = requests.get(url)
if response.status_code != 200:
if not silent:
logger.error(f'Failed to download {file}! Unable to continue.')
continue
if local_content == response.text:
if not silent:
logger.info(f'FDEV ID file {file} already up to date.')
else:
if not silent:
logger.info(f'FDEV ID file {file} not up to date. Downloading...')
with open(fdevid_file, 'w', newline='', encoding='utf-8') as csvfile:
csvfile.write(response.text)
class EDMCVersion: class EDMCVersion:
""" """
Hold all the information about an EDMC version. Hold all the information about an EDMC version.
@ -135,6 +168,8 @@ class Updater:
elif sys.platform == 'win32' and self.updater: elif sys.platform == 'win32' and self.updater:
self.updater.win_sparkle_check_update_with_ui() self.updater.win_sparkle_check_update_with_ui()
check_for_fdev_updates()
def check_appcast(self) -> EDMCVersion | None: def check_appcast(self) -> EDMCVersion | None:
""" """
Manually (no Sparkle or WinSparkle) check the update_feed appcast file. Manually (no Sparkle or WinSparkle) check the update_feed appcast file.