~severinh/ubuntu/natty/lottanzb/merge-from-sid

« back to all changes in this revision

Viewing changes to lottanzb/modes/base.py

  • Committer: Bazaar Package Importer
  • Author(s): Severin Heiniger
  • Date: 2009-01-06 12:54:07 UTC
  • Revision ID: james.westby@ubuntu.com-20090106125407-0p6ko3l0wwjoyr0b
Tags: upstream-0.4.0
ImportĀ upstreamĀ versionĀ 0.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008 LottaNZB Development Team
 
2
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; version 3.
 
6
 
7
# This program is distributed in the hope that it will be useful,
 
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
# GNU General Public License for more details.
 
11
 
12
# You should have received a copy of the GNU General Public License
 
13
# along with this program; if not, write to the Free Software
 
14
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
15
 
 
16
from lottanzb.core import App
 
17
 
 
18
class Mode:
 
19
    def __init__(self, config):
 
20
        self.config = config
 
21
        self._signal_ids = []
 
22
        self.init_error = ""
 
23
    
 
24
    def enter(self):
 
25
        App().backend.connectToHella(*self.get_connection_args())
 
26
        
 
27
        event_map = { "unexpected-disconnect" : self.handle_disconnect }
 
28
        
 
29
        for event, handler in event_map.iteritems():
 
30
            self._signal_ids.append(App().backend.connect(event, handler))
 
31
        
 
32
        self.init_error = ""
 
33
    
 
34
    def leave(self):
 
35
        App().backend.disconnectFromHella()
 
36
        
 
37
        map(App().backend.disconnect, self._signal_ids)
 
38
        self._signal_ids = []
 
39
    
 
40
    def reenter(self):
 
41
        self.leave()
 
42
        self.enter()
 
43
    
 
44
    def __str__(self):
 
45
        return self.short
 
46
    
 
47
    def handle_disconnect(self, backend):
 
48
        pass
 
49
    
 
50
    def get_connection_args(self):
 
51
        raise NotImplementedError
 
52
    
 
53
    @classmethod
 
54
    def get_name(cls):
 
55
        return cls.__module__.split(".")[-1]