summaryrefslogtreecommitdiff
path: root/beinc_poller.py
diff options
context:
space:
mode:
authorSimeon Simeonov2017-05-12 09:35:08 +0200
committerSimeon Simeonov2017-05-12 09:35:08 +0200
commit1336daa7a6383bc4ed723c914fa5ee8b4e967b26 (patch)
treed04ea0f5d4a59aa066861fec5fa00f4679987414 /beinc_poller.py
parent0bf37c734a03d6ed643c355dc0fcbdfcc788854b (diff)
Replace pynotify with notify2. Remove pyosd backend.
Diffstat (limited to 'beinc_poller.py')
-rwxr-xr-xbeinc_poller.py132
1 files changed, 14 insertions, 118 deletions
diff --git a/beinc_poller.py b/beinc_poller.py
index 5cceeaa..aaf2d05 100755
--- a/beinc_poller.py
+++ b/beinc_poller.py
@@ -1,8 +1,8 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2# -*- coding: utf-8 -*- 2# -*- coding: utf-8 -*-
3 3
4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v2.0 4# Blackmore's Enhanced IRC-Notification Collection (BEINC) v3.0
5# Copyright (C) 2013-2015 Simeon Simeonov 5# Copyright (C) 2013-2017 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
@@ -21,45 +21,25 @@
21import argparse 21import argparse
22import errno 22import errno
23import getpass 23import getpass
24import httplib # for Python < 2.7.9 24import httplib
25import os 25import os
26import sched 26import sched
27import socket 27import socket
28import ssl 28import ssl
29import sys 29import sys
30import time 30import time
31import xmlrpclib
32 31
33try: 32try:
34 import pynotify 33 import notify2 as pynotify
35except ImportError as e: 34except ImportError as e:
36 pynotify = None 35 pynotify = None
37 36
38try:
39 import pyosd
40 pyosd_positions = {'top': pyosd.POS_TOP,
41 'middle': pyosd.POS_MID,
42 'bottom': pyosd.POS_BOT}
43 pyosd_alignments = {'left': pyosd.ALIGN_LEFT,
44 'center': pyosd.ALIGN_CENTER,
45 'right': pyosd.ALIGN_RIGHT}
46except ImportError as e:
47 pyosd = None
48
49 37
50__author__ = 'Simeon Simeonov' 38__author__ = 'Simeon Simeonov'
51__version__ = '2.0' 39__version__ = '3.0'
52__license__ = 'GPL3' 40__license__ = 'GPL3'
53 41
54 42
55BEINC_SSL_METHODS = {'TLSv1': ssl.PROTOCOL_TLSv1}
56try:
57 BEINC_SSL_METHODS.update({'TLSv1_1': ssl.PROTOCOL_TLSv1_1})
58 BEINC_SSL_METHODS.update({'TLSv1_2': ssl.PROTOCOL_TLSv1_2})
59except:
60 pass
61
62
63class BEINCCustomHTTPSConnection(httplib.HTTPConnection): 43class BEINCCustomHTTPSConnection(httplib.HTTPConnection):
64 """ 44 """
65 This class allows communication via SSL. 45 This class allows communication via SSL.
@@ -128,26 +108,7 @@ def display_notification(args, title, message):
128 title: notification title 108 title: notification title
129 message: notification message 109 message: notification message
130 """ 110 """
131 if args.osd_sys == 'pyosd': 111 if args.osd_sys == 'pynotify':
132 if not pyosd:
133 raise Exception(
134 'Could not load "pyosd".\n'
135 'Please install "pyosd" or use a different osd-system!\n'
136 'Terminating...\n')
137 notification_obj = pyosd.osd()
138 notification_obj.set_timeout(args.osd_timeout)
139 if args.font:
140 notification_obj.set_font(args.font)
141 notification_obj.set_vertical_offset(args.voffset)
142 notification_obj.set_horizontal_offset(args.hoffset)
143 notification_obj.set_align(
144 pyosd_alignments.get(args.alignment, pyosd.ALIGN_LEFT))
145 notification_obj.set_pos(
146 pyosd_positions.get(args.position, pyosd.POS_BOT))
147 notification_obj.set_colour(args.color)
148 notification_obj.display(title, line=0)
149 notification_obj.display(message, line=1)
150 elif args.osd_sys == 'pynotify':
151 if not pynotify: 112 if not pynotify:
152 raise Exception( 113 raise Exception(
153 'Could not load "pynotify".\n' 114 'Could not load "pynotify".\n'
@@ -156,13 +117,8 @@ def display_notification(args, title, message):
156 if not pynotify.init('BEINC Notify'): 117 if not pynotify.init('BEINC Notify'):
157 raise Exception('There was a problem with libnotify\n') 118 raise Exception('There was a problem with libnotify\n')
158 notification_obj = pynotify.Notification(' ') 119 notification_obj = pynotify.Notification(' ')
159 notification_obj.set_timeout(1000 * args.osd_timeout) 120 notification_obj.timeout = 1000 * args.osd_timeout
160 notification_obj.set_property( 121 notification_obj.set_category('im.received')
161 'app_name',
162 '{0} {1}'.format(sys.argv[0], __version__))
163 notification_obj.set_properties(
164 summary=title,
165 body=message)
166 notification_obj.show() 122 notification_obj.show()
167 else: 123 else:
168 raise Exception( 124 raise Exception(
@@ -237,20 +193,6 @@ def main():
237 type=str, 193 type=str,
238 help='BEINC server destination URL') 194 help='BEINC server destination URL')
239 parser.add_argument( 195 parser.add_argument(
240 '-a', '--align',
241 metavar='ALIGNMENT',
242 type=str,
243 dest='alignment',
244 default='left',
245 help='Alignment for "pyosd": "left" (default), "center", "right"')
246 parser.add_argument(
247 '-C', '--color',
248 metavar='COLOR',
249 type=str,
250 dest='color',
251 default='blue',
252 help='Color for "pyosd" (default: "blue")')
253 parser.add_argument(
254 '-c', '--cert-file', 196 '-c', '--cert-file',
255 metavar='FILE', 197 metavar='FILE',
256 type=str, 198 type=str,
@@ -265,20 +207,12 @@ def main():
265 dest='ciphers', 207 dest='ciphers',
266 default='', 208 default='',
267 help='Preferred ciphers list (default: auto)') 209 help='Preferred ciphers list (default: auto)')
268 if sys.hexversion >= 0x20709f0:
269 parser.add_argument(
270 '--disable-hostname-check',
271 action='store_true',
272 dest='disable_hostname_check',
273 default=False,
274 help='Do not check whether server cert matches server hostname')
275 parser.add_argument( 210 parser.add_argument(
276 '--font', 211 '--disable-hostname-check',
277 metavar='FONT', 212 action='store_true',
278 type=str, 213 dest='disable_hostname_check',
279 dest='font', 214 default=False,
280 default=None, 215 help='Do not check whether server cert matches server hostname')
281 help='Custom font for "pyosd" (default: pyosd default font)')
282 parser.add_argument( 216 parser.add_argument(
283 '-f', '--frequency', 217 '-f', '--frequency',
284 metavar='SECONDS', 218 metavar='SECONDS',
@@ -287,13 +221,6 @@ def main():
287 default=10, 221 default=10,
288 help='Polling frequency in seconds (default: 10)') 222 help='Polling frequency in seconds (default: 10)')
289 parser.add_argument( 223 parser.add_argument(
290 '--h-offset',
291 metavar='OFFSET',
292 type=int,
293 dest='hoffset',
294 default=30,
295 help='Horizontal offset for "pyosd" (default: 30)')
296 parser.add_argument(
297 '-n', '--resource-name', 224 '-n', '--resource-name',
298 metavar='NAME', 225 metavar='NAME',
299 type=str, 226 type=str,
@@ -306,7 +233,7 @@ def main():
306 type=str, 233 type=str,
307 dest='osd_sys', 234 dest='osd_sys',
308 default='pynotify', 235 default='pynotify',
309 help='BEINC osd-system: "pynotify" (default), "pyosd"') 236 help='BEINC osd-system: "pynotify" (default)')
310 parser.add_argument( 237 parser.add_argument(
311 '-p', '--password', 238 '-p', '--password',
312 metavar='PASSWORD[FILE]', 239 metavar='PASSWORD[FILE]',
@@ -316,30 +243,6 @@ def main():
316 help='BEINC taget-password / text-file containing the target password' 243 help='BEINC taget-password / text-file containing the target password'
317 ' (default & recommended: prompt for passwd)') 244 ' (default & recommended: prompt for passwd)')
318 parser.add_argument( 245 parser.add_argument(
319 '-P', '--position',
320 metavar='POSITION',
321 type=str,
322 dest='position',
323 default='bottom',
324 help='Position for "pyosd": "top", "middle", "bottom" (default)')
325 if sys.hexversion >= 0x20709f0:
326 parser.add_argument(
327 '-s', '--ssl-version',
328 metavar='VERSION',
329 type=str,
330 dest='ssl_version',
331 default='auto',
332 help='Use SSL version: "auto" (default), '
333 '"SSLv3", "TLSv1", "TLSv1_1", "TLSv1_2"')
334 else:
335 parser.add_argument(
336 '-s', '--ssl-version',
337 metavar='VERSION',
338 type=str,
339 dest='ssl_version',
340 default='auto',
341 help='Use SSL version: "auto" (default), "SSLv3", "TLSv1"')
342 parser.add_argument(
343 '-T', '--socket-timeout', 246 '-T', '--socket-timeout',
344 metavar='SECONDS', 247 metavar='SECONDS',
345 type=int, 248 type=int,
@@ -358,13 +261,6 @@ def main():
358 action='version', 261 action='version',
359 version='%(prog)s {0}'.format(__version__), 262 version='%(prog)s {0}'.format(__version__),
360 help='display program-version and exit') 263 help='display program-version and exit')
361 parser.add_argument(
362 '--v-offset',
363 metavar='OFFSET',
364 type=int,
365 dest='voffset',
366 default=120,
367 help='Vertical offset for "pyosd" (default: 120)')
368 args = parser.parse_args() 264 args = parser.parse_args()
369 if not args.password: 265 if not args.password:
370 try: 266 try: