1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import os
18
19 if (not 'DISPLAY' in os.environ):
20 os.environ['DISPLAY'] = ':0'
21
22 import pynotify
23 import sys
24 import base64
25 import subprocess
26 import gtk
27 import tempfile
28
29
30 PLUGIN_NAME = 'reminder'
31 VERSION = open(os.path.join(os.path.dirname(__file__), 'version')).readline()
32
33 uuid = ''
34
35 capabilities = {'actions': False,
36 'body': False,
37 'body-hyperlinks': False,
38 'body-images': False,
39 'body-markup': False,
40 'icon-multi': False,
41 'icon-static': False,
42 'sound': False,
43 'image/svg+xml': False,
44 'private-synchronous': False,
45 'append': False,
46 'private-icon-only': False}
47
49 caps = pynotify.get_server_caps()
50 if caps is None:
51 print "Failed to receive server caps."
52 sys.exit(1)
53 for cap in caps:
54 capabilities[cap] = True
55
57 info = pynotify.get_server_info()
58 print "Information about your notification component:"
59 print "Name: " + info["name"]
60 print "Vendor: " + info["vendor"]
61 print "Version: " + info["version"]
62 print "Spec. Version: " + info["spec-version"]
63 caps = pynotify.get_server_caps()
64 if caps is None:
65 print "Failed to receive server caps."
66 sys.exit (1)
67 print "Supported capabilities/hints:"
68 if capabilities['actions']:
69 print "\tactions"
70 if capabilities['body']:
71 print "\tbody"
72 if capabilities['body-hyperlinks']:
73 print "\tbody-hyperlinks"
74 if capabilities['body-images']:
75 print "\tbody-images"
76 if capabilities['body-markup']:
77 print "\tbody-markup"
78 if capabilities['icon-multi']:
79 print "\ticon-multi"
80 if capabilities['icon-static']:
81 print "\ticon-static"
82 if capabilities['sound']:
83 print "\tsound"
84 if capabilities['image/svg+xml']:
85 print "\timage/svg+xml"
86 if capabilities['private-synchronous']:
87 print "\tprivate-synchronous"
88 if capabilities['append']:
89 print "\tappend"
90 if capabilities['private-icon-only']:
91 print "\tprivate-icon-only"
92 print "Notes:"
93 if info["name"] == "notify-osd":
94 print "\tx- and y-coordinates hints are ignored"
95 print "\texpire-timeout is ignored"
96 print "\tbody-markup is accepted but filtered"
97 else:
98 print "\tnone"
99
101
102 p = subprocess.Popen('crontab -l', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
103 output = ''
104 output_err = ''
105 skip_line = 0
106 while True:
107 stdout, stderr = p.communicate()
108 tmp = stdout
109 for line in tmp.split('\n'):
110
111 if (line.find('# DO NOT EDIT THIS FILE') != -1):
112 continue
113 if (line.find('# (Cron version ') != -1):
114 continue
115 if (line.find(' installed on ') != -1 and line[0] == '#'):
116 continue
117 if (line.find(' task ' + uuid + ' ') != -1):
118 skip_line = 1
119 else:
120 if (skip_line == 1):
121 skip_line = 0
122 else:
123 output += line + '\n'
124 output_err += stderr
125 rc = p.poll()
126 if rc is not None:
127 break
128
129 if (rc == 0):
130 f = tempfile.NamedTemporaryFile(delete=False)
131 f.write(output)
132 f.close()
133 else:
134 print(output_err)
135
136 p = subprocess.Popen('crontab ' + f.name, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
137 output = ''
138 while True:
139 stdout, stderr = p.communicate()
140 output += stdout
141 output += stderr
142 rc = p.poll()
143 if rc is not None:
144 break
145 if (rc != 0):
146 print(output)
147 gtk.main_quit()
148
151
153
154 pynotify.init('Getting Things GNOME! ' + PLUGIN_NAME)
155 initCaps()
156
157 if (len(sys.argv) < 8):
158 print('version: ' + VERSION)
159 print('usage: notify.py uuid title(base64) message(base64) icon(base64) timeout urgency args...(base64)')
160 print('example: notify.py 00000000-0000-0000-0000-000000000000 IA== IA== IA== -1 -1 IA==')
161 printCaps()
162 sys.exit(1)
163 cron = int(sys.argv[1])
164 global uuid
165 uuid = sys.argv[2]
166 title = base64.b64decode(sys.argv[3])
167 message = base64.b64decode(sys.argv[4])
168 icon = base64.b64decode(sys.argv[5])
169 timeout = int(sys.argv[6])
170 urgency = int(sys.argv[7])
171
172 if (title == ' '):
173 title = 'Getting Things GNOME!'
174 if (icon != ' '):
175 notice = pynotify.Notification(title, message, icon)
176 else:
177 notice = pynotify.Notification(title, message, '/usr/share/icons/hicolor/32x32/apps/gtg.png')
178 if (timeout != -1):
179 notice.set_timeout(timeout)
180 if (urgency != -1):
181 notice.set_urgency(timeout)
182 if (capabilities['actions'] and cron):
183 notice.add_action("clicked","Stop notify", callback_stop, None)
184 notice.connect("closed", callback_closed)
185 notice.show()
186
187 if (len(sys.argv) == 9):
188 arg = base64.b64decode(sys.argv[8])
189 subprocess.Popen(arg, shell=True)
190
191 if (capabilities['actions'] and cron):
192 gtk.main()
193
194 if __name__ == '__main__':
195 main()
196
197
198