# Path: umit/icm/agent/gui/dashboard/timeline/Calendar.py
# (INC_YEAR, INC_MONTH, INC_DAY, INC_HOUR) = (
#     (DEC_YEAR, DEC_MONTH, DEC_DAY, DEC_HOUR)) = range(4)
# def monthname(month, first=-1):
# def isleap(year):
# def startup_calendar_opts():
#     def __init__(self, year, month, day, hour, year_range, first_weekday=0):
#     def get_dryrun(self):
#     def set_dryrun(self, enable):
#     def validate_date(self, year, month, day, hour):
#     def get_current_firstlast_firstwday(self):
#     def get_firstlast_firstwday(self, year, month):
#     def get_date(self, model=None):
#     def get_current_weekday_name(self):
#     def get_current_weekday_no(self):
#     def get_current_weekday(self):
#     def get_weekday(self, year, month, day):
#     def get_year_range(self):
#     def set_year_range(self, yrange):
#     def get_year(self):
#     def set_year(self, year):
#     def get_month(self):
#     def set_month(self, month):
#     def get_current_monthrange(self):
#     def get_monthrange(self, year, month):
#     def get_day(self):
#     def set_day(self, day):
#     def get_first_weekday(self):
#     def set_first_weekday(self, fwday):
#     def get_hour(self):
#     def set_hour(self, hour):
#     def fix_date(self):
#     def inc_date(self, param, inc=1):
#     def dec_date(self, param, inc=-1):
#     def __inc_year(self, inc=1):
#     def __inc_month(self, inc=1):
#     def __inc_day(self, inc=1):
#     def __inc_hour(self, inc=1):
# class Error(Exception):
# class OutOfRangeError(Error):
# class YearOutOfRangeError(OutOfRangeError):
# class YearRangeOutOfRangeError(OutOfRangeError):
# class MonthOutOfRangeError(OutOfRangeError):
# class DayOutOfRangeError(OutOfRangeError):
# class HourOutOfRangeError(OutOfRangeError):
# class FirstWeekdayOutOfRangeError(OutOfRangeError):
# class CalendarManager(object):
# 
# Path: umit/icm/agent/gui/dashboard/timeline/Calendar.py
# def isleap(year):
#     """
#     Returns True for leap years.
#     """
#     return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
# 
# Path: umit/icm/agent/I18N.py
#     LC_ALL = locale.setlocale(locale.LC_ALL,'')
#     LC_ALL = locale.setlocale(locale.LC_ALL, None)        
# LANG = None
# ENC = None
#     LANG = "en_US"
#     LANG = "zh_CN"
#     LANG = "pt"
#     LANG = "ja"
#     LANG, ENC = locale.getdefaultlocale()
#     ENC = "utf8"
#     LANG = "en_US"   
# 
# Path: umit/icm/agent/Application.py
# def main_is_frozen():
#     def __init__(self):
#     def _init_components(self, aggregator):
#     def _load_from_db(self):
#     def init_after_running(self, port=None, username=None, password=None,
#                            server_enabled=True, skip_server_check=False):
#     def check_aggregator_success(self,response):
#     def login_window_show(self):       
#     def check_aggregator_failed(self,message):
#     def login_without_gui(self):
#     def check_software_auto(self):
#     def register_agent(self, username, password):
#     def _handle_register(self, result):
#     def _handle_errback(self, failure):
#     def login(self, username, password, save_login=False, login_only=False):
#     def check_username(self,username="",password=""):
#     def _login_after_register_callback(self, message, username,
#                                        password, save_login, login_only):
#     def _handle_login_errback(self,failure):
#     def _handle_login(self, result, username, password, save_login,login_only=False):
#     def login_simulate(self):
#     def task_loop_manager(self):
#     def logout(self):
#     def _handle_logout(self, result):
#     def start(self, run_reactor=True, managed_mode=False, aggregator=None):
#     def quit_window_in_wrong(self,primary_text = "",secondary_text = ""):
#     def terminate(self):
#     def on_quit(self):
# class Application(object):
# 
# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'


import datetime
from umit.icm.agent.gui.dashboard.timeline.Calendar import mdays
from umit.icm.agent.gui.dashboard.timeline.Calendar import isleap
from umit.icm.agent.I18N import _
from umit.icm.agent.Global import *
from umit.icm.agent.Application import theApp
from umit.icm.agent.logger import g_logger
from umit.icm.agent.gui.dashboard.DashboardListBase import  *
    def changes_by_category_in_range(self, args,choice_tab=None):
        """
        Generic function for changes_anything 
        (choice_tab can provide report, task tab choice)
        (This method also received the range )
        """
        
        if len(args) == 1: # yearly
            return self.changes_in_year(args[0], choice_tab)
        elif len(args) == 2: # monthly
            return self.changes_in_month(args[0], args[1], choice_tab)
        elif len(args) == 3: # daily
            return self.changes_in_day(args[0], args[1], args[2], choice_tab)
        elif len(args) == 4: # hourly
            return self.changes_in_hour(args[0], args[1], args[2], args[3],choice_tab)
        else:
            g_logger.error("Invalid number of parameters specified")

    def timerange_changes_count_generic(self,start,end,choice_tab):
        """
        Selects what method to use to grab changes count.
        """
        
        #start and end should always 
        if not start or not end:
            g_logger.error("You should specify range start and range end")
            return
        
        #check choice_tab
        if not choice_tab:

# Path: umit/icm/agent/gui/dashboard/timeline/Calendar.py
# (INC_YEAR, INC_MONTH, INC_DAY, INC_HOUR) = (
#     (DEC_YEAR, DEC_MONTH, DEC_DAY, DEC_HOUR)) = range(4)
# def monthname(month, first=-1):
# def isleap(year):
# def startup_calendar_opts():
#     def __init__(self, year, month, day, hour, year_range, first_weekday=0):
#     def get_dryrun(self):
#     def set_dryrun(self, enable):
#     def validate_date(self, year, month, day, hour):
#     def get_current_firstlast_firstwday(self):
#     def get_firstlast_firstwday(self, year, month):
#     def get_date(self, model=None):
#     def get_current_weekday_name(self):
#     def get_current_weekday_no(self):
#     def get_current_weekday(self):
#     def get_weekday(self, year, month, day):
#     def get_year_range(self):
#     def set_year_range(self, yrange):
#     def get_year(self):
#     def set_year(self, year):
#     def get_month(self):
#     def set_month(self, month):
#     def get_current_monthrange(self):
#     def get_monthrange(self, year, month):
#     def get_day(self):
#     def set_day(self, day):
#     def get_first_weekday(self):
#     def set_first_weekday(self, fwday):
#     def get_hour(self):
#     def set_hour(self, hour):
#     def fix_date(self):
#     def inc_date(self, param, inc=1):
#     def dec_date(self, param, inc=-1):
#     def __inc_year(self, inc=1):
#     def __inc_month(self, inc=1):
#     def __inc_day(self, inc=1):
#     def __inc_hour(self, inc=1):
# class Error(Exception):
# class OutOfRangeError(Error):
# class YearOutOfRangeError(OutOfRangeError):
# class YearRangeOutOfRangeError(OutOfRangeError):
# class MonthOutOfRangeError(OutOfRangeError):
# class DayOutOfRangeError(OutOfRangeError):
# class HourOutOfRangeError(OutOfRangeError):
# class FirstWeekdayOutOfRangeError(OutOfRangeError):
# class CalendarManager(object):
# 
# Path: umit/icm/agent/gui/dashboard/timeline/Calendar.py
# def isleap(year):
#     """
#     Returns True for leap years.
#     """
#     return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
# 
# Path: umit/icm/agent/I18N.py
#     LC_ALL = locale.setlocale(locale.LC_ALL,'')
#     LC_ALL = locale.setlocale(locale.LC_ALL, None)        
# LANG = None
# ENC = None
#     LANG = "en_US"
#     LANG = "zh_CN"
#     LANG = "pt"
#     LANG = "ja"
#     LANG, ENC = locale.getdefaultlocale()
#     ENC = "utf8"
#     LANG = "en_US"   
# 
# Path: umit/icm/agent/Application.py
# def main_is_frozen():
#     def __init__(self):
#     def _init_components(self, aggregator):
#     def _load_from_db(self):
#     def init_after_running(self, port=None, username=None, password=None,
#                            server_enabled=True, skip_server_check=False):
#     def check_aggregator_success(self,response):
#     def login_window_show(self):       
#     def check_aggregator_failed(self,message):
#     def login_without_gui(self):
#     def check_software_auto(self):
#     def register_agent(self, username, password):
#     def _handle_register(self, result):
#     def _handle_errback(self, failure):
#     def login(self, username, password, save_login=False, login_only=False):
#     def check_username(self,username="",password=""):
#     def _login_after_register_callback(self, message, username,
#                                        password, save_login, login_only):
#     def _handle_login_errback(self,failure):
#     def _handle_login(self, result, username, password, save_login,login_only=False):
#     def login_simulate(self):
#     def task_loop_manager(self):
#     def logout(self):
#     def _handle_logout(self, result):
#     def start(self, run_reactor=True, managed_mode=False, aggregator=None):
#     def quit_window_in_wrong(self,primary_text = "",secondary_text = ""):
#     def terminate(self):
#     def on_quit(self):
# class Application(object):
# 
# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'


# Path: umit/icm/agent/gui/dashboard/timeline/DataGrabber.py
import datetime
from umit.icm.agent.gui.dashboard.timeline.Calendar import mdays
from umit.icm.agent.gui.dashboard.timeline.Calendar import isleap
from umit.icm.agent.I18N import _
from umit.icm.agent.Global import *
from umit.icm.agent.Application import theApp
from umit.icm.agent.logger import g_logger
from umit.icm.agent.gui.dashboard.DashboardListBase import  *

    def changes_by_category_in_range(self, args,choice_tab=None):
        """
        Generic function for changes_anything 
        (choice_tab can provide report, task tab choice)
        (This method also received the range )
        """
        
        if len(args) == 1: # yearly
            return self.changes_in_year(args[0], choice_tab)
        elif len(args) == 2: # monthly
            return self.changes_in_month(args[0], args[1], choice_tab)
        elif len(args) == 3: # daily
            return self.changes_in_day(args[0], args[1], args[2], choice_tab)
        elif len(args) == 4: # hourly
            return self.changes_in_hour(args[0], args[1], args[2], args[3],choice_tab)
        else:
            g_logger.error("Invalid number of parameters specified")

    def timerange_changes_count_generic(self,start,end,choice_tab):
        """
        Selects what method to use to grab changes count.
        """
        
        #start and end should always 
        if not start or not end:
            g_logger.error("You should specify range start and range end")
            return
        
        #check choice_tab
        if not choice_tab:

            g_logger.error("You should specify choice_tab")