Skip to content

Commit

Permalink
More tweaks to edscupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Smith committed Feb 20, 2015
1 parent 249b423 commit ca4fc78
Showing 1 changed file with 47 additions and 14 deletions.
61 changes: 47 additions & 14 deletions edscupdate.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import re
import sys
import tradedb
import tradeenv


# Systems we know are bad.
Expand All @@ -52,11 +53,13 @@ def parse_arguments():
epilog='Confirmed systems are written to tmp/new.systems.csv.',
)
parser.add_argument(
'refsystem',
'refSystem',
help='*Exact* name of the system you are *currently* in, '
'used as a reference system for distance validations.',
type=str,
metavar='"REFERENCE SYSTEM"',
default=None,
nargs='?',
)
parser.add_argument(
'--cmdr',
Expand Down Expand Up @@ -102,11 +105,38 @@ def parse_arguments():
dest='splash',
default=True,
)
parser.add_argument(
'--summary',
required=False,
help='Check for and report on new systems but do no work.',
action='store_true',
)
parser.add_argument(
'--detail', '-v',
help='Increase level of detail in output.',
default=0,
required=False,
action='count',
)
parser.add_argument(
'--debug', '-w',
help='Enable/raise level of diagnostic output.',
default=0,
required=False,
action='count',
)

argv = parser.parse_args(sys.argv[1:])
if not argv.cmdr:
raise UsageError("No --cmdr specified / no CMDR environment variable")
dateRe = re.compile(r'^20\d\d-(0\d|1[012])-([012]\d|3[01]) ([01]\d|2[0123]):[0-5]\d:[0-5]\d$')
if not argv.summary:
if not argv.cmdr:
raise UsageError("No --cmdr specified / no CMDR environment variable")
if not argv.refSystem:
raise UsageError(
"Must specify a reference system name (when not using "
"--summary). Be sure to put the name in double quotes, "
"e.g. \"SOL\" or \"I BOOTIS\".\n"
)
if argv.date and not dateRe.match(argv.date):
raise UsageError(
"Invalid date: '{}', expecting YYYY-MM-DD HH:MM:SS format."
Expand Down Expand Up @@ -206,19 +236,22 @@ def add_to_extras(argv, name):
def main():
argv = parse_arguments()

tdb = tradedb.TradeDB()
tdenv = tradeenv.TradeEnv(properties=argv)
tdb = tradedb.TradeDB(tdenv)
if not argv.date:
argv.date = tdb.query("SELECT MAX(modified) FROM System").fetchone()[0]

try:
argv.startSys = tdb.lookupSystem(argv.refsystem)
except (LookupError, tradedb.AmbiguityError):
raise UsageError(
"Unrecognized system '{}'. Reference System must be an existing "
"system that TD already knows about.\n"
"Did you forget to put double-quotes around the refsystem name?"
.format(argv.refsystem)
)
if not argv.summary:
try:
argv.startSys = tdb.lookupSystem(argv.refSystem)
except (LookupError, tradedb.AmbiguityError):
raise UsageError(
"Unrecognized system '{}'. Reference System must be an "
"*exact* name for a system that TD already knows.\n"
"Did you forget to put double-quotes around the reference "
"system name?"
.format(argv.refSystem)
)

print("start date: {}".format(argv.date))

Expand All @@ -245,7 +278,7 @@ def main():
]
print("{} deltas".format(len(systems)))

if len(systems) <= 0:
if argv.summary or len(systems) <= 0:
return

if argv.random:
Expand Down

0 comments on commit ca4fc78

Please sign in to comment.