Exemplo n.º 1
0
    def _process_results(self):
        occs = self.search.get_results()
        occsd = occs.get_dict()
        # Executing occs.get_active_dict here wouldn't make sense; let
        # NextOccurrencesEngine deal with snoozed and active alarms

        search_old_occurrences_end_event.signal(filename=self.filename)

        try:
            occsdf = occsd[self.filename]
        except KeyError:
            pass
        else:
            # Note that occsdf still includes occurrence times equal to
            # self.exclmint: these must be excluded because self.exclmint
            # is the time that was last already activated
            # The organism_alarms extension will check if the database is still
            # open while activating the alarms
            # Also note that as long as the handler of this event remains on
            # this thread, it's under the protection of
            # self._handle_save_permission_check
            activate_occurrences_range_event.signal(filename=self.filename,
                        mint=self.exclmint, maxt=self.whileago, occsd=occsdf)

        core_api.bind_to_save_permission_check(
                                    self._handle_save_permission_check, False)
Exemplo n.º 2
0
    def _process_results(self):
        occs = self.search.get_results()
        occsd = occs.get_dict()
        # Executing occs.get_active_dict here wouldn't make sense; let
        # NextOccurrencesEngine deal with snoozed and active alarms

        search_old_occurrences_end_event.signal(filename=self.filename)

        try:
            occsdf = occsd[self.filename]
        except KeyError:
            pass
        else:
            # Note that occsdf still includes occurrence times equal to
            # self.exclmint: these must be excluded because self.exclmint
            # is the time that was last already activated
            # The organism_alarms extension will check if the database is still
            # open while activating the alarms
            # Also note that as long as the handler of this event remains on
            # this thread, it's under the protection of
            # self._handle_save_permission_check
            activate_occurrences_range_event.signal(filename=self.filename,
                        mint=self.exclmint, maxt=self.whileago, occsd=occsdf)

        core_api.bind_to_save_permission_check(
                                    self._handle_save_permission_check, False)
Exemplo n.º 3
0
    def start(self):
        # Do not use directly NextOccurrencesEngine to search for old
        # occurrences when opening a database, in fact if the database hasn't
        # been opened for a while and it has _many_ old occurrences to
        # activate, NextOccurrencesEngine could recurse too many times,
        # eventually raising a RuntimeError exception
        # This function can also speed up opening an old database if it has
        # many occurrences to activate immediately

        # Search until 2 minutes ago and let NextOccurrencesEngine handle the
        # rest, so as to make sure not to interfere with its functionality
        self.whileago = int(time_.time()) - 120
        last_search = self.database.get_last_search()

        if self.whileago > last_search:
            log.debug('Search old occurrences')

            # Set the last search in this (main) thread, otherwise
            # NextOccurrencesEngine would race with this function, and possibly
            # do the same search, in fact still seeing the old last search
            # timestamp
            # Note that saving and closing the database after this point, but
            # before the search is finished and the old alarms are activated,
            # would lose all the old alarms; that's why saving must be
            # prevented while the search is ongoing
            core_api.bind_to_save_permission_check(
                                            self._handle_save_permission_check)
            self.database.set_last_search(self.whileago)

            # The "excl" in the name reminds that this time is exclusive, i.e.
            # only the occurrences strictly greater than the value will then be
            # activated, even though the search actually finds also those with
            # time equal to this value
            self.exclmint = last_search

            # Use a thread to let the GUI be responsive and possibly abort the
            # search
            # Start the thread with a timer to give some time for the
            # *interface* to finish opening the database, otherwise the
            # old alarms dialog will appear with a lot of delay and it will be
            # very hard to restrict the search range or skip the search
            # altogether
            # Note that DELAY shouldn't be too long, in fact self.restart and
            # self.abort are not protected, and if they're called during this
            # time, they crash because self.search hasn't been assigned yet
            thread = threading.Timer(self.DELAY, self._continue)
            thread.name = "organism_old_occurrences_{}".format(self.filename)
            # Do not set the thread as a daemon, it's better to properly handle
            # closing the database
            thread.start()
Exemplo n.º 4
0
    def start(self):
        # Do not use directly NextOccurrencesEngine to search for old
        # occurrences when opening a database, in fact if the database hasn't
        # been opened for a while and it has _many_ old occurrences to
        # activate, NextOccurrencesEngine could recurse too many times,
        # eventually raising a RuntimeError exception
        # This function can also speed up opening an old database if it has
        # many occurrences to activate immediately

        # Search until 2 minutes ago and let NextOccurrencesEngine handle the
        # rest, so as to make sure not to interfere with its functionality
        self.whileago = int(time_.time()) - 120
        last_search = self.database.get_last_search()

        if self.whileago > last_search:
            log.debug('Search old occurrences')

            # Set the last search in this (main) thread, otherwise
            # NextOccurrencesEngine would race with this function, and possibly
            # do the same search, in fact still seeing the old last search
            # timestamp
            # Note that saving and closing the database after this point, but
            # before the search is finished and the old alarms are activated,
            # would lose all the old alarms; that's why saving must be
            # prevented while the search is ongoing
            core_api.bind_to_save_permission_check(
                                            self._handle_save_permission_check)
            self.database.set_last_search(self.whileago)

            # The "excl" in the name reminds that this time is exclusive, i.e.
            # only the occurrences strictly greater than the value will then be
            # activated, even though the search actually finds also those with
            # time equal to this value
            self.exclmint = last_search

            # Use a thread to let the GUI be responsive and possibly abort the
            # search
            # Start the thread with a timer to give some time for the
            # *interface* to finish opening the database, otherwise the
            # old alarms dialog will appear with a lot of delay and it will be
            # very hard to restrict the search range or skip the search
            # altogether
            # Note that DELAY shouldn't be too long, in fact self.restart and
            # self.abort are not protected, and if they're called during this
            # time, they crash because self.search hasn't been assigned yet
            thread = threading.Timer(self.DELAY, self._continue)
            thread.name = "organism_old_occurrences_{}".format(self.filename)
            # Do not set the thread as a daemon, it's better to properly handle
            # closing the database
            thread.start()
Exemplo n.º 5
0
 def _abort(self):
     search_old_occurrences_end_event.signal(filename=self.filename)
     core_api.bind_to_save_permission_check(
                                 self._handle_save_permission_check, False)
Exemplo n.º 6
0
 def _abort(self):
     search_old_occurrences_end_event.signal(filename=self.filename)
     core_api.bind_to_save_permission_check(
                                 self._handle_save_permission_check, False)