Skip to content

Commit

Permalink
"update" now puts timestamps in updated.prices.
Browse files Browse the repository at this point in the history
Also made it use "place"s for the start station.
  • Loading branch information
kfsone committed Dec 1, 2014
1 parent fe34171 commit f976f8a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.1.3 Nov 30 2014
. (kfsone) Changed UPDATE command to use places, check for stations, and to
generate a complete .prices fragment with timestamps for maddavo compat.
. (kfsone) Fixed "run" and "nav" not understanding stations correctly
. (kfsone) "avoid" now handles systems/stations discretely
- avoiding a station means you won't land there but you can
Expand Down
60 changes: 42 additions & 18 deletions commands/update_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from commands.parsing import MutuallyExclusiveGroup, ParseArgument
from tradeexcept import TradeException
from commands.exceptions import CommandLineError
from tradedb import System, Station
import prices
import cache
import subprocess
Expand All @@ -21,7 +22,7 @@
"check for changes.")
wantsTradeDB=True
arguments = [
ParseArgument('origin', help='Name of the station to update.', type=str)
ParseArgument('starting', help='Name of the station to update.', type=str)
]
switches = [
ParseArgument('--editor',
Expand Down Expand Up @@ -126,6 +127,22 @@ def saveTemporaryFile(tmpPath):
tmpPath.rename(lastPath)


def saveCopyOfChanges(cmdenv, dbFilename, stationID):
dumpPath = pathlib.Path("updated.prices")
with dumpPath.open("w") as dumpFile:
# Remember the filename so we know we need to delete it.
prices.dumpPrices(dbFilename, prices.Element.full,
file=dumpFile,
stationID=stationID,
defaultZero=False,
debug=cmdenv.debug,
)
if not cmdenv.quiet:
print("- Copy of changes saved as '{}'".format(
str(dumpPath)
))


def getEditorPaths(cmdenv, editorName, envVar, windowsFolders, winExe, nixExe):
cmdenv.DEBUG0("Locating {} editor", editorName)
try:
Expand Down Expand Up @@ -273,14 +290,9 @@ def editUpdate(tdb, cmdenv, stationID):
else:
cache.importDataFromFile(tdb, cmdenv, tmpPath)

savePath = pathlib.Path("updated.prices")
if savePath.exists():
savePath.unlink()
tmpPath.rename(savePath)
if not cmdenv.quiet:
print("- Copy of changes saved as '{}'".format(
str(savePath)
))
saveCopyOfChanges(cmdenv, dbFilename, stationID)

tmpPath.unlink()
tmpPath = None

finally:
Expand All @@ -291,35 +303,47 @@ def editUpdate(tdb, cmdenv, stationID):

def guidedUpdate(tdb, cmdenv):
dbFilename = cmdenv.dbFilename or tdb.defaultDB
stationID = cmdenv.startStation.ID
tmpPath = getTemporaryPath(cmdenv)

from commands.update_gui import render
try:
render(tdb, cmdenv, tmpPath)
cmdenv.DEBUG0("Got results, importing")
cache.importDataFromFile(tdb, cmdenv, tmpPath)
savePath = pathlib.Path("updated.prices")
if savePath.exists():
savePath.unlink()
tmpPath.rename(savePath)
if not cmdenv.quiet:
print("- Copy of changes saved as '{}'".format(
str(savePath)
))

saveCopyOfChanges(cmdenv, dbFilename, stationID)

tmpPath.unlink()
tmpPath = None

except Exception as e:
print("*** ERROR ENCOUNTERED ***")
print("*** YOUR UPDATES WILL BE SAVED AS {} ***".format(
"prices.last"
))
raise
finally:
saveTemporaryFile(tmpPath)
if tmpPath:
saveTemporaryFile(tmpPath)


######################################################################
# Perform query and populate result set

def run(results, cmdenv, tdb):
place = cmdenv.origPlace
if isinstance(place, System):
system = place
if len(system.stations) != 1:
raise CommandLineError(
"'{}' is a system, not a station.".format(
system.name()
))
cmdenv.startStation = system.stations[0]
else:
cmdenv.startStation = place

if not cmdenv.editor and not cmdenv.editing:
if cmdenv.gui:
guidedUpdate(tdb, cmdenv)
Expand Down

0 comments on commit f976f8a

Please sign in to comment.