Example #1
0
    def __init__(self, parent, title="default"):
        self.title = title
        self.torrents = []
        self.joblist = MultiQueue()
        wx.NotebookPage.__init__(self, parent)

        self.olv = ObjectListView(self, style=wx.LC_REPORT)
        self.olv.SetEmptyListMsg("No torrents")
        self.olv.SetColumns(self._columns)
        self.joblist.put(2, ("download_list", self.title, self.set_list))
Example #2
0
class TasksQueue:
    """
    Queue and task wrapper
    Maintains required user/tasks interface
    and executes tasks in a BG thread. 
    """
    def __init__(self):
        self.queue = MultiQueue()
        self.running = True
        self.thread = Thread(name="manager", target=self._manage)
        self.thread.start()

    def push_tasks(self, User, delays, callback = None):
        Tasks = [Task(User, delay, callback) for delay in delays]
        self.queue.push(User, Tasks)

    def empty(self):
        return self.queue.empty()
    
    def wait(self):
        while not self.empty():
            self.thread.join(0.001)
        
    def join(self):
        while not self.empty():
            self.thread.join(0.001)
        self.stop()

    def stop(self):
        self.running = False
        self.thread.join()

    def _manage(self):
        while self.running:
            task_data = self.queue.pull_wait(1)
            if task_data:
                (User, task) = task_data
                ## print "run task ", task
                task()
import Queue

from class_objectProcessorQueue import ObjectProcessorQueue
from multiqueue import MultiQueue

workerQueue = Queue.Queue()
UISignalQueue = Queue.Queue()
addressGeneratorQueue = Queue.Queue()
# receiveDataThreads dump objects they hear on the network into this
# queue to be processed.
objectProcessorQueue = ObjectProcessorQueue()
invQueue = MultiQueue()
addrQueue = MultiQueue()
portCheckerQueue = Queue.Queue()
receiveDataQueue = Queue.Queue()
# The address generator thread uses this queue to get information back
# to the API thread.
apiAddressGeneratorReturnQueue = Queue.Queue()
# Exceptions
excQueue = Queue.Queue()
Example #4
0
    def test_auto_recycle(self):
        # very small value for auto_recycle, don't do this in real code
        q = MultiQueue(weights=[1, 10], auto_recycle=100)

        # fill queues with some data
        q.put((0, 1))
        q.put((1, 1))

        # forces cycle to grow over auto_recycle value
        for i in xrange(20):
            q.put((0, 1))
            q.put((1, 1))
            q.get()
            q.get()

        # extract rest of items
        while not q.empty():
            q.get()
Example #5
0
    def test_order(self):
        q = MultiQueue(weights=[1, 5, 3])
        for i in xrange(10):
            q.put((0, i))
        for i in xrange(10):
            q.put((1, i))
        for i in xrange(10):
            q.put((2, i))

        # check first in, first out
        self.assertEqual(q.get(), (0, 0))
        self.assertEqual(q.get(), (1, 0))
        self.assertEqual(q.get(), (2, 0))

        # now weights start to affect results
        self.assertEqual(q.get(), (1, 1))
        self.assertEqual(q.get(), (1, 2))
        self.assertEqual(q.get(), (1, 3))
        self.assertEqual(q.get(), (2, 1))
        self.assertEqual(q.get(), (1, 4))
        self.assertEqual(q.get(), (0, 1))
        self.assertEqual(q.get(), (1, 5))
        self.assertEqual(q.get(), (1, 6))
        self.assertEqual(q.get(), (2, 2))
        self.assertEqual(q.get(), (1, 7))
        self.assertEqual(q.get(), (1, 8))
        self.assertEqual(q.get(), (1, 9))

        # no more items from queue 1
        self.assertEqual(q.get(), (2, 3))
        self.assertEqual(q.get(), (0, 2))
        self.assertEqual(q.get(), (2, 4))
        self.assertEqual(q.get(), (0, 3))
        self.assertEqual(q.get(), (2, 5))
        self.assertEqual(q.get(), (2, 6))
        self.assertEqual(q.get(), (0, 4))
        self.assertEqual(q.get(), (2, 7))
        self.assertEqual(q.get(), (2, 8))
        self.assertEqual(q.get(), (0, 5))
        self.assertEqual(q.get(), (2, 9))

        # no more items from queue 2
        self.assertEqual(q.get(), (0, 6))
        self.assertEqual(q.get(), (0, 7))
        self.assertEqual(q.get(), (0, 8))
        self.assertEqual(q.get(), (0, 9))
Example #6
0
 def test_noresize(self):
     q = MultiQueue(num_queues=5)
     self.assertRaises(InvalidQueue, q.put, (6, 1))
Example #7
0
 def test_normal(self):
     q = MultiQueue()
     q.put((1, 2))
     self.assertEqual(q.get(), (1, 2))
     q.put((2, 4))
     self.assertEqual(q.get(), (2, 4))
     q.put((1, 1))
     self.assertEqual(q.get(), (1, 1))
Example #8
0
class rTorrentView(wx.NotebookPage):
    _columns = [
        ColumnDefn("Name", valueGetter="name", isSpaceFilling=True, 
                   minimumWidth=100, maximumWidth=300),
        ColumnDefn("Up", "right", 70, "up_rate", stringConverter=format_speed),
        ColumnDefn("Down", "right", 70, "down_rate", 
                   stringConverter=format_speed),
        ColumnDefn("Size", "right", 70, "size_bytes", 
                   stringConverter=format_bytes),
        ColumnDefn("Up Total", "right", 80, "up_total", 
                   stringConverter=format_bytes),
        ColumnDefn("Down Total", "right", 80, "bytes_done", 
                   stringConverter=format_bytes),
        ColumnDefn("Ratio", "right", fixedWidth=40, valueGetter="ratio", 
                   stringConverter="%s%%"),
        #ColumnDefn("S", "center", 25, "peers_complete"),
        #ColumnDefn("P", "center", 25, "peers_accounted"),
    ]
    def __init__(self, parent, title="default"):
        self.title = title
        self.torrents = []
        self.joblist = MultiQueue()
        wx.NotebookPage.__init__(self, parent)

        self.olv = ObjectListView(self, style=wx.LC_REPORT)
        self.olv.SetEmptyListMsg("No torrents")
        self.olv.SetColumns(self._columns)
        self.joblist.put(2, ("download_list", self.title, self.set_list))

    def __repr__(self):
        return "<rTorrentView '%s'>" % self.title.capitalize()

    def get_list(self):
        ''' Clear the queue and update the current page. 
        Called on page change '''
        self.joblist.put(0, ("download_list", self.title, self.set_list))

    def set_list(self, hashlist):
        ''' Given a list of infohashes, add and remove torrents 
        from the torrents list as necessary '''
        self.torrents = [self.find_torrent(ih) for ih in hashlist]
        self.olv.AddObjects(filter(lambda to: to not in self.olv.GetObjects(),
                            self.torrents))
        self.olv.RemoveObjects(filter(lambda to: to not in self.torrents,
                               self.olv.GetObjects()))
        
    def find_torrent(self, infohash):
        for t in self.torrents:
            if t.infohash == infohash:
                return t
        # else make a new torrent object
        t = Torrent(self, infohash)
        for k in t.properties:
            self.joblist.put(t.properties[k][2], t.properties[k][1])
        return t
                
    def on_erase(self, e):
        dlg = wx.MessageDialog(self, "Remove this torrent?", "Delete torrent", 
                               wx.OK | wx.CANCEL | wx.ICON_QUESTION)
        if dlg.ShowModal() == wx.ID_OK:
            print 'on_erase Not implemented'
        dlg.Destroy()
Example #9
0
 def __init__(self):
     self.queue = MultiQueue()
     self.running = True
     self.thread = Thread(name="manager", target=self._manage)
     self.thread.start()