diff --git a/commands/commandenv.py b/commands/commandenv.py index 59d1447f..6ec9b7cb 100644 --- a/commands/commandenv.py +++ b/commands/commandenv.py @@ -79,11 +79,12 @@ def run(self, tdb): self.checkVias() self.checkShip() - return self._cmd.run(CommandResults(self)) + results = CommandResults(self) + return self._cmd.run(results, self, tdb) def render(self, results): - self._cmd.render(self, results) + self._cmd.render(self, results, self, self.tdb) def checkMFD(self): diff --git a/commands/local_cmd.py b/commands/local_cmd.py index 97641b0e..a38743c9 100644 --- a/commands/local_cmd.py +++ b/commands/local_cmd.py @@ -1,7 +1,9 @@ from commands.commandenv import ResultRow from commands import MutuallyExclusiveGroup, ParseArgument from formatting import RowFormat, ColumnFormat -import math + +###################################################################### +# Parser config name='local' help='Calculate local systems.' @@ -40,7 +42,15 @@ ), ] +###################################################################### +# Helpers + class PillCalculator(object): + """ + Helper that calculates the position of stars relative to + a line of stars. + """ + def __init__(self, tdb, startStar, endStar, percent): lhs, rhs = tdb.lookupSystem(startStar), tdb.lookupSystem(endStar) self.normal = [ @@ -63,8 +73,10 @@ def distance(self, star): else: return dotProduct / self.pillLength +###################################################################### +# Perform query and populate result set -def run(results): +def run(results, cmdenv, tdb): cmdenv = results.cmdenv tdb = cmdenv.tdb srcSystem = cmdenv.nearSystem @@ -107,12 +119,15 @@ def run(results): return results +###################################################################### +# Transform result set into output -def render(results): - cmdenv = results.cmdenv +def render(results, cmdenv, tdb): + # Compare system names so we can tell + longestNamed = max(results.rows, + key=lambda row: len(row.system.name())) + longestNameLen = len(longestNamed.system.name()) - longestName = max(results.rows, key=lambda row: len(row.system.name())) - longestNameLen = len(longestName.system.name()) sysRowFmt = RowFormat().append( ColumnFormat("System", '<', longestNameLen, key=lambda row: row.system.name())