#!/usr/bin/env python
# Lyle Scott, III  // lyle@digitalfoo.net // Copyright 2013

import json
import os
import sys


#path = os.path.dirname(os.path.realpath(__file__))
#sys.path.insert(0, '%s/src' % path)

try:
    import constants
except ImportError:
    print '''Problem importing src/constants.py. Make sure
src/constants.py.sample is copied to src/constants.py and is setup
properly.'''
    sys.exit(3)

from parsers import ParserEmail
from parsers import ParserLog


def usage():
    """Usage statement."""
    me = sys.argv[0]
    print 'USAGE: %s' % me
    sys.exit(1)


def pre_checks():
    if not os.path.exists('src/constants.py'):
        print ('Copy constants.py.sample to constants.py and fill in the '
            'appropriate options.')
        exit(2)


def get_parsers():
    """Parse arguments."""
    objs = []

    if constants.getConstant('EMAIL_ENABLE'):
        objs.append(ParserEmail)

    if constants.getConstant('LOG_ENABLE'):
        objs.append(ParserLog)

    return objs


def run(args):
    """Do work."""
    pre_checks()
    with open('locations.json', 'w') as fp:
        fp.write('var locations = ')
        for parser in get_parsers():
            results = parser.run()
            if results:
                json.dump(list(results), fp)
        fp.write(';')        


if __name__ == '__main__':
    run(get_parsers())

@@ -1057,97 +1057,33 @@
 s()%0A
+%0A
     
-with open('locations.json', 'w') as fp:%0A        fp.write('var locations = ')%0A  
+allresults = %5B%5D%0A
     
-  
 for 
@@ -1107,20 +1107,16 @@
 sers():%0A
-    
         
@@ -1150,32 +1150,129 @@
     
-    if results:%0A        
+allresults.extend(list(results or %5B%5D))%0A%0A    with open('locations.json', 'w') as fp:%0A        fp.write('var locations = ')%0A
     
@@ -1289,21 +1289,18 @@
 ump(
-list(
+all
 results
-)
 , fp
@@ -1322,24 +1322,16 @@
 ite(';')
-        
 %0A%0A%0Aif __

fix bug where multiple input sources corrupted the json file.