Exemplo n.º 1
0
    def _detectChangesOne(self, name, old, new):

        # On error, don't do anything.
        if old == False or new == False: return

        # Extract type from transfer name.
        type = os.path.splitext(name)[1][1:]
        if type not in ('torrent', 'wget', 'nzb'):
            type = 'unknown'

        # Extract running, percent_done and downtotal values.
        if old is not None:
            old_running      = parseInt(old.running, -1)
            old_percent_done = parseFloat(old.percent_done)
        else:
            old_running      = -1
            old_percent_done = 0.

        new_running      = parseInt(new.running, -1)
        new_percent_done = parseFloat(new.percent_done)
        new_downtotal    = parseLong(new.downtotal)

        # transfer started:
        #   * transition of running
        #  from !1 to 1
        if old_running != 1 and new_running == 1:
            if 'transferStarted' in self.jobs[name].keys():
                self._fireEvent('transferStarted', name, new)

        # transfer stopped:
        #    * transition of running
        # from 1 to !1
        if old_running == 1 and new_running != 1:
            if 'transferStopped' in self.jobs[name].keys():
                self._fireEvent('transferStopped', name, new)

        # transfer Completed:
        #   * transition of (running, percent_done)
        #       from (*, <100) to ([01], 100)
        #   * with downtotal > 0 (to not interpret a checking->seeding
        #       transition as a download completion)
        if old_percent_done < 100. and \
            new_running in (0, 1) and new_percent_done == 100. and \
            new_downtotal > 0L:
            if 'transferCompleted' in self.jobs[name].keys():
                self._fireEvent('transferCompleted', name, new)

        # transfer Seeding:
        #   * torrents only
        #   * transition of (running, percent_done)
        #       from (1, *) to (1, 100)
        if type == 'torrent' and \
            old_running == 1 and \
            new_running == 1 and new_percent_done == 100.:
            try:
                if 'transferSeeding' in self.jobs[name].keys():
                    self._fireEvent('transferSeeding', name, new)
            except Exception, e:
                #self.logger.error("Error getting keys for %s (%s)" % (name, e))
                pass
Exemplo n.º 2
0
        self._userStats[user]['running'] += 1
        self._transferStats['running'] += 1
        
        # sf is provided ?
        if sf == None:
            try:
                sf = StatFile("%s%s.stat" % (self.pathTransfers, name))
            except Exception, e:
                sf = StatFile()
                self.logger.warning("Error loading state for transfer %s (%s)" % (name, e))
                
        # add it to transfers
        self._transfers[name] = sf
        
        # percentage
        percentage = parseFloat(sf.percent_done)
        
        # download/seed
        if percentage > -200 and percentage < 100:
        
            # downloading
            self._userStats[user]['downloading'] += 1
            self._transferStats['downloading'] += 1
            
        else:
        
            # seeding
            self._userStats[user]['seeding'] += 1
            self._transferStats['seeding'] += 1