# Path: libAirSuck/asLog.py
# class asLog():
#     """
#     airSuck logging class.
#     """
#     
#     def __init__(self, loggingMode="stdout"):
#         """
#         asLog constructor
#         """
#         
#         # Check for acceptable logging mode.
#         if loggingMode in ('stdout', 'syslog', 'none'):
#             # Set class-wide logging mode.
#             self.mode = loggingMode
#         else:
#             raise ValueError("Valid loging mode not specified. Please use 'stdout', 'syslog', or 'none'.")
#         
#         if loggingMode == "syslog":
#             syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)
#     
#     def __logStdout(self, message):
#         """
#         Log a message to stdout with a UTC timestamp.
#         """
#         # Get timestamp.
#         dts = str(datetime.datetime.utcnow())
#         
#         # Keep the log looking pretty and uniform.
#         if len(dts) == 19:
#             dts = dts + ".000000"
#         
#         # Dump the message.
#         sys.stdout.write("%s - %s\n" %(dts, message))
#     
#     def __logSyslog(self, message, sev=syslog.LOG_NOTICE):
#         """
#         Log a message to syslog.
#         """
#         
#         # Log it.
#         syslog.syslog(sev, message)
#     
#     def log(self, message):
#         """
#         Log a message.
#         """
#         
#         try:
#             # If we don't want to do anything...
#             if self.mode == "stdout":
#                 # Log to stdout.
#                 self.__logStdout(message)
#             
#             elif self.mode == "syslog":
#                 # Log to syslog. Not fully implemented yet.
#                 self.__logSyslog(message)
#             
#             elif self.mode == "none":
#                 # This logs absolutely nothing.
#                 None
#         
#         except KeyboardInterrupt:
#             raise KeyboardInterrupt
#         
#         except:
#             tb = traceback.format_exc()
#             print("airSuck logger failure:\n%s" %tb)


	import config
import sys
import redis
import pymongo
import time
import json
import datetime
import traceback
from libAirSuck import asLog
from pprint import pprint
# Convert datetime objects expressed as a string back to datetime
def str2Datetime(strDateTime):
    """
    Convert utcnow() datetime string back to a datetime object.
    """
    retVal = None
    
    try:
        # Check the length of the string since frames received on the second sometimes lack the %f portion of the data.
        if (len(strDateTime) == 19):
            strDateTime = strDateTime + ".000000"
        
        # Attempt to convert the date.
        retVal = datetime.datetime.strptime(strDateTime, "%Y-%m-%d %H:%M:%S.%f")
    
    except:
        tb = traceback.format_exc()
        logger.log("Failed to convert string to datetime:\n%s" %tb)
    
    return retVal

# Decapsulate the JSON data.
def dejsonify(msg):
        return json.loads(msg)

# Insert records into specified mongo instance
def serializeADSB(entry):
        mDBColl.insert(entry)

# Set up the logger.

# Path: libAirSuck/asLog.py
# class asLog():
#     """
#     airSuck logging class.
#     """
#     
#     def __init__(self, loggingMode="stdout"):
#         """
#         asLog constructor
#         """
#         
#         # Check for acceptable logging mode.
#         if loggingMode in ('stdout', 'syslog', 'none'):
#             # Set class-wide logging mode.
#             self.mode = loggingMode
#         else:
#             raise ValueError("Valid loging mode not specified. Please use 'stdout', 'syslog', or 'none'.")
#         
#         if loggingMode == "syslog":
#             syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)
#     
#     def __logStdout(self, message):
#         """
#         Log a message to stdout with a UTC timestamp.
#         """
#         # Get timestamp.
#         dts = str(datetime.datetime.utcnow())
#         
#         # Keep the log looking pretty and uniform.
#         if len(dts) == 19:
#             dts = dts + ".000000"
#         
#         # Dump the message.
#         sys.stdout.write("%s - %s\n" %(dts, message))
#     
#     def __logSyslog(self, message, sev=syslog.LOG_NOTICE):
#         """
#         Log a message to syslog.
#         """
#         
#         # Log it.
#         syslog.syslog(sev, message)
#     
#     def log(self, message):
#         """
#         Log a message.
#         """
#         
#         try:
#             # If we don't want to do anything...
#             if self.mode == "stdout":
#                 # Log to stdout.
#                 self.__logStdout(message)
#             
#             elif self.mode == "syslog":
#                 # Log to syslog. Not fully implemented yet.
#                 self.__logSyslog(message)
#             
#             elif self.mode == "none":
#                 # This logs absolutely nothing.
#                 None
#         
#         except KeyboardInterrupt:
#             raise KeyboardInterrupt
#         
#         except:
#             tb = traceback.format_exc()
#             print("airSuck logger failure:\n%s" %tb)


# Path: mongoDump.py
	import config
import sys
import redis
import pymongo
import time
import json
import datetime
import traceback
from libAirSuck import asLog
from pprint import pprint

# Convert datetime objects expressed as a string back to datetime
def str2Datetime(strDateTime):
    """
    Convert utcnow() datetime string back to a datetime object.
    """
    retVal = None
    
    try:
        # Check the length of the string since frames received on the second sometimes lack the %f portion of the data.
        if (len(strDateTime) == 19):
            strDateTime = strDateTime + ".000000"
        
        # Attempt to convert the date.
        retVal = datetime.datetime.strptime(strDateTime, "%Y-%m-%d %H:%M:%S.%f")
    
    except:
        tb = traceback.format_exc()
        logger.log("Failed to convert string to datetime:\n%s" %tb)
    
    return retVal

# Decapsulate the JSON data.
def dejsonify(msg):
        return json.loads(msg)

# Insert records into specified mongo instance
def serializeADSB(entry):
        mDBColl.insert(entry)

# Set up the logger.

logger = asLog(config.connMongo['logMode'])