Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Buntain committed Jan 11, 2015
2 parents 5260450 + 20c0505 commit b232852
Show file tree
Hide file tree
Showing 14 changed files with 1,163 additions and 315 deletions.
13 changes: 13 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.6.1 Jan 10 2015
. (kfsone) Added "--blackmarket" option to "run" command, restrictions
to stations which have a black market.
. (kfsone) Added "--end-jumps" ('-e') to "run" command, includes stations
from systems within this many jumps of the specified --to.
e.g.
trade.py run --from sol --to lave -e 3
will find runs from sol to somewhere within 3 jumps of lave.
. (kfsone) "rares" now has a friendly error when no rares are found
+ Data: kfsone, maddavo, Dave Ryalls, EDStarQuery/kfsone
[I'm adding several hundred new systems from EDStarQuery but I'm also
manually vetting all of them!]

v6.6.0 Jan 08 2015
. (kfsone) Overhaul of loading of trades and adjancent-system finding
- Item data is loaded as discrete sales and purchases in TradeCalc,
Expand Down
12 changes: 11 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,16 @@ RUN sub-command:

--start-jumps N
-s N
Considers stations from stations upto this many jumps from your
Considers stations from systems upto this many jumps from your
specified start location.
--from beagle2 --ly-per 7.56 --empty 10.56 -s 2

--end-jumps N
-e N
Considers stations from systems upto this many jumps from your
specified destination (--to).
--to lave -e 3 (find runs that end within 3 jumps of lave)

--via <station or system>
Lets you specify a station that must be between the second and final hop.
Requires that hops be at least 2.
Expand All @@ -249,6 +255,10 @@ RUN sub-command:
--pad ? (unknown only),
--pad L (large only, ignores unknown)

--black-market
-bm
Only consider stations that have a black market.

--ls-penalty N.NN
--lsp N.NN
DEFAULT: 0.5
Expand Down
32 changes: 26 additions & 6 deletions commands/TEMPLATE.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from __future__ import absolute_import, with_statement, print_function, division, unicode_literals
from commands.commandenv import ResultRow
from commands.parsing import MutuallyExclusiveGroup, ParseArgument
from formatting import RowFormat, ColumnFormat

######################################################################
# Parser config

help=#'Terse description of command'
name=#'cmd'
epilog=#None
wantsTradeDB=True
help = 'Describe your command briefly here for the top-level --help.'
name = 'TEMPLATE' # name of your .py file excluding the _cmd
epilog = None # text to print at the bottom of --help
wantsTradeDB = True # Should we try to load the cache at startup?
usesTradeData = True # Will we be needing trading data?
arguments = [
#ParseArgument('near', help='System to start from', type=str),
]
Expand All @@ -27,7 +30,19 @@
# Perform query and populate result set

def run(results, cmdenv, tdb):
from commands.commandenv import ResultRow
"""
Implement code that validates arguments, collects and prepares
any data you will need to generate your results for the user.
If your command has finished and has no output to generate,
return None, otherwise return "results" to be forwarded to
the 'render' function.
DO NOT print() during 'run', this allows run() functions to
be re-used between modules and allows them to be used beyond
the trade.py command line - e.g. someone writing a TD GUI
will call run() and then render the results themselves.
"""

### TODO: Implement

Expand All @@ -37,6 +52,11 @@ def run(results, cmdenv, tdb):
# Transform result set into output

def render(results, cmdenv, tdb):
from formatting import RowFormat, ColumnFormat
"""
If run() returns a non-None value, the trade.py code will then
call the corresponding render() function.
This is where you should generate any output from your command.
"""

### TODO: Implement
1 change: 1 addition & 0 deletions commands/commandenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, properties, argv, cmdModule):

self._cmd = cmdModule or __main__
self.wantsTradeDB = getattr(cmdModule, 'wantsTradeDB', True)
self.usesTradeData = getattr(cmdModule, 'usesTradeData', False)

# We need to relocate to the working directory so that
# we can load a TradeDB after this without things going
Expand Down
11 changes: 4 additions & 7 deletions commands/export_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def run(results, cmdenv, tdb):
raise CommandLineError("Save location '{}' not found.".format(str(exportPath)))

# connect to the database
if not cmdenv.quiet:
print("Using database '{}'".format(tdb.dbFilename))
cmdenv.NOTE("Using database '{}'", tdb.dbPath)
conn = tdb.getDB()
conn.row_factory = sqlite3.Row

Expand Down Expand Up @@ -114,12 +113,10 @@ def run(results, cmdenv, tdb):
tableName = row['name']
if tableName in ignoreList:
# ignore the table
if not cmdenv.quiet:
print("Ignore Table '{table}'".format(table=tableName))
cmdenv.NOTE("Ignore Table '{table}'", table=tableName)
continue

if not cmdenv.quiet:
print("Export Table '{table}'".format(table=tableName))
cmdenv.NOTE("Export Table '{table}'", table=tableName)

# create CSV files
lineCount, filePath = exportTableToFile(tdb, cmdenv, tableName, exportPath)
Expand All @@ -128,4 +125,4 @@ def run(results, cmdenv, tdb):
filePath.unlink()
cmdenv.DEBUG0("Delete empty file {file}'".format(file=filePath))

return None
return None
3 changes: 3 additions & 0 deletions commands/rares_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ def render(results, cmdenv, tdb):
the output of the command.
"""

if not results.rows:
raise CommandLineError("No items found.")

# Calculate the longest station name in our list.
longestStnName = max(results.rows, key=lambda result: len(result.rare.station.name())).rare.station
longestStnNameLen = len(longestStnName.name())
Expand Down
Loading

0 comments on commit b232852

Please sign in to comment.