예제 #1
0
 def __init__(self, lgt, lat, use_cron, myxpl, log):
     """
     Init the dawndusk API
     @param lgt : longitude of the observer
     @param lat : latitude of the observer
     """
     self.use_cron = use_cron
     self.log = log
     self.myxpl = myxpl
     if self.use_cron == False:
         self._scheduler = Scheduler()
         self._scheduler.start()
     else:
         self._cronquery = CronQuery(self.myxpl, self.log)
     self.mycity = ephem.Observer()
     self.mycity.lat, self.mycity.lon = lat, lgt
     self.mycity.horizon = '-6'
     self.job = None
     self.job_test_dawn = None
     self.job_test_dusk = None
예제 #2
0
 def setUp(self):
     global sendplugin
     self.__myxpl = sendplugin.myxpl
     self.cronquery = CronQuery(self.__myxpl)
예제 #3
0
    def __init__(self):
        """
        Create the cron class
        """
        XplPlugin.__init__(self, name = 'earth')
        self.log.debug("__init__ : Start ...")

        self.config = Query(self.myxpl, self.log)
        try:
            delay_cron = int(self.config.query('earth', 'delay-cron'))
        except:
            delay_cron = 30
            error = "Can't get configuration from XPL : %s" %  (traceback.format_exc())
            self.log.warning("__init__ : " + error)
            self.log.warning("Continue with default values.")

        cron = CronQuery(self.myxpl, self.log)
        cont = 3
        cron_started = False
        while not self.get_stop().isSet() and cont>=0:
            try :
                res = cron.is_running_server()
            except :
                pass
            if res :
                cron_started = True
                cont = -1
            else:
                self.log.debug("Can't talk to cron plugin. Retries=%s" % cont)
                self.get_stop().wait(delay_cron)
                cont -= 1
        if not cron_started :
            self.force_leave()
            error = "Can't talk to cron plugin. Exiting ..."
            self.log.error("__init__ : "+error)
            return
        else :
            self.log.info("Communication with the cron plugin established.")
        self.log.debug("__init__ : Try to start the earth API")
        try:
            self._earth = EarthAPI(self.log, self.config, self.myxpl, \
                            self.get_data_files_directory(), \
                            self.get_stop(), self.get_sanitized_hostname())
        except:
            self.force_leave()
            error = "Something went wrong during EarthAPI init : %s" %  \
                     (traceback.format_exc())
            self.log.error("__init__ : "+error)
            return

        self.log.debug("__init__ : Try to create listeners")
        Listener(self.request_cb, self.myxpl,
             {'schema': 'earth.request', 'xpltype': 'xpl-cmnd'})
        Listener(self.fired_cb, self.myxpl,
              {'schema': 'earth.basic', 'xpltype': 'xpl-trig', 'current': 'fired'})
        Listener(self.basic_cb, self.myxpl,
             {'schema': 'earth.basic', 'xpltype': 'xpl-cmnd'})

        self.add_stop_cb(self._earth.stop_all)

        self.log.debug("__init__ : Enable the heartbeat")
        self.enable_hbeat()

        self._earth.plugin_enabled(True)

        self.log.info("Plugin earth correctly started.")