# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'


import os,sys,platform
        import _winreg as Regedit
        import _winreg as Regedit
        import shutil
from umit.icm.agent.logger import g_logger
from umit.icm.agent.BasePaths import *
from umit.icm.agent.Global import *

        try:
            tag = self.regedit_path
            key = Regedit.OpenKey(regedit,tag,0,Regedit.KEY_WRITE)
            try:
                try:
                    Regedit.SetValueEx(key,self.key_name,0,Regedit.REG_SZ,self.exe_path)                    
                    Regedit.DeleteValue(key,self.key_name)
                    g_logger.info("Cancel Auto StartUP")
                except EnvironmentError:
                    g_logger.error("Cancel Auto StartUP Error in Windows (%s,%s)" % (tag,self.key_name))
                    raise
            finally:
                Regedit.CloseKey(key)
        finally:
            Regedit.CloseKey(regedit)    
                
    def _linux_set(self):
        if  not os.path.exists(self.auto_sys_path):
            os.mkdir(self.auto_sys_path)
        try:
            shutil.copy(self.auto_desktop_file, self.auto_sys_path+self.desktop_name)
            g_logger.info("Auto StartUP icm-agent in Linux (%s,%s)" %(self.auto_desktop_file,self.auto_sys_path))
        except Exception,e:
            g_logger.error("[Failed]Auto StartUP icm-agent in Linux (%s,%s,%s)" % (self.auto_desktop_file,self.auto_sys_path,e) )
                      
    def _linux_clear(self):
        file = self.auto_sys_path + self.desktop_name
        if os.path.exists(file):
            try:
                os.remove(file)

# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'


# Path: umit/icm/agent/utils/Startup.py
import os,sys,platform
        import _winreg as Regedit
        import _winreg as Regedit
        import shutil
from umit.icm.agent.logger import g_logger
from umit.icm.agent.BasePaths import *
from umit.icm.agent.Global import *

        try:
            tag = self.regedit_path
            key = Regedit.OpenKey(regedit,tag,0,Regedit.KEY_WRITE)
            try:
                try:
                    Regedit.SetValueEx(key,self.key_name,0,Regedit.REG_SZ,self.exe_path)                    
                    Regedit.DeleteValue(key,self.key_name)
                    g_logger.info("Cancel Auto StartUP")
                except EnvironmentError:
                    g_logger.error("Cancel Auto StartUP Error in Windows (%s,%s)" % (tag,self.key_name))
                    raise
            finally:
                Regedit.CloseKey(key)
        finally:
            Regedit.CloseKey(regedit)    
                
    def _linux_set(self):
        if  not os.path.exists(self.auto_sys_path):
            os.mkdir(self.auto_sys_path)
        try:
            shutil.copy(self.auto_desktop_file, self.auto_sys_path+self.desktop_name)
            g_logger.info("Auto StartUP icm-agent in Linux (%s,%s)" %(self.auto_desktop_file,self.auto_sys_path))
        except Exception,e:
            g_logger.error("[Failed]Auto StartUP icm-agent in Linux (%s,%s,%s)" % (self.auto_desktop_file,self.auto_sys_path,e) )
                      
    def _linux_clear(self):
        file = self.auto_sys_path + self.desktop_name
        if os.path.exists(file):
            try:
                os.remove(file)

                g_logger.info("Cancel Auto StartUP icm-agent in Linux (%s)" %(file)) 
