~bit-team/backintime/release-1.0

« back to all changes in this revision

Viewing changes to notify/plugins/notifyplugin.py

  • Committer: BIT Team
  • Date: 2012-10-27 14:42:44 UTC
  • mfrom: (784.2.33 backintime.ssh)
  • Revision ID: dan@le-web.org-20121027144244-rxmqo5axjbkpcnf4
lp:~germar/backintime/ssh

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#    Back In Time
 
2
#    Copyright (C) 2008-2009 Oprea Dan, Bart de Koning, Richard Bailey
 
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
 
20
import pluginmanager
 
21
import gettext
 
22
 
 
23
_=gettext.gettext
 
24
 
 
25
 
 
26
class NotifyPlugin( pluginmanager.Plugin ):
 
27
        def __init__( self ):
 
28
                self.user = ''
 
29
 
 
30
                try:
 
31
                        self.user = os.getlogin()
 
32
                except:
 
33
                        pass
 
34
 
 
35
                if len(self.user) <= 0:
 
36
                        try:
 
37
                                user = os.environ['USER']
 
38
                        except:
 
39
                                pass
 
40
 
 
41
                if len(self.user) <= 0:
 
42
                        try:
 
43
                                user = os.environ['LOGNAME']
 
44
                        except:
 
45
                                pass
 
46
 
 
47
        def init( self, snapshots ):
 
48
                return True
 
49
 
 
50
        def is_gui( self ):
 
51
                return True
 
52
 
 
53
        def on_process_begins( self ):
 
54
                pass
 
55
 
 
56
        def on_process_ends( self ):
 
57
                pass
 
58
 
 
59
        def on_error( self, code, message ):
 
60
                return
 
61
 
 
62
        def on_new_snapshot( self, snapshot_id, snapshot_path ):
 
63
                return
 
64
 
 
65
        def on_message( self, profile_id, profile_name, level, message, timeout ):
 
66
                if 1 == level:
 
67
                        cmd = "notify-send "
 
68
                        if timeout > 0:
 
69
                                cmd = cmd + " -t %s" % (1000 * timeout)
 
70
                        
 
71
                        title = "Back In Time (%s) : %s" % (self.user, profile_name)
 
72
                        message = message.replace("\n", ' ')
 
73
                        message = message.replace("\r", '')
 
74
 
 
75
                        cmd = cmd + " \"%s\" \"%s\"" % (title, message)
 
76
                        print cmd
 
77
                        os.system(cmd)
 
78
                return
 
79