summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README2
-rwxr-xr-xbeinc_generic_client.py2
-rwxr-xr-xbeinc_poller.py124
-rwxr-xr-xbeinc_server.py2
-rw-r--r--beinc_weechat.py2
5 files changed, 64 insertions, 68 deletions
diff --git a/README b/README
index 10c99e9..492e892 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
1Copyright (C) 2014 - Simeon Simeonov 1Copyright (C) 2014, 2015 - Simeon Simeonov
2See the end of the file for license conditions. 2See the end of the file for license conditions.
3 3
4 4
diff --git a/beinc_generic_client.py b/beinc_generic_client.py
index 39e0fe8..b46d3fd 100755
--- a/beinc_generic_client.py
+++ b/beinc_generic_client.py
@@ -2,7 +2,7 @@
2# -*- coding: utf-8 -*- 2# -*- coding: utf-8 -*-
3 3
4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v1.0 4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v1.0
5# Copyright (C) 2013-2014 Simeon Simeonov 5# Copyright (C) 2013-2015 Simeon Simeonov
6 6
7# This program is free software: you can redistribute it and/or modify 7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by 8# it under the terms of the GNU General Public License as published by
diff --git a/beinc_poller.py b/beinc_poller.py
index a1269c2..2bdfe29 100755
--- a/beinc_poller.py
+++ b/beinc_poller.py
@@ -2,7 +2,7 @@
2# -*- coding: utf-8 -*- 2# -*- coding: utf-8 -*-
3 3
4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v1.0 4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v1.0
5# Copyright (C) 2013-2014 Simeon Simeonov 5# Copyright (C) 2013-2015 Simeon Simeonov
6 6
7# This program is free software: you can redistribute it and/or modify 7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by 8# it under the terms of the GNU General Public License as published by
@@ -84,13 +84,61 @@ class ValidHTTPSHandler(urllib2.HTTPSHandler):
84 return self.do_open(ValidHTTPSConnection, req) 84 return self.do_open(ValidHTTPSConnection, req)
85 85
86 86
87def poll_notifications(scheduler, args, notification_obj): 87def display_notification(args, title, message):
88 """
89 A wrapper function for displaying a single notification
90
91 args: the argparse processed command-line arguments
92 title: notification title
93 message: notification message
94 """
95 if args.osd_sys == 'pyosd':
96 if not pyosd:
97 raise Exception(
98 'Could not load "pyosd".\n'
99 'Please install "pyosd" or use a different osd-system!\n'
100 'Terminating...\n')
101 notification_obj = pyosd.osd()
102 notification_obj.set_timeout(args.osd_timeout)
103 if args.font:
104 notification_obj.set_font(args.font)
105 notification_obj.set_vertical_offset(args.voffset)
106 notification_obj.set_horizontal_offset(args.hoffset)
107 notification_obj.set_align(
108 pyosd_alignments.get(args.alignment, pyosd.ALIGN_LEFT))
109 notification_obj.set_pos(
110 pyosd_positions.get(args.position, pyosd.POS_BOT))
111 notification_obj.set_colour(args.color)
112 notification_obj.display(title, line=0)
113 notification_obj.display(message, line=1)
114 elif args.osd_sys == 'pynotify':
115 if not pynotify:
116 raise Exception(
117 'Could not load "pynotify".\n'
118 'Please install "pynotify" or use a different osd-system!\n'
119 'Terminating...\n')
120 if not pynotify.init('BEINC Notify'):
121 raise Exception('There was a problem with libnotify\n')
122 notification_obj = pynotify.Notification(' ')
123 notification_obj.set_timeout(1000 * args.osd_timeout)
124 notification_obj.set_property(
125 'app_name',
126 '{0} {1}'.format(sys.argv[0], __version__))
127 notification_obj.set_properties(
128 summary=title,
129 body=message)
130 notification_obj.show()
131 else:
132 raise Exception(
133 'Unsupported osd-system: {0}\n'.format(args.osd_sys))
134
135
136def poll_notifications(scheduler, args):
88 """ 137 """
89 the core function initiated by the scheduler performing a single poll 138 the core function initiated by the scheduler performing a single poll
90 139
91 scheduler: scheduler object 140 scheduler: scheduler object
92 args: the argparse processed command-line arguments 141 args: the argparse processed command-line arguments
93 notification_obj: pynotify or pyosd notification object
94 """ 142 """
95 try: 143 try:
96 post_values = {'password': args.password} 144 post_values = {'password': args.password}
@@ -113,23 +161,16 @@ def poll_notifications(scheduler, args, notification_obj):
113 for entry in res_list: 161 for entry in res_list:
114 title = entry.get('title', '') 162 title = entry.get('title', '')
115 message = entry.get('message', '') 163 message = entry.get('message', '')
116 if args.osd_sys == 'pyosd': 164 display_notification(args, title, message)
117 notification_obj.display(title, line=0)
118 notification_obj.display(message, line=1)
119 else:
120 notification_obj.set_properties(
121 summary=title,
122 body=message)
123 notification_obj.show()
124 scheduler.enter(args.frequency, 165 scheduler.enter(args.frequency,
125 1, 166 1,
126 poll_notifications, 167 poll_notifications,
127 (scheduler, args, notification_obj)) 168 (scheduler, args))
128 except urllib2.HTTPError as e: 169 except urllib2.HTTPError as e:
129 sys.stderr.write('BEINC-server error ({0} - {1})\n'.format(e.code, 170 sys.stderr.write('BEINC-server error ({0} - {1})\n'.format(e.code,
130 e.reason)) 171 e.reason))
131 except Exception as e: 172 except Exception as e:
132 sys.stderr.write('BEINC-poller error: {0}\n'.format(e)) 173 sys.stderr.write('BEINC-poller error: {0}\nTerminating...'.format(e))
133 sys.exit(errno.EPERM) 174 sys.exit(errno.EPERM)
134 175
135 176
@@ -231,51 +272,6 @@ def main():
231 default=120, 272 default=120,
232 help='Vertical offset for "pyosd" (default: 120)') 273 help='Vertical offset for "pyosd" (default: 120)')
233 args = parser.parse_args() 274 args = parser.parse_args()
234 if args.osd_sys == 'pyosd':
235 if not pyosd:
236 sys.stderr.write(
237 'Could not load "pyosd".\n'
238 'Please install "pyosd" or use a different osd-system!\n'
239 'Terminating...\n')
240 sys.exit(1)
241 try:
242 notification_obj = pyosd.osd()
243 notification_obj.set_timeout(args.osd_timeout)
244 if args.font:
245 notification_obj.set_font(args.font)
246 notification_obj.set_vertical_offset(args.voffset)
247 notification_obj.set_horizontal_offset(args.hoffset)
248 notification_obj.set_align(
249 pyosd_alignments.get(args.alignment, pyosd.ALIGN_LEFT))
250 notification_obj.set_pos(
251 pyosd_positions.get(args.position, pyosd.POS_BOT))
252 notification_obj.set_colour(args.color)
253 except Exception as e:
254 sys.stderr.write(
255 'Unable to create pyosd osd-object: {0}\n'.format(
256 e))
257 sys.exit(1)
258 else:
259 if not pynotify:
260 sys.stderr.write(
261 'Could not load "pynotify".\n'
262 'Please install "pynotify" or use a different osd-system!\n'
263 'Terminating...\n')
264 sys.exit(1)
265 if not pynotify.init('BEINC Notify'):
266 sys.stderr.write('There was a problem with libnotify\n')
267 sys.exit(1)
268 try:
269 notification_obj = pynotify.Notification(' ')
270 notification_obj.set_timeout(1000 * args.osd_timeout)
271 notification_obj.set_property(
272 'app_name',
273 '{0} {1}'.format(sys.argv[0], __version__))
274 except Exception as e:
275 sys.stderr.write(
276 'Unable to create pynotify Notification-object: {0}\n'.format(
277 e))
278 sys.exit(1)
279 if not args.password: 275 if not args.password:
280 try: 276 try:
281 args.password = getpass.getpass() 277 args.password = getpass.getpass()
@@ -291,12 +287,12 @@ def main():
291 except Exception as e: 287 except Exception as e:
292 sys.stderr.write('Unable to open password file: {0}'.format(e)) 288 sys.stderr.write('Unable to open password file: {0}'.format(e))
293 sys.exit(1) 289 sys.exit(1)
294 sc = sched.scheduler(time.time, time.sleep) 290 scheduler = sched.scheduler(time.time, time.sleep)
295 sc.enter(args.frequency, 291 scheduler.enter(args.frequency,
296 1, 292 1,
297 poll_notifications, 293 poll_notifications,
298 (sc, args, notification_obj)) 294 (scheduler, args))
299 sc.run() 295 scheduler.run()
300 296
301 297
302if __name__ == '__main__': 298if __name__ == '__main__':
diff --git a/beinc_server.py b/beinc_server.py
index 30c8a95..894eeb2 100755
--- a/beinc_server.py
+++ b/beinc_server.py
@@ -2,7 +2,7 @@
2# -*- coding: utf-8 -*- 2# -*- coding: utf-8 -*-
3 3
4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v1.0 4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v1.0
5# Copyright (C) 2013-2014 Simeon Simeonov 5# Copyright (C) 2013-2015 Simeon Simeonov
6 6
7# This program is free software: you can redistribute it and/or modify 7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by 8# it under the terms of the GNU General Public License as published by
diff --git a/beinc_weechat.py b/beinc_weechat.py
index f878c89..b875be6 100644
--- a/beinc_weechat.py
+++ b/beinc_weechat.py
@@ -2,7 +2,7 @@
2# -*- coding: utf-8 -*- 2# -*- coding: utf-8 -*-
3 3
4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v1.0 4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v1.0
5# Copyright (C) 2013-2014 Simeon Simeonov 5# Copyright (C) 2013-2015 Simeon Simeonov
6 6
7# This program is free software: you can redistribute it and/or modify 7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by 8# it under the terms of the GNU General Public License as published by