Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2251] Fix FDevID Update Paths #2253

Merged
merged 9 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions EDMarketConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

from EDMCLogging import edmclogger, logger, logging
from journal_lock import JournalLock, JournalLockResult
from update import check_for_fdev_updates

if __name__ == '__main__': # noqa: C901
# Command-line arguments
Expand Down Expand Up @@ -2323,6 +2324,7 @@ def messagebox_not_py3():
root.after(2, show_killswitch_poppup, root)
# Start the main event loop
try:
check_for_fdev_updates()
root.mainloop()
except KeyboardInterrupt:
logger.info("Ctrl+C Detected, Attempting Clean Shutdown")
Expand Down
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,5 @@ def build() -> None:


if __name__ == "__main__":
check_for_fdev_updates()
check_for_fdev_updates(local=True)
build()
6 changes: 5 additions & 1 deletion collate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import companion
import outfitting
from config import config
from edmc_data import companion_category_map, ship_name_map


Expand Down Expand Up @@ -50,7 +51,10 @@ def addcommodities(data) -> None: # noqa: CCR001
if not data['lastStarport'].get('commodities'):
return

commodityfile = pathlib.Path('FDevIDs/commodity.csv')
try:
commodityfile = pathlib.Path(config.app_dir_path / 'FDevIDs' / 'commodity.csv')
except FileNotFoundError:
commodityfile = pathlib.Path('FDevIDs/commodity.csv')
commodities = {}

# slurp existing
Expand Down
4 changes: 2 additions & 2 deletions companion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,10 +1203,10 @@ def fixup(data: CAPIData) -> CAPIData: # noqa: C901, CCR001 # Can't be usefully
if not commodity_map:
# Lazily populate
for f in ('commodity.csv', 'rare_commodity.csv'):
if not os.path.isfile(config.respath_path / 'FDevIDs/' / f):
if not os.path.isfile(config.app_dir_path / 'FDevIDs/' / f):
logger.warning(f'FDevID file {f} not found! Generating output without these commodity name rewrites.')
continue
with open(config.respath_path / 'FDevIDs' / f, 'r') as csvfile:
with open(config.app_dir_path / 'FDevIDs' / f, 'r') as csvfile:
reader = csv.DictReader(csvfile)

for row in reader:
Expand Down
2 changes: 1 addition & 1 deletion config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
# <https://semver.org/#semantic-versioning-specification-semver>
# Major.Minor.Patch(-prerelease)(+buildmetadata)
# NB: Do *not* import this, use the functions appversion() and appversion_nobuild()
_static_appversion = '5.11.0'
_static_appversion = '5.11.1-alpha3'
_cached_version: semantic_version.Version | None = None
copyright = '© 2015-2019 Jonathan Harris, 2020-2024 EDCD'

Expand Down
35 changes: 30 additions & 5 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import annotations

import pathlib
import shutil
import sys
import threading
from traceback import print_exc
Expand All @@ -26,23 +27,40 @@
logger = get_main_logger()


def check_for_fdev_updates(silent: bool = False) -> None: # noqa: CCR001
def check_for_fdev_updates(silent: bool = False, local: bool = False) -> None: # noqa: CCR001
"""Check for and download FDEV ID file updates."""
if local:
pathway = config.respath_path
else:
pathway = config.app_dir_path

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 = pathlib.Path(pathway / '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)
logger.info(f'File {file} not found. Writing from bundle...')
try:
for localfile in files_urls:
filepath = pathlib.Path(f"FDevIDs/{localfile[0]}")
try:
shutil.copy(filepath, pathway / 'FDevIDs')
except shutil.SameFileError:
logger.info("Not replacing same file...")
fdevid_file = pathlib.Path(pathway / 'FDevIDs' / file)
with open(fdevid_file, newline='', encoding='utf-8') as f:
local_content = f.read()
except FileNotFoundError:
local_content = None

response = requests.get(url, timeout=20)
if response.status_code != 200:
if not silent:
logger.error(f'Failed to download {file}! Unable to continue.')
Expand Down Expand Up @@ -169,6 +187,13 @@ def check_for_updates(self) -> None:
self.updater.win_sparkle_check_update_with_ui()

check_for_fdev_updates()
# TEMP: Only include until 6.0
try:
check_for_fdev_updates(local=True)
except Exception as e:
logger.info("Tried to update bundle FDEV files but failed. Don't worry, "
"this likely isn't important and can be ignored unless"
f" you run into other issues. If you're curious: {e}")

def check_appcast(self) -> EDMCVersion | None:
"""
Expand Down
Loading