## ------------------------------------------------------------------------
## iSiLK - A python-based graphical user interface for SiLK
## ------------------------------------------------------------------------
## Copyright (c) 2007-2008 Carnegie Mellon University. All Rights Reserved.
## ------------------------------------------------------------------------
## Authors: Andrew Kompanek (ajk@cert.org)
## ------------------------------------------------------------------------
## GNU General Public License (GPL) Rights pursuant to Version 2, June 1991
## Government Purpose License Rights (GPLR) pursuant to DFARS 252.225-7013
## ------------------------------------------------------------------------
## See the LICENSE file included in this distribution
## ------------------------------------------------------------------------

import pdb
from config import OptionsGroup
from config import _xml_read_site_config
from config import _xml_save_site_config
from dateutils import DateRange

opts = {}

def init(readOptions=True):
    global opts
    opts["CLASS_TYPE_OPTIONS"] = DEFAULT_CLASS_TYPE_OPTIONS
    opts["SENSOR_OPTIONS"] = DEFAULT_SENSOR_OPTIONS
    opts["DATE_RANGE_OPTIONS"] = DEFAULT_DATE_RANGE_OPTIONS
    if readOptions:
        _read_options()

def _save_options():
    global opts
    opts_dicts = {}
    for k in opts:
        opts_dicts[k] = opts[k].todict()
    _xml_save_site_config("fglob", opts_dicts)
    
def _read_options():
    global opts
    try:
        opts = _xml_read_site_config("fglob")
        for k in opts:
            opts[k] = OptionsGroup(opts[k])
        return opts
    except IOError:
        return  None 
    
# Site-specific option
DEFAULT_CLASS_TYPE_OPTIONS = OptionsGroup ({
    "(1) Incoming"  : 
        {"type" : "in,inweb" },
    "(2) Outgoing"  : 
        {"type" : "out,outweb" },
    "(3) All"  : 
        {"type" : "out,outweb,in,inweb" }
})

# Site-specific option
DEFAULT_SENSOR_OPTIONS = OptionsGroup ({
    "(1) All Sensors"       : None
})


DEFAULT_DATE_RANGE_OPTIONS = OptionsGroup ({
    # MUSTFIXME: Remove before release
#    "(01) Test Range 1"    : DateRange.TEST_DATE_RANGE_1,
#    "(01) Test Range 2"    : DateRange.TEST_DATE_RANGE_2,    
    "(02) Current Hour"  : DateRange.CURRENT_HOUR,
    "(03) Today"         : DateRange.TODAY,
    "(04) Yesterday"     : DateRange.YESTERDAY,
    "(05) Previous Hour"     : DateRange.LAST_HOUR,
    "(06) Previous 24 Hours" : DateRange.LAST_24_HOURS,
    "(07) Previous 7 Days"   : DateRange.LAST_7_DAYS,
    "(08) Previous 14 Days"  : DateRange.LAST_14_DAYS,
    "(09) Previous 30 Days"  : DateRange.LAST_30_DAYS,
    "(99) Custom"       : None
})



