~ubuntu-branches/ubuntu/maverick/backintime/maverick

« back to all changes in this revision

Viewing changes to common/pluginmanager.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Wiltshire
  • Date: 2009-05-16 23:04:32 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090516230432-orrutvtufbtuxsc6
Tags: 0.9.24-1
* New upstream version (closes: #527447):
  - backintime is no longer aware of 'backintime-gnome' and 'backintime-kde4'
    (you need run 'backintime-gnome' for GNOME version and 'backintime-kde4'
    for KDE4 version)
  - fix a bug that crashes the program after taking a snapshot
* Update homepage field in debian/control (closes: #527595)
* Refactor packaging to fit new upstream build system (an almost entire 
  re-write of debian/rules)
* Make configure scripts use /bin/sh instead of /bin/bash (they don't use
  bash features)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#    Back In Time
 
2
#    Copyright (C) 2008-2009 Oprea Dan
 
3
#
 
4
#    This program is free software; you can redistribute it and/or modify
 
5
#    it under the terms of the GNU General Public License as published by
 
6
#    the Free Software Foundation; either version 2 of the License, or
 
7
#    (at your option) any later version.
 
8
#
 
9
#    This program is distributed in the hope that it will be useful,
 
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
#    GNU General Public License for more details.
 
13
#
 
14
#    You should have received a copy of the GNU General Public License along
 
15
#    with this program; if not, write to the Free Software Foundation, Inc.,
 
16
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
17
 
 
18
 
 
19
import os.path
 
20
import tools
 
21
import types
 
22
 
 
23
tools.register_backintime_path( 'common' )
 
24
tools.register_backintime_path( 'plugins' )
 
25
 
 
26
 
 
27
class Plugin:
 
28
        
 
29
        def __init__( self ):
 
30
                return
 
31
 
 
32
        def init( self, snapshots ):
 
33
                return True
 
34
 
 
35
        def is_gui( self ):
 
36
                return False
 
37
 
 
38
        def on_process_begins( self ):
 
39
                return
 
40
 
 
41
        def on_process_ends( self ):
 
42
                return
 
43
 
 
44
        def on_error( self, code, message ):
 
45
                return
 
46
 
 
47
        def on_new_snapshot( self, snapshot_id, snapshot_path ):
 
48
                return
 
49
 
 
50
 
 
51
class PluginManager():
 
52
        def __init__( self ):
 
53
                self.plugins = []
 
54
                self.has_gui_plugins_ = False
 
55
                self.plugins_loaded = False
 
56
 
 
57
        def load_plugins( self, snapshots, force = False ):
 
58
                if self.plugins_loaded and not force:
 
59
                        return
 
60
 
 
61
                self.plugins_loaded = True
 
62
                self.plugins = []
 
63
                self.has_gui_plugins_ = False
 
64
                
 
65
                plugins_path = tools.get_backintime_path( 'plugins' )
 
66
 
 
67
                for file in os.listdir( plugins_path ):
 
68
                        if file.endswith( '.py' ) and not file.startswith( '__' ):
 
69
                                path = os.path.join( plugins_path, file )
 
70
 
 
71
                                module = __import__( file[ : -3 ] )
 
72
                                module_dict = module.__dict__
 
73
                                
 
74
                                for key, value in module_dict.items():
 
75
                                        if key.startswith( '__' ):
 
76
                                                continue
 
77
 
 
78
                                        if type(value) is types.ClassType:
 
79
                                                if issubclass( value, Plugin ):
 
80
                                                        plugin = value()
 
81
                                                        if plugin.init( snapshots ):
 
82
                                                                if plugin.is_gui():
 
83
                                                                        self.has_gui_plugins_ = True
 
84
                                                                        self.plugins.insert( 0, plugin )
 
85
                                                                else:
 
86
                                                                        self.plugins.append( plugin )
 
87
 
 
88
        def has_gui_plugins( self ):
 
89
                return self.has_gui_plugins_
 
90
 
 
91
        def on_process_begins( self ):
 
92
                for plugin in self.plugins:
 
93
                        plugin.on_process_begins()
 
94
 
 
95
        def on_process_ends( self ):
 
96
                for plugin in reversed( self.plugins ):
 
97
                        plugin.on_process_ends()
 
98
 
 
99
        def on_error( self, code, message = '' ):
 
100
                for plugin in self.plugins:
 
101
                        plugin.on_error( code, message )
 
102
 
 
103
        def on_new_snapshot( self, snapshot_id, snapshot_path ):
 
104
                for plugin in self.plugins:
 
105
                        plugin.on_new_snapshot( snapshot_id, snapshot_path )
 
106