# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'
# 
# 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/Version.py
# PEER_TYPE = get_peer_type(PEER_ATTRIBUTE)


import cPickle
        import re
from umit.icm.agent.logger import g_logger
from umit.icm.agent.Global import *
from umit.icm.agent.Application import theApp
from umit.icm.agent.Version import PEER_TYPE 
        from socket import socket, SOCK_DGRAM, AF_INET
        from twisted.web.client import getPage


        self.is_registered = False
        self.is_logged_in = False

        self.get_local_ip()
        self.get_internet_ip()

    def load_from_db(self):
        rs = g_db_helper.select('select * from peer_info')
        if not rs:
            g_logger.info("No peer info in db.")
        else:
            if len(rs) > 1:
                g_logger.warning("More than one record in user_info. " \
                                 "Use the first one.")
            g_logger.debug(rs[0])
            self.ID = rs[0][0]
            self.Username = rs[0][1]
            self.Password = rs[0][2]
            self.Email = rs[0][3]
            self.CipheredPublicKeyHash = rs[0][4]
            self.Type = rs[0][5]
            self.is_registered = True  

    def save_to_db(self):
        if self.is_registered:
            sql_str = "insert or replace into peer_info values " \
                            "('%s', '%s', '%s', '%s', '%s', %d)" % \
                            (self.ID, self.Username, self.Password, self.Email,
                             self.CipheredPublicKeyHash, self.Type)

# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'
# 
# 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/Version.py
# PEER_TYPE = get_peer_type(PEER_ATTRIBUTE)


# Path: umit/icm/agent/core/PeerInfo.py
import cPickle
        import re
from umit.icm.agent.logger import g_logger
from umit.icm.agent.Global import *
from umit.icm.agent.Application import theApp
from umit.icm.agent.Version import PEER_TYPE 
        from socket import socket, SOCK_DGRAM, AF_INET
        from twisted.web.client import getPage


        self.is_registered = False
        self.is_logged_in = False

        self.get_local_ip()
        self.get_internet_ip()

    def load_from_db(self):
        rs = g_db_helper.select('select * from peer_info')
        if not rs:
            g_logger.info("No peer info in db.")
        else:
            if len(rs) > 1:
                g_logger.warning("More than one record in user_info. " \
                                 "Use the first one.")
            g_logger.debug(rs[0])
            self.ID = rs[0][0]
            self.Username = rs[0][1]
            self.Password = rs[0][2]
            self.Email = rs[0][3]
            self.CipheredPublicKeyHash = rs[0][4]
            self.Type = rs[0][5]
            self.is_registered = True  

    def save_to_db(self):
        if self.is_registered:
            sql_str = "insert or replace into peer_info values " \
                            "('%s', '%s', '%s', '%s', '%s', %d)" % \
                            (self.ID, self.Username, self.Password, self.Email,
                             self.CipheredPublicKeyHash, self.Type)

            g_logger.info("[save_to_db]:save %s into DB"%sql_str)            
