Skip to content

Commit

Permalink
Merged kfsone/tradedangerous into master
Browse files Browse the repository at this point in the history
  • Loading branch information
orphu committed Dec 3, 2014
2 parents 6a8fc3c + 697db71 commit 674a70e
Show file tree
Hide file tree
Showing 8 changed files with 19,903 additions and 19,702 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.1.4 Dec 01 2014
. (kfsone) "updated.prices" will now contain line removals
. (kfsone) 155 new systems from RedWizard
. (Eggplant!) More Stations
. (kfsone) Fix miscount of jumps when same-system hops were in a route,
. (kfsone) run --jumps=0 now limits to same-system options
. (kfsone) Fixed empty "Jump" lines in nav output for same-system hop
. (Eggplant!) More Stations

v6.1.3 Nov 30 2014
. (gazelle) More Station and Ship data
Expand Down
4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ IMPORT sub-command:
the data is usually saved as "prices.last". You can open this file and correct
the error and then import it, rather than having to re-enter all of the data.

NOTE: Items not listed for a station in an import are considered unavailable at
that station. If you have an entry for Beagle2/Food and you import a file that
does not include Beagle2/Food, Beagle2/Food will be removed from your db.

trade.py import [-q | -v] [filename | url | --maddavo] [--ignore-unknown]

filename
Expand Down
6 changes: 3 additions & 3 deletions commands/import_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# Parser config

help=(
"Imports price data from a '.prices' format file "
"without affecting data for stations not included "
"in the import file."
"Imports price data from a '.prices' format file. "
"Previous data for the stations included in the file "
"is removed, but other stations are not affected."
)
name='import'
epilog=None
Expand Down
157 changes: 92 additions & 65 deletions commands/update_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,38 @@
ParseArgument('starting', help='Name of the station to update.', type=str)
]
switches = [
ParseArgument('--editor',
help='Generates a text file containing the prices for the station and '
'loads it into the specified editor for you.',
default=None,
type=str,
),
ParseArgument('--supply', '-S',
help='Includes demand and stock (supply) values in the update.',
help='[Text editing] Includes demand and stock (supply) values in the update.',
action='store_true',
default=False,
),
),
ParseArgument('--timestamps', '-T',
help='Includes timestamps in the update.',
help='[Text editing] Includes timestamps in the update.',
action='store_true',
default=False,
),
),
ParseArgument('--all', '-A',
help='List all known items.',
action='store_true',
default=False,
),
),
ParseArgument('--use-demand', '-D',
help='Unlock the "Demand" column in the GUI.',
action='store_true',
dest='useDemand',
default=False,
),
),
ParseArgument('--force-na', '-0',
help="Forces 'unk' supply to become 'n/a' by default",
action='store_true',
default=False,
dest='forceNa',
),
ParseArgument('--experimental-gui', '-G',
help="Use the experimental built-in GUI",
action='store_true',
default=False,
dest='gui',
),
),
ParseArgument('--height', '-H',
help="[GUI] Specify height of the window",
type=int,
default=800,
),
),
ParseArgument('--front', '-F',
help=(
"[GUI] Keep the GUI infront of other windows; "
Expand All @@ -78,24 +66,39 @@
action='store_true',
default=False,
dest='alwaysOnTop',
),
),
MutuallyExclusiveGroup(
ParseArgument('--sublime',
help='Like --editor but uses Sublime Text (2 or 3), which is nice.',
action='store_const', const='sublime', dest='editing',
ParseArgument('--experimental-gui', '-G',
help="Use the experimental built-in GUI",
action='store_true',
default=False,
dest='gui',
),
MutuallyExclusiveGroup(
ParseArgument('--editor',
help='Generates a text file containing the prices for '
'the station and loads it into the specified '
'text editor for you.',
default=None,
type=str,
),
ParseArgument('--sublime',
help='Like --editor but uses Sublime Text (2 or 3).',
action='store_const', const='sublime', dest='editing',
),
ParseArgument('--notepad',
help='Like --editor but uses Notepad.',
action='store_const', const='notepad', dest='editing',
ParseArgument('--notepad',
help='Like --editor but uses Notepad.',
action='store_const', const='notepad', dest='editing',
),
ParseArgument('--npp',
help='Like --editor but uses Notepad++.',
action='store_const', const='npp', dest='editing',
ParseArgument('--npp',
help='Like --editor but uses Notepad++.',
action='store_const', const='npp', dest='editing',
),
ParseArgument('--vim',
help='Like --editor but uses vim.',
action='store_const', const='vim', dest='editing',
ParseArgument('--vim',
help='Like --editor but uses vim.',
action='store_const', const='vim', dest='editing',
),
),
)
]

Expand All @@ -114,7 +117,7 @@ def getTemporaryPath(cmdenv):
"Temporary file already exists: {}\n"
"(Check you aren't already editing in another window"
.format(tmpPath)
)
)
tmpPath.unlink()
return tmpPath

Expand All @@ -131,12 +134,13 @@ 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,
prices.dumpPrices(dbFilename,
prices.Element.full | prices.Element.blanks,
file=dumpFile,
stationID=stationID,
defaultZero=False,
debug=cmdenv.debug,
)
)
if not cmdenv.quiet:
print("- Copy of changes saved as '{}'".format(
str(dumpPath)
Expand Down Expand Up @@ -178,7 +182,7 @@ def getEditorPaths(cmdenv, editorName, envVar, windowsFolders, winExe, nixExe):
"Either specify the path to your editor with --editor "
"or set the {} environment variable to point to it."
.format(editorName, envVar)
)
)


def editUpdate(tdb, cmdenv, stationID):
Expand All @@ -197,24 +201,42 @@ def editUpdate(tdb, cmdenv, stationID):
editor, editorArgs = cmdenv.editor, []
if cmdenv.editing == 'sublime':
cmdenv.DEBUG0("Sublime mode")
editor = editor or getEditorPaths(cmdenv,
"sublime", "SUBLIME_EDITOR",
["Sublime Text 3", "Sublime Text 2"], "sublime_text.exe", "subl")
editor = editor or \
getEditorPaths(cmdenv,
"sublime", "SUBLIME_EDITOR",
["Sublime Text 3", "Sublime Text 2"],
"sublime_text.exe",
"subl"
)
editorArgs += [ "--wait" ]
elif cmdenv.editing == 'npp':
cmdenv.DEBUG0("Notepad++ mode")
editor = editor or getEditorPaths(cmdenv,
"notepad++", "NOTEPADPP_EDITOR",
["Notepad++"], "notepad++.exe", "notepad++")
editor = editor or \
getEditorPaths(cmdenv,
"notepad++", "NOTEPADPP_EDITOR",
["Notepad++"],
"notepad++.exe",
"notepad++"
)
if not cmdenv.quiet:
print("NOTE: You'll need to exit Notepad++ to return control back to trade.py")
print("NOTE: "
"You'll need to exit Notepad++ when you are done.")
elif cmdenv.editing == "vim":
cmdenv.DEBUG0("VI iMproved mode")
if not editor:
# Hack... Hackity hack, hack, hack.
# This has a disadvantage in that: we don't check for just "vim" (no .exe) under Windows
vimDirs = [ "Git\\share\\vim\\vim{}".format(vimVer) for vimVer in range(70,75) ]
editor = getEditorPaths(cmdenv, "vim", "EDITOR", vimDirs, "vim.exe", "vim")
vimDirs = [
"Git\\share\\vim\\vim{}".format(vimVer)
for vimVer in range(70,75)
]
editor = getEditorPaths(cmdenv,
"vim",
"EDITOR",
vimDirs,
"vim.exe",
"vim"
)
elif cmdenv.editing == "notepad":
cmdenv.DEBUG0("Notepad mode")
editor = editor or "notepad.exe" # herp
Expand All @@ -235,15 +257,17 @@ def editUpdate(tdb, cmdenv, stationID):
elementMask = prices.Element.basic
if cmdenv.supply: elementMask |= prices.Element.supply
if cmdenv.timestamps: elementMask |= prices.Element.timestamp
if cmdenv.all: elementMask |= prices.Element.blanks
# Open the file and dump data to it.
with tmpPath.open("w") as tmpFile:
# Remember the filename so we know we need to delete it.
absoluteFilename = str(tmpPath.resolve())
prices.dumpPrices(dbFilename, elementMask,
file=tmpFile,
stationID=stationID,
defaultZero=cmdenv.forceNa,
debug=cmdenv.debug)
file=tmpFile,
stationID=stationID,
defaultZero=cmdenv.forceNa,
debug=cmdenv.debug
)

# Stat the file so we can determine if the user writes to it.
# Use the most recent create/modified timestamp.
Expand All @@ -259,13 +283,13 @@ def editUpdate(tdb, cmdenv, stationID):
raise CommandLineError(
"Unable to launch requested editor: {}"
.format(editorCommandLine)
)
)
if result != 0:
raise CommandLineError(
"NO DATA IMPORTED: "
"Your editor exited with a 'failed' exit code ({})"
.format(result)
)
)

# Did they update the file? Some editors destroy the file and rewrite it,
# other files just write back to it, and some OSes do weird things with
Expand All @@ -275,7 +299,8 @@ def editUpdate(tdb, cmdenv, stationID):

if postStamp == preStamp:
import random
print("- No changes detected - doing nothing. {}".format(random.choice([
print("- No changes detected - doing nothing. {}".format(
random.choice([
"Brilliant!",
"I'll get my coat.",
"I ain't seen you.",
Expand All @@ -286,11 +311,11 @@ def editUpdate(tdb, cmdenv, stationID):
"Boutros, boutros, ghali!",
"I'm Ed Winchester!",
"Suit you, sir! Oh!"
])))
])
))
else:
cache.importDataFromFile(tdb, cmdenv, tmpPath)

saveCopyOfChanges(cmdenv, dbFilename, stationID)
saveCopyOfChanges(cmdenv, dbFilename, stationID)

tmpPath.unlink()
tmpPath = None
Expand Down Expand Up @@ -321,7 +346,7 @@ def guidedUpdate(tdb, cmdenv):
print("*** ERROR ENCOUNTERED ***")
print("*** YOUR UPDATES WILL BE SAVED AS {} ***".format(
"prices.last"
))
))
raise
finally:
if tmpPath:
Expand All @@ -339,20 +364,22 @@ def run(results, cmdenv, tdb):
raise CommandLineError(
"'{}' is a system, not a station.".format(
system.name()
))
))
cmdenv.startStation = system.stations[0]
else:
cmdenv.startStation = place

if cmdenv.gui:
guidedUpdate(tdb, cmdenv)
return None

if not cmdenv.editor and not cmdenv.editing:
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")
"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
13 changes: 12 additions & 1 deletion data/Added.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@ unq:name
'Alpha2'
'Alpha3'
'Alpha4'
'Beta1 (unverified)'
'Beta1 (unverified)-Inferred'
'Beta1'
'Beta2'
'Beta1-Inferred'
'Beta2 (outside Beta3)'
'Beta2 (outside Beta3)-Inferred'
'Beta2 (unverified)'
'Beta2 (unverified)-Inferred'
'Beta2'
'Beta2-Inferred'
'Beta3 (unverified)'
'Beta3 (unverified)-Inferred'
'Beta3'
'Beta3-Inferred'
'Beyond The Pill (unverified)-Inferred'
'Gamma (unverified)'
'Gamma (unverified)-Inferred'
'Gamma'
'Gamma-Inferred'
'Gamma1 (unverified)'
'Gamma1 (unverified)-Inferred'
'Gamma1'
'Gamma1-Inferred'
'Not Present'
Expand Down
Loading

0 comments on commit 674a70e

Please sign in to comment.