Skip to content

Commit

Permalink
Handle the case where the .prices file doesnt exist
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Nov 27, 2014
1 parent ad61509 commit b9be772
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
v6.1.0 Nov 26 2014
. (gazelle) Added "export" sub-command to generate csv files of the current database
. (kfsone) Made the update-gui significantly more user friendly.
. (kfsone) Handle cases where .prices file is missing, e.g. bootstrap

v6.0.7 Nov 26 2014
. (kfsone) Removed 'pill' options from local command
Expand Down
12 changes: 11 additions & 1 deletion cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,12 @@ def buildCache(tdenv, dbPath, sqlPath, pricesPath, importTables, defaultZero=Fal
tdenv.DEBUG0("WARNING: processImportFile found no {} file", importName)

# Parse the prices file
processPricesFile(tdenv, tempDB, pricesPath, defaultZero=defaultZero)
if pricesPath.exists():
processPricesFile(tdenv, tempDB, pricesPath, defaultZero=defaultZero)
elif not tdenv.quiet:
print("NOTE: Missing \"{}\" file - no price data".format(
str(pricesPath)
), file=sys.stderr)

generateStationLink(tdenv, tempDB)

Expand All @@ -854,6 +859,11 @@ def importDataFromFile(tdb, tdenv, path, reset=False):
existing records for that station in the database.
"""

if not path.exists():
raise TradeException("No such file: {}".format(
str(path)
))

if reset:
tdenv.DEBUG0("Resetting price data")
tdb.getDB().execute("DELETE FROM StationItem")
Expand Down
5 changes: 1 addition & 4 deletions commands/buildcache_cmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import, with_statement, print_function, division, unicode_literals
from commands.parsing import MutuallyExclusiveGroup, ParseArgument
from commands.exceptions import CommandLineError
import sys

######################################################################
# Parser config
Expand Down Expand Up @@ -83,10 +84,6 @@ def run(results, cmdenv, tdb):
raise CommandLineError(
"SQL File does not exist: {}".format(sqlFilename))

if not pricesPath.exists():
raise CommandLineError(
"Prices file does not exist: {}".format(pricesFilename))

from cache import buildCache
buildCache(cmdenv, dbPath, sqlPath, pricesPath, importTables)

Expand Down
3 changes: 3 additions & 0 deletions trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ def main(argv):
main(sys.argv)
except tradeexcept.TradeException as e:
print("%s: %s" % (sys.argv[0], str(e)))
import os
if 'EXCEPTIONS' in os.environ:
raise e
sys.exit(1)

0 comments on commit b9be772

Please sign in to comment.