コード例 #1
0
    def init_standalone(self, path="./", config=None):
        """ Start the component isolated of system """
        self.ME_PATH = path  # Path of current component
        self.ME_STANDALONE = True
        if not Misc.existsFile("config.yaml", self.ME_PATH):
            raise ValueError(Messages.config_no_file)

        self.ME_CONFIG_PATH = normpath(self.ME_PATH + "/config.yaml")
        self.ME_CONFIG = Misc.readConfig(
            self.ME_CONFIG_PATH) if config == None else config
        self.CP = CommPool(self.ME_CONFIG, standAlone=True)

        self.load()
コード例 #2
0
ファイル: monitor.py プロジェクト: Turing-IA-IHC/Home-Monitor
    def __init__(self, vars=[]):
        """ Start the sub system to monitor the health of the entire system
            Vars: Set any config var using form VAR=VALUE
        """
        print('\n')
        print('=========================='.center(50, "="))
        print(' Wellcome to Home-Monitor '.center(50, "="))
        print(' Version: {} '.format(__version__).center(50, " "))
        print('=========================='.center(50, "="))
        print(' Health Monitor System '.center(50, "="))
        print('=========================='.center(50, "="))
        print('')

        self.CONFIG_FILE = normpath(abspath('.') + "/config.yaml")
        self.CONFIG = Misc.readConfig(self.CONFIG_FILE)

        # Replacing config vars
        Misc.replaceConfigVars(self.CONFIG, vars)
        Misc.showConfig(self.CONFIG)

        self.commPool = CommPool(self.CONFIG)

        current_os = platform.system()
        if current_os == 'Windows':
            print(' Press esc or x to exit '.center(50, "="))
            import msvcrt

        chk_time = Misc.hasKey(self.CONFIG, 'CHECKING_TIME', 30)
        while True:
            if current_os == 'Windows':
                if msvcrt.kbhit():
                    keyPressed = ord(msvcrt.getch())
                    if keyPressed in [27, 120]:
                        break

            pool_msg = self.commPool.count()

            for i in range(chk_time):
                msg = '{} - Refreshing time: {} Seg.'.format(
                    pool_msg, (chk_time - i))
                if Misc.toBool(Misc.hasKey(self.CONFIG, 'RUN_IN_COLLAB', 'N')):
                    sys.stdout.write('\r' + msg)
                else:
                    print(msg, end='\r', flush=True)

                sleep(1)
コード例 #3
0
    def start(self):
        """ Start load of all device controllers """
        cp = CommPool(self.CONFIG, preferred_url=CommPool.URL_TICKETS)
        cp.logFromCore(Messages.system_controllers_connect.format(cp.URL_BASE),
                       LogTypes.INFO, self.__class__.__name__)

        while True:
            #cp.logFromCore(Messages.controller_searching, LogTypes.DEBUG, self.__class__.__name__)
            controllersFolders = Misc.lsFolders("./Controllers")
            for cf in controllersFolders:
                if Misc.hasKey(self.controllers, cf, None) == None:
                    comp = Component(cf, cp)
                    self.controllers[cf] = comp

            for c in self.controllers:
                comp = self.controllers[c]
                comp.load()

            sleep(self.CHECKING_TIME)

        cp.logFromCore(Messages.controller_stop, LogTypes.INFO,
                       self.__class__.__name__)
コード例 #4
0
ファイル: main.py プロジェクト: Turing-IA-IHC/Home-Monitor
    def __init__(self, components: int, vars=[]):
        """ 
            Start whole system and all sub systems.
            components is a number between 1 and 15.
            components represents a binary of 4 positions being:
                components[0] => DataPool   : Example 1
                components[1] => Controllers: Example 2
                components[2] => Recognizers: Exmaple 4
                components[3] => Analyzers  : Exmaple 8
            To load all sub system set 15 to 'components' parameter.
            It is possible to combine the starting of some subsystems, for example, 
            to load DataPool and recognizer only set 5 to 'components' parameter.
            Vars: Set any config var using form VAR=VALUE
        """
        print('\n')
        print('=========================='.center(50, "="))
        print(' Wellcome to Home-Monitor '.center(50, "="))
        print(' Version: {} '.format(__version__).center(50, " "))
        print('=========================='.center(50, "="))
        print('')

        # Verify components to load param
        if components < 1 or components > 15:
            Binnacle().logFromCore(Messages.nothing_to_load, LogTypes.WARNING,
                                   self.__class__.__name__)
            return

        # Loading configuration file
        self.CONFIG_FILE = normpath(abspath('.') + "/config.yaml")
        if not exists(self.CONFIG_FILE):
            Binnacle().loggingSettings(
                LogTypes.ERROR, '',
                '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            Binnacle().logFromCore(Messages.config_no_file + self.CONFIG_FILE,
                                   LogTypes.ERROR, self.__class__.__name__)
            return
        self.CONFIG = Misc.readConfig(self.CONFIG_FILE)

        # Replacing config vars
        Misc.replaceConfigVars(self.CONFIG, vars)
        Misc.showConfig(self.CONFIG)

        # Logging Configuration
        tm = gmtime()
        if Misc.toBool(Misc.hasKey(self.CONFIG, 'LOGGING_TO_FILE', 'False')):
            loggingFile = '{}.log'.format(
                str(tm.tm_year) + '%02d' % tm.tm_mon + '%02d' % tm.tm_mday)
            loggingFile = normpath(
                Misc.hasKey(self.CONFIG, 'LOGGING_PATH' + "/", "./") +
                loggingFile)
            self.CONFIG['LOGGING_FILE'] = loggingFile
        Binnacle().loggingConf(self.CONFIG)

        # Define which component should be started
        toStart = "%04d" % int(str(bin(components)).replace("0b", ""))
        #print('')
        Binnacle().logFromCore(Messages.system_start, LogTypes.INFO,
                               self.__class__.__name__)
        Binnacle().logFromCore(Messages.system_start_components + toStart,
                               LogTypes.INFO, self.__class__.__name__)
        #print('')

        self.must_start_pool = toStart[3] == '1'
        self.must_start_controllers = toStart[2] == '1'
        self.must_start_recognizers = toStart[1] == '1'
        self.must_start_analyzers = toStart[0] == '1'

        self.commPool = CommPool(self.CONFIG)
        if not self.must_start_pool and components > 1:
            self.check_pool_connection()

        if self.must_start_pool:
            self.start_pool()
        if self.must_start_controllers:
            self.start_controllers()
        if self.must_start_recognizers:
            self.start_recognizers()
        if self.must_start_analyzers:
            self.start_analyzers()

        self.heart_beat()