Example #1
0
def handleAssociationAction(associate):
    from Settings.Associators import getAssociator

    associator = getAssociator()
    if not associator:
        print "Association is not avaliable."
        return
    if associate:
        associator.SetAssociation()
    else:
        associator.RemoveAssociation()
    exit()
Example #2
0
    def connect(self):
        # Initialize socket
        self.close()
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.settimeout(self.timeout)

        # Attempt to connect, retry if necessary
        try:
            pOUT("Conecting to %s:%i..." % (self.host, self.port))
            self.socket.connect((self.host, self.port))
        except Exception as e:
            pERR(
                "Could not connect to %s:%i [Attempt %i]: %s" % (
                    self.host, self.port, self.retry_counter + 1, e
                )
            )

            # Increment retry counter until we hit the max count
            if self.retry_counter < self.retry_count:
                self.retry_counter += 1
                return self.connect()
            else:
                exit(1)

        # Disable timeout/blocking
        self.socket.settimeout(None)

        # Send connection info
        pOUT("Sending connection information...")
        self.send_cmd('USER', self.username)
        self.send_cmd('PASS', self.password)
        self.send_cmd('NICK', self.username)

        # Check if we have successfully logged in
        if self.successful_login():
            pOUT("Login Successful [%s]" % self.username)
        else:
            pERR("Login Unsuccessful [%s]" % self.username)
            exit(1)

        # Join your channel
        self.send_cmd('JOIN', self.channel)
        pOUT("Joined %s" % self.channel)
Example #3
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())