status.py :  » Network » Torrent-Swapper » swapper » ABC » Torrent » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Torrent Swapper 
Torrent Swapper » swapper » ABC » Torrent » status.py
import sys

from Utility.constants import *#IGNORE:W0611


################################################################
#
# Class: TorrentStatus
#
# Keep track of the status of a torrent
#
################################################################        
class TorrentStatus:
    def __init__(self, torrent):
        self.torrent = torrent
        self.utility = torrent.utility
        
        # set queue status
        self.value = STATUS_QUEUE
        self.completed = False
        self.dontupdate = True # Don't update until the list item is created

    def getStatusText(self):
        value = self.value
        
        if self.isActive():
            if value == STATUS_PAUSE:
                status = self.utility.lang.get('pause')
            elif value == STATUS_SUPERSEED:
                status = self.utility.lang.get('superseeding')
            elif self.torrent.connection.engine is not None:
                status = self.torrent.connection.engine.btstatus
            else:
                status = self.utility.lang.get('stopping')
        elif value == STATUS_FINISHED:
            status = self.utility.lang.get('completed')
        elif value == STATUS_STOP:
            status = self.utility.lang.get('stop')
        elif value == STATUS_QUEUE:
            status = self.utility.lang.get('queue')
        else:
            # Most likely just not quite started yet
            status = self.utility.lang.get('waiting')
        
        return status
        
    # Is the torrent active?
    def isActive(self, working = True, checking = True, pause = True):
        engine = self.torrent.connection.engine
        if engine is not None:
            if not pause and self.value == STATUS_PAUSE:
                return False
            if working and engine.working:
                return True
            elif checking and (engine.checking or engine.waiting):
                return True
                
    # See if the torrent is checking existing data or allocating
    def isCheckingOrAllocating(self):
        # If the torrent is in its initialization stage, the progress value
        # we get from ABCEngine won't reflect the download progress
        # 
        # Note: "moving data" is a third initialization status that is listed
        #       in the BitTornado source
        ######################################################################
        if not self.utility.abcquitting and self.torrent.connection.engine is not None:
            status = self.getStatusText()
            statuslist = [ self.utility.lang.get('waiting'), 
                           self.utility.lang.get('checkingdata'), 
                           self.utility.lang.get('allocatingspace'), 
                           self.utility.lang.get('movingdata') ]
            if (status in statuslist):
                return True
        return False
        
    def isDoneUploading(self):
        finished = False
        
        uploadoption = self.torrent.connection.getSeedOption('uploadoption')
        
        # If the file isn't finished, or it's set to unlimited upload
        if self.torrent.files.progress != 100.0:
            pass

        elif (uploadoption == "1"):
            uploadtimes = self.torrent.connection.getTargetSeedingTime()
            
            if uploadtimes < 1800: #Cheat people edit config file..unlimited upload!
                pass
            elif self.torrent.connection.seedingtime >= uploadtimes:
                finished = True
        
        elif (uploadoption == "2"
            and self.torrent.getColumnValue(12) >= float(self.torrent.connection.getSeedOption('uploadratio'))):
            finished = True
            
        # Also mark as completed in case it wasn't for some reason
        if finished:
            self.value = STATUS_FINISHED
            self.completed = True
            
        elif self.value == STATUS_FINISHED:
            # Was finished before, but isn't now
            self.value = STATUS_QUEUE
            
        self.torrent.updateColumns([COL_BTSTATUS])
        
        return finished
        
    def updateStatus(self, value, update = True):
        if value != self.value:
            self.value = value
            if update:
                self.torrent.torrentconfig.writeStatus()
        
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.