def prepareDaemon(self):
     """
     Prepare daemon
     """
     if not Settings.cfgFileIsPresent():
         sys.stdout.write(" (config file doesn't exist)")
         sys.exit(2)
     try:
         # Initialize
         Settings.initialize()
         Logger.initialize()
         CliFunctions.initialize(parent=self)
     except Exception as e:
         self.error("Unable to initialize settings: %s" % str(e))
     else:
         # config file exist so prepare the deamon
         self.prepare(
             pidfile="%s/%s/%s.pid" %
             (Settings.getDirExec(), Settings.get(
                 'Paths', 'run'), Settings.get('Server', 'acronym')),
             name=Settings.get('Server', 'name'),
             stdout="%s/%s/output.log" %
             (Settings.getDirExec(), Settings.get('Paths', 'logs')),
             stderr="%s/%s/output.log" %
             (Settings.getDirExec(), Settings.get('Paths', 'logs')),
             stdin="/dev/null",
             runningfile="%s/%s/%s.running" %
             (Settings.getDirExec(), Settings.get(
                 'Paths', 'run'), Settings.get('Server', 'acronym')),
         )
    def initialize(self,
                   ip,
                   port,
                   type,
                   name,
                   descr,
                   defaultTool,
                   supportProxy=False,
                   proxyIp=None,
                   proxyPort=None,
                   sslSupport=True,
                   isAgent=0,
                   fromCmd=False):
        """
        Initialize the tool

        @param ip:
        @type ip: 

        @param type:
        @type type: 

        @param name:
        @type name: 

        @param descr:
        @type descr: 
        """
        self.running = False
        self.defaultTool = defaultTool
        self.tool = None
        if not Settings.cfgFileIsPresent():
            sys.stdout.write(" (config file doesn't exist)")
            sys.exit(RETURN_CONFIG)

        try:
            Settings.initialize()
            Logger.initialize(
                logPathFile="%s/%s/%s.log" %
                (Settings.getDirExec(), Settings.get('Paths', 'logs'), name))
            if (isAgent, str(type)) in plugins:
                self.info("Initialize %s tool type=%s..." % (type, isAgent))

                if not len(ip): raise Exception("No controller ip specified!")
                if not len(name): raise Exception("No tool name specified!")

                self.tool = plugins[(isAgent, str(type))].initialize(
                    controllerIp=str(ip),
                    toolName=str(name),
                    toolDesc=str(descr),
                    defaultTool=defaultTool,
                    controllerPort=int(port),
                    supportProxy=supportProxy,
                    proxyIp=str(proxyIp),
                    proxyPort=proxyPort,
                    sslSupport=sslSupport)
                self.tool.setFromCmd()

                self.tool.onRegistrationSuccessful = self.onRegistrationSuccessful
                self.tool.onRegistrationFailed = self.onRegistrationFailed
                self.tool.onRegistrationRefused = self.onRegistrationRefused
                self.tool.onToolWarningCalled = self.onToolLogWarningCalled
                self.tool.onToolLogErrorCalled = self.onToolLogErrorCalled
                self.tool.onToolDisconnection = self.onToolDisconnection
                self.tool.onConnectionRefused = self.onConnectionRefused
                self.tool.onConnectionTimeout = self.onConnectionTimeout
                self.tool.onProxyConnectionTimeout = self.onProxyConnectionTimeout
                self.tool.onProxyConnectionRefused = self.onProxyConnectionRefused
                self.tool.onProxyConnectionError = self.onProxyConnectionError
                self.tool.checkPrerequisites()
                self.tool.startCA()
            else:
                self.error('tool type unknown: %s' % type)
                self.finalize(RETURN_TYPE_UNKNOWN)
        except Exception as e:
            self.error("unable to start tool: " + str(e))
            try:
                Settings.finalize()
            except:
                pass
            Logger.finalize()

        else:
            # run in loop
            self.running = True
            self.run()
Esempio n. 3
0
if __name__ == '__main__':
    app = QApplication(sys.argv)

    # initiliaze settings application, read settings from the ini file
    Settings.initialize()

    # initialize logger
    logPathFile = "%s/%s" % (QtHelper.dirExec(),
                             Settings.instance().readValue(key='Trace/file'))
    level = Settings.instance().readValue(key='Trace/level')
    size = Settings.instance().readValue(key='Trace/max-size-file')
    nbFiles = int(Settings.instance().readValue(key='Trace/nb-backup-max'))
    Logger.initialize(logPathFile=logPathFile,
                      level=level,
                      size=size,
                      nbFiles=nbFiles,
                      noSettings=True)

    # init the core plugin
    MyPlugin = CorePlugin.MainWindow(debugMode=DEBUGMODE)

    # create the main  widget
    WidgetSettings = SettingsPage(parent=MyPlugin)
    MyPlugin.addSettingsPage(widget=WidgetSettings)

    WidgetMain = MainPage(parent=MyPlugin)
    MyPlugin.addMainPage(pageName=WidgetSettings.cfg()["plugin"]["name"],
                         widget=WidgetMain)

    # register the main and settings page of the plugin