Skip to content

Commit

Permalink
Made it possible to redirect warnings to a file (--warnings-to) in em…
Browse files Browse the repository at this point in the history
…dn-tap
  • Loading branch information
kfsone committed Sep 9, 2014
1 parent eb82de5 commit 4b4bf28
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions emdn-tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# global variables: jeebus doesn't love me anymore.

warnOnly = False
warningFh = sys.stderr

blackMarketItems = frozenset([
'battleweapons',
Expand All @@ -47,7 +48,7 @@ def processCommandLine():
Process the command line with argparse.
"""

global warnOnly
global warnOnly, warningFh

parser = argparse.ArgumentParser(description='Pull updates from the EMDN firehose to the TradeDangerous DB')
parser.add_argument('--firehose', '-u', help='URI for the firehose. Default={}'.format(Firehose.defaultURI), default=None)
Expand All @@ -59,6 +60,7 @@ def processCommandLine():
parser.add_argument('--verbose', '-v', help='Increase verboseness.', action='count', default=0)
parser.add_argument('--no-writes', help='Don\'t actually write to the database.', action='store_true', default=False, dest='noWrites')
parser.add_argument('--warn', help='Demote unrecognized items/stations to warnings.', action='store_true', default=False)
parser.add_argument('--warn-to', help='Same as --warn but specifies file to write to.', dest='warnTo')
parser.add_argument('--commit', help='Automatically commit after this many seconds, 0 disables. Default: 90', type=int, default=90)

pargs = parser.parse_args()
Expand All @@ -83,6 +85,10 @@ def processCommandLine():
'every {} seconds'.format(pargs.commit) if pargs.commit else 'disabled'
))

if pargs.warnTo:
pargs.warn = True
warningFh = open(pargs.warnTo, 'w')

warnOnly = pargs.warn

return pargs
Expand Down Expand Up @@ -134,8 +140,11 @@ def bleat(category, name, *args, **kwargs):
bleatKey = '{}:{}'.format(category, name)

if not bleatKey in bleat.bleated:
import datetime
now = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
print(now, '[{} >> {}]'.format(category, name), *args, file=warningFh, **kwargs)
warningFh.flush()
bleat.bleated.add(bleatKey)
print(*args, file=sys.stderr, **kwargs)

if not warnOnly:
sys.exit(1)
Expand Down Expand Up @@ -257,3 +266,4 @@ def main():

if __name__ == "__main__":
main()

0 comments on commit 4b4bf28

Please sign in to comment.