Skip to content

Commit

Permalink
Merge branch 'master' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
bgol committed Nov 21, 2014
2 parents c51ab14 + 04ff4fa commit f9eb3b9
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 26 deletions.
11 changes: 11 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.0.3 Nov 21 2014
. (kfsone) Added a GUI to the "update" sub-command, it's experimental:
- Use <tab>/<shift-tab> to cycle across rows,
- Use <enter> to drop to the first column of the next line,
- Scrolling is currently broken - you have to manually scroll. Ick.
- Use the "--exp" flag to indicate your understanding it is experimental.
e.g.: trade.py update --exp aulin
. (kfsone) Fixed sqrt crash in buildCache.py in multi-station systems,
. (kfsone) Fixed "local" command not showing stations when using "--detail",
. (kfsone) Renamed "buildcache.py" to "cache.py"

BETA 3:
CAUTION: So many systems changed with the Beta 3 update that old prices files
won't stand a chance of containing many valid systems. You may want to obtain
Expand Down
2 changes: 1 addition & 1 deletion buildcache.py → cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def generateStationLink(tdenv, db):
((lSys.pos_x - rSys.pos_x) * (lSys.pos_x - rSys.pos_x)) +
((lSys.pos_y - rSys.pos_y) * (lSys.pos_y - rSys.pos_y)) +
((lSys.pos_z - rSys.pos_z) * (lSys.pos_z - rSys.pos_z))
)
) AS dist
FROM Station AS lhs
INNER JOIN System AS lSys
ON (lhs.system_id = lSys.system_id),
Expand Down
2 changes: 1 addition & 1 deletion commands/buildcache_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run(results, cmdenv, tdb):
raise CommandLineError(
"Prices file does not exist: {}".format(pricesFilename))

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

return None
Expand Down
8 changes: 3 additions & 5 deletions commands/local_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def run(results, cmdenv, tdb):
if distSq <= lySq and destSys is not srcSystem:
distances[destSys] = math.sqrt(distSq)

detail = cmdenv.detai
detail = cmdenv.detail
if cmdenv.pill or cmdenv.percent:
pillCalc = PillCalculator(tdb, "Eranin", "HIP 107457", pill.percent)
else:
Expand All @@ -122,9 +122,7 @@ def run(results, cmdenv, tdb):
row.stations = []
if detail:
for (station) in system.stations:
row.stations.append({'station': station, 'dist': station.lsFromStar})
stationDistance = " {} ls".format(station.lsFromStar) if station.lsFromStar > 0 else ""
print("\t<{}>{}".format(station.str(), stationDistance))
row.stations.append(ResultRow(station=station, dist=station.lsFromStar))
results.rows.append(row)

return results
Expand Down Expand Up @@ -159,7 +157,7 @@ def render(results, cmdenv, tdb):

if cmdenv.detail:
stnRowFmt = RowFormat(prefix=' + ').append(
ColumnFormat("Station", '.<', 32,
ColumnFormat("Station", '<', 32,
key=lambda row: row.station.str())
).append(
ColumnFormat("Dist", '>', '9',
Expand Down
67 changes: 51 additions & 16 deletions commands/update_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tradeexcept import TradeException
from commands.exceptions import CommandLineError
import prices
import buildcache
import cache
import subprocess
import os
import pathlib
Expand Down Expand Up @@ -46,6 +46,12 @@
default=False,
dest='forceNa',
),
ParseArgument('--experimental-gui', '-G',
help="Use the experimental built-in GUI",
action='store_true',
default=False,
dest='gui',
),
MutuallyExclusiveGroup(
ParseArgument('--sublime',
help='Like --editor but uses Sublime Text (2 or 3), which is nice.',
Expand Down Expand Up @@ -73,6 +79,27 @@ class TemporaryFileExistsError(TradeException):
pass


def getTemporaryPath(cmdenv):
tmpPath = pathlib.Path("prices.tmp")
if tmpPath.exists():
if not cmdenv.force:
raise TemporaryFileExistsError(
"Temporary file already exists: {}\n"
"(Check you aren't already editing in another window"
.format(tmpPath)
)
tmpPath.unlink()
return tmpPath


def saveTemporaryFile(tmpPath):
if tmpPath.exists():
lastPath = pathlib.Path("prices.last")
if lastPath.exists():
lastPath.unlink()
tmpPath.rename(lastPath)


def getEditorPaths(cmdenv, editorName, envVar, windowsFolders, winExe, nixExe):
cmdenv.DEBUG0("Locating {} editor", editorName)
try:
Expand Down Expand Up @@ -113,7 +140,7 @@ def getEditorPaths(cmdenv, editorName, envVar, windowsFolders, winExe, nixExe):

def importDataFromFile(cmdenv, tdb, path, stationID, dbFilename):
cmdenv.DEBUG0("Importing data from {}".format(str(path)))
buildcache.processPricesFile(cmdenv,
cache.processPricesFile(cmdenv,
db=tdb.getDB(),
pricesPath=path,
stationID=stationID,
Expand Down Expand Up @@ -176,13 +203,7 @@ def editUpdate(tdb, cmdenv, stationID):
pass

# Create a temporary text file with a list of the price data.
tmpPath = pathlib.Path("prices.tmp")
if tmpPath.exists():
raise TemporaryFileExistsError(
"Temporary file already exists: {}\n"
"(Check you aren't already editing in another window"
.format(tmpPath)
)
tmpPath = getTemporaryPath(cmdenv)

absoluteFilename = None
dbFilename = cmdenv.dbFilename or tdb.defaultDB
Expand Down Expand Up @@ -251,22 +272,36 @@ def editUpdate(tdb, cmdenv, stationID):
finally:
# Save a copy
if absoluteFilename and tmpPath:
lastPath = pathlib.Path("prices.last")
if lastPath.exists():
lastPath.unlink()
tmpPath.rename(lastPath)
saveTemporaryFile(tmpPath)


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

def guidedUpdate(cmdenv, tdb):
raise CommandLineError("Guided update mode not implemented yet. See -h for help.")
from commands.update_gui import render
try:
render(tdb.dbPath, stationID, tmpPath)
cmdenv.DEBUG0("Got results, importing")
importDataFromFile(cmdenv, tdb, tmpPath, stationID, dbFilename)
finally:
saveTemporaryFile(tmpPath)


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

def run(results, cmdenv, tdb):
if not cmdenv.editor and not cmdenv.editing:
guidedUpdate(tdb, cmdenv)
if cmdenv.gui:
guidedUpdate(tdb, cmdenv)
return None
raise CommandLineError(
"The GUI for updates is currently experimental. "
"Either use one of the editors or specify the "
"--experimental-gui (--exp or -G for short) "
"flags.\n")

# User specified one of the options to use an editor.
editUpdate(tdb, cmdenv, cmdenv.startStation.ID)
Expand Down
Loading

0 comments on commit f9eb3b9

Please sign in to comment.