コード例 #1
0
ファイル: Controller.py プロジェクト: ekitru/astro
 def initialization(self):
     """ Initialization for all components
     Opens DB connection and connection with PLCm also reads translation codes """
     #        try:
     logging.info('======= Program initialization =======')
     self.logThread = LogThread(self.resources)
     self.alarmLogThred = AlarmLogThread(self.resources)
コード例 #2
0
ファイル: Controller.py プロジェクト: ekitru/astro
class Controller(object):
    def __init__(self):
        self.__initLogger()
        self.resources = Resources()
        lang = self.resources.config.getDefaultLanguage()
        self.codes = TranslationConfig(lang)

        plcManager = self.resources.plcManager
        self.object = ObjectRepresenter(self.resources.object)
        self.tsTimes = TimeRepresenter(self.resources.observer)
        self.tsMode = TelescopeModeRepresenter(plcManager.getModeHelper())
        self.tsStatus = TelescopeStateRepresenter(plcManager.getStateHelper())
        self.tsPosition = PositionRepresenter(plcManager.getPositionHelper())
        self.tsControl = ControlModeRepresenter(self.resources, self)


    def __initLogger(self):
        """ Initialize base system logger  """
        logPath = getLogPath()
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                            datefmt='%m-%d %H:%M',
                            filename=join(logPath, 'common.log'),
                            filemode='w')

    def initialization(self):
        """ Initialization for all components
        Opens DB connection and connection with PLCm also reads translation codes """
        #        try:
        logging.info('======= Program initialization =======')
        self.logThread = LogThread(self.resources)
        self.alarmLogThred = AlarmLogThread(self.resources)

    #        except ConfigurationException as ce:
    #            logging.info('Error during initialization occure', ce)
    #            raise InitializationException(ce)
    #        except Exception as e:
    #            logging.info('Error during initialization occure', e)
    #            raise InitializationException(e)


    def freeResources(self):
        """ free all resources, close all connections """
        try:
            logging.info('======= Program closing =======')
            self.logThread.stop()
            self.alarmLogThred.stop()
            del self.resources
        except Exception as e:
            raise ClosingException(e)

    def isConnected(self):
        return self.resources.plcManager.isConnected()

    def forceLog(self):
        """ Force to log message and start new timer  """
        self.logThread.force()

    def updateLogTime(self, time):
        """ update logging period, time in minutes """
        self.logThread.updatePeriod(int(time) * 60)