Example #1
0
def startWorking(queries = [], files = [], directories = []):
    """ The entry point for the real work of SubiT. The parameters are those 
        that parsed successfully from the command line.
    """
    WriteDebug('Starting SubiT\'s real work.')
    WriteDebug('Running from: %s' % GetProgramDir())
    
    WriteDebug('Creating SUBIT_WORKER_THREAD daemon thread.')
    SUBIT_WORKER_THREAD = SubiTWorkerThread(queries, files, directories)
    SUBIT_WORKER_THREAD.setDaemon(True)
    SUBIT_WORKER_THREAD.start()
    WriteDebug('SUBIT_WORKER_THREAD created and started.')

    # In Gui mode, after calling load(), the thread enters the event loop so
    # we don't need to take to much care about the rest of the code.
    getInteractor().load()

    # In Console modes however, we wait for the worker thread to finish 
    # (otherwise, we are ending the run in here beacuse there is no event loop
    # for the console).
    if (getInteractor().InteractionType in \
        [InteractionTypes.Console, InteractionTypes.ConsoleSilent]):
        while SUBIT_WORKER_THREAD.isAlive():
            sleep(0.05)
Example #2
0
    def run(self):
        """ Execute the procedure. """

        # Wait until the interactor finishes the loading procedure        
        while not getInteractor() or not getInteractor().IsLoaded():
            sleep(0.05)

        # We can set the writeLog variable only after the interactor was
        # loaded, because before that, we don't have the right underlying
        # function for the writeLog.
        writeLog = getInteractor().writeLog

        if getInteractor().InteractionType == InteractionTypes.Gui:
            from SubProviders import getSelectedLanguages
            # We need to ask the user to select his languages.
            if not getSelectedLanguages():
                getInteractor().showLanguageSelection()

        # We are checking for update in each program's load.
        self.doUpdateCheck()

        # Now we are ready for the real work.
        from SubFlow import SubFlow
        close_on_finish = SubiTConfig.Singleton().getBoolean\
            ('Global', 'close_on_finish', False)
        interactive_by_interactor = getInteractor().InteractionType in [
            InteractionTypes.Console, InteractionTypes.Gui]

        self.interactive = \
            interactive_by_interactor and self.interactive_by_input

        writeLog(INFO_LOGS.STARTING)

        if self.single_input_queue.empty() and interactive_by_interactor:
            WriteDebug('The queue is empty from the start, adding user query.')
            self._put_user_single_input_in_queue()

        while not self.single_input_queue.empty():
            WriteDebug('Getting next_single_input form the queue.')
            next_single_input = self.single_input_queue.getSingleInput()
            WriteDebug('Got next_single_input: %s' % next_single_input.printableInfo())
            writeLog(INFO_LOGS.STARTING_PROCESSING_OF_SINGLE_INPUT %
                     next_single_input.printableInfo())
            writeLog(GUI_SPECIAL_LOGS.SEARCH_LINE_UPDATE % next_single_input.query)
            try:
                SubFlow(next_single_input).process(self.interactive)
            except Exception as eX:
                WriteDebug('Failed processing the next_single_input: %s' % eX)
                writeLog(BuildLog(WARN_LOGS._TYPE_,
                                  'SingleInput failure: %s' % str(eX)))
            else:
                writeLog(FINISH_LOGS.FINISHED_PROCESSING_SINGLE_INPUT % 
                         next_single_input.printableInfo())
            # Update the stats after processing the SingleInput
            self._update_working_stats(next_single_input)

            if self.single_input_queue.empty() and not close_on_finish:
                WriteDebug('Queue is empty, getting query from the user.')
                self._put_user_single_input_in_queue()

        WriteDebug('Successful downloads: %s' % self.number_of_success)
        WriteDebug('Failed downloads: %s' % self.number_of_failures)
        # Finish up.
        writeLog(FINISH_LOGS.FINISHED)
        writeLog(FINISH_LOGS.APPLICATION_WILL_NOW_EXIT)                
        # Close program in this stage.
        exit(2, self._get_exit_code())
def autoupdate(bot):
    while bot.bot_active:
        while bot.verbose:
            tail_logs(bot)
            sleep(bot.interval)
        sleep("10s")