action.py :  » Network » Torrent-Swapper » swapper » ABC » Scheduler » 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 » Scheduler » action.py
import sys
import os

#from traceback import print_exc
#from cStringIO import StringIO

from Utility.constants import *#IGNORE:W0611
fromUtility.helpersintersection

################################################################
#
# Class: ActionHandler
#
# Separates out some of the methods that are solely used to
# deal with actions that occur in ABCList
#
################################################################
class ActionHandler:
    def __init__(self, utility):
        self.utility = utility
        self.queue = self.utility.queue

    def procREMOVE(self, workinglist = None, removefiles = False):
        if workinglist is None:
            workinglist = []
            
        Read = self.utility.config.Read
        
        indexremoved = []
        for ABCTorrentTemp in workinglist:
            indexremoved.append(ABCTorrentTemp.listindex)
            
            if Read('removetorrent', "boolean"):
                try:
                    os.remove(ABCTorrentTemp.src)
                except:
                    pass

            ABCTorrentTemp.shutdown()
            
            # Arno: remove torrentinfo file as well
            try:
                os.remove(ABCTorrentTemp.torrentconfig.filename)
            except:
                pass

            if removefiles:
                ABCTorrentTemp.files.removeFiles()
            
            ABCTorrentTemp = None

        # Only need to update if we actually removed something
        if indexremoved:
            #indexremoved.sort(reverse = True)    ## for compatible with python2.3
            indexremoved.sort()
            indexremoved.reverse()
            for index in indexremoved:
                # Remove from the display
                self.utility.list.DeleteItem(index)
        
                # Remove from scheduler
                self.utility.torrents["all"].pop(index)

            self.queue.updateListIndex(startindex = indexremoved[-1])
            self.queue.updateAndInvoke()

    def procMOVE(self, workinglist = None):
        if workinglist is None:
            workinglist = self.utility.torrents["all"]

        update = [1 for ABCTorrentTemp in workinglist if ABCTorrentTemp.files.move()]
            
        if update:
            self.queue.updateAndInvoke()

    def procSTOP(self, workinglist = None):
        if workinglist is None:
            workinglist = self.utility.torrents["all"]
            
        update = [1 for ABCTorrentTemp in workinglist if ABCTorrentTemp.actions.stop()]
            
        if update:
            self.queue.updateAndInvoke()

    def procUNSTOP(self, workinglist = None):
        fulllist = self.utility.torrents["inactive"].keys()
        if workinglist is None:
            workinglist = fulllist
        else:
            workinglist = intersection(fulllist, workinglist)

        update = [1 for ABCTorrentTemp in workinglist
                    if ABCTorrentTemp.status.value == STATUS_STOP
                       and ABCTorrentTemp.actions.queue()]

        if update:
            self.queue.updateAndInvoke()
        
    def procPAUSE(self, workinglist = None, release = False):
        fulllist = self.utility.torrents["active"].keys()
        if workinglist is None:
            workinglist = fulllist
        else:
            workinglist = intersection(fulllist, workinglist)

        update = [1 for ABCTorrentTemp in workinglist if ABCTorrentTemp.actions.pause(release)]

        if update:
            self.queue.UpdateRunningTorrentCounters()
       
    def procRESUME(self, workinglist = None, skipcheck = False):
        fulllist = self.utility.torrents["inactive"].keys()
        if workinglist is None:
            workinglist = fulllist
        else:
            workinglist = intersection(fulllist, workinglist)
        
        update = [1 for ABCTorrentTemp in workinglist if ABCTorrentTemp.actions.resume(skipcheck)]

        if update:
            self.queue.updateAndInvoke(invokeLater = False)

    def procQUEUE(self, workinglist = None):
        if workinglist is None:
            workinglist = self.utility.torrents["all"]
        
        update = [1 for ABCTorrentTemp in workinglist if ABCTorrentTemp.actions.queue()]
        
        if update:
            self.queue.updateAndInvoke()

    def procHASHCHECK(self, workinglist = None):
        if workinglist is None:
            workinglist = self.utility.torrents["all"]
        
        update = [1 for ABCTorrentTemp in workinglist if ABCTorrentTemp.actions.hashCheck()]
        
        if update:
            self.queue.updateAndInvoke()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.