2
# Copyright (C) 2008-2009 Oprea Dan
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.
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.
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.
23
tools.register_backintime_path( 'common' )
24
tools.register_backintime_path( 'plugins' )
32
def init( self, snapshots ):
38
def on_process_begins( self ):
41
def on_process_ends( self ):
44
def on_error( self, code, message ):
47
def on_new_snapshot( self, snapshot_id, snapshot_path ):
51
class PluginManager():
54
self.has_gui_plugins_ = False
55
self.plugins_loaded = False
57
def load_plugins( self, snapshots, force = False ):
58
if self.plugins_loaded and not force:
61
self.plugins_loaded = True
63
self.has_gui_plugins_ = False
65
plugins_path = tools.get_backintime_path( 'plugins' )
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 )
71
module = __import__( file[ : -3 ] )
72
module_dict = module.__dict__
74
for key, value in module_dict.items():
75
if key.startswith( '__' ):
78
if type(value) is types.ClassType:
79
if issubclass( value, Plugin ):
81
if plugin.init( snapshots ):
83
self.has_gui_plugins_ = True
84
self.plugins.insert( 0, plugin )
86
self.plugins.append( plugin )
88
def has_gui_plugins( self ):
89
return self.has_gui_plugins_
91
def on_process_begins( self ):
92
for plugin in self.plugins:
93
plugin.on_process_begins()
95
def on_process_ends( self ):
96
for plugin in reversed( self.plugins ):
97
plugin.on_process_ends()
99
def on_error( self, code, message = '' ):
100
for plugin in self.plugins:
101
plugin.on_error( code, message )
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 )