Skip to content

Commit

Permalink
fix: Don't crash when attempting to download non-existent file.
Browse files Browse the repository at this point in the history
Fixes #21.

Specifically, it fixes the crash that happens because of the ship's
index file no longer existing of the EDCD coriolois data github.

So the Ships database won't be getting updated until a new source is
found to download from.

For now the latest version available before the removal is stored as a
template.

TD will get another update once we have a new site from which to get the
index again.
  • Loading branch information
eyeonus committed May 22, 2019
1 parent f088f25 commit 97c254d
Show file tree
Hide file tree
Showing 3 changed files with 6,378 additions and 36 deletions.
42 changes: 21 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,38 @@

package = "tradedangerous"

exec(open("tradedangerous/version.py").read()) #pylint: disable=W0122
exec(open("tradedangerous/version.py").read()) # pylint: disable=W0122

setup(name=package,
version=__version__, #pylint: disable=E0602
install_requires=["requests"],
setup_requires=["pytest-runner"],
tests_require=["pytest"],
packages=['tradedangerous', 'tradedangerous.commands', 'tradedangerous.mfd', 'tradedangerous.mfd.saitek', 'tradedangerous.misc', 'tradedangerous.plugins'],
url="https://github.com/eyeonus/Trade-Dangerous",
project_urls={
setup(name = package,
version = __version__, # pylint: disable=E0602
install_requires = ["requests"],
setup_requires = ["pytest-runner"],
tests_require = ["pytest"],
packages = ['tradedangerous', 'tradedangerous.commands', 'tradedangerous.mfd', 'tradedangerous.mfd.saitek', 'tradedangerous.misc', 'tradedangerous.plugins'],
url = "https://github.com/eyeonus/Trade-Dangerous",
project_urls = {
"Bug Tracker": "https://github.com/eyeonus/Trade-Dangerous/issues",
"Documentation": "https://github.com/eyeonus/Trade-Dangerous/wiki",
"Source Code": "https://github.com/eyeonus/Trade-Dangerous",
},
author="eyeonus",
author_email="eyeonus@gmail.com",
description="Trade-Dangerous is a set of powerful trading tools for Elite Dangerous, organized around one of the most powerful trade run optimizers available.",
long_description=long_description,
long_description_content_type="text/markdown",
keywords=["trade", "elite", "elite-dangerous"],
classifiers=[
author = "eyeonus",
author_email = "eyeonus@gmail.com",
description = "Trade-Dangerous is a set of powerful trading tools for Elite Dangerous, organized around one of the most powerful trade run optimizers available.",
long_description = long_description,
long_description_content_type = "text/markdown",
keywords = ["trade", "elite", "elite-dangerous"],
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
license="MPL",
test_suite="tests",
package_data={"tradedangerous": ["templates/TradeDangerous.sql", "templates/Added.csv", "templates/RareItem.csv"]},
entry_points={
license = "MPL",
test_suite = "tests",
package_data = {"tradedangerous": ["templates/TradeDangerous.sql", "templates/Added.csv", "templates/RareItem.csv", "templates/DefaultShipIndex.json"]},
entry_points = {
"console_scripts": [
"trade=tradedangerous.cli:main"
]
},
zip_safe=False
zip_safe = False
)
42 changes: 27 additions & 15 deletions tradedangerous/plugins/eddblink_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .. import plugins, cache, csvexport, tradedb, tradeenv, transfers
from ..misc import progress as pbar
from ..plugins import PluginException
from shutil import copyfile

# Constants
BASE_URL = os.environ.get('TD_SERVER') or "http://elite.tromador.com/files/"
Expand Down Expand Up @@ -155,25 +156,36 @@ def downloadFile(self, urlTail, path):
"""
tdb, tdenv = self.tdb, self.tdenv

tdenv.DEBUG0("Checking for update to '{}'.", path)
tdenv.NOTE("Checking for update to '{}'.", path)
if urlTail == SHIPS_URL:
url = SHIPS_URL
else:
if not self.getOption('fallback'):
try:
url = BASE_URL + urlTail
response = request.urlopen(url)
except:
# If Tromador's server fails for whatever reason,
# fallback to download direct from EDDB.io
self.options["fallback"] = True
if self.getOption('fallback'):
# EDDB.io doesn't have live listings.
if urlTail == LIVE_LISTINGS:
return False

url = FALLBACK_URL + urlTail
url = BASE_URL + urlTail
if url == SHIPS_URL or not self.getOption('fallback'):
try:
response = request.urlopen(url)
except Exception as e:
# If Tromador's server fails for whatever reason,
# fallback to download direct from EDDB.io
tdenv.WARN("Problem with download:\nURL: {}\nError: {}", url, str(e))
self.options["fallback"] = True

if self.getOption('fallback'):
# EDDB.io doesn't have live listings or the ship index.
if urlTail == LIVE_LISTINGS:
return False

if urlTail == SHIPS_URL:
tdenv.NOTE("Using Default Ship Index.")
copyfile(self.tdenv.templateDir / Path("DefaultShipIndex.json"), self.dataPath / path)
return True

url = FALLBACK_URL + urlTail
try:
response = request.urlopen(url)
except Exception as e:
tdenv.WARN("Problem with download (fallback enabled):\nURL: {}\nError: {}", url, str(e))
return False

dumpModded = 0
# The coriolis file is from github, so it doesn't have a "Last-Modified" metadata.
Expand Down
Loading

0 comments on commit 97c254d

Please sign in to comment.