Search
j0ke.net Open Build Service
>
Projects
>
home:netmax
:
tools
>
urlwatch
> urlwatch_xmpp_1.17.patch
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File urlwatch_xmpp_1.17.patch of Package urlwatch (Revision 13)
Currently displaying revision
13
,
show latest
--- urlwatch-1.17/urlwatch.orig 2014-08-01 21:48:56.000000000 +0200 +++ urlwatch-1.17/urlwatch 2014-10-04 17:56:19.941211878 +0200 @@ -60,6 +60,7 @@ cache_dir = os.path.join(urlwatch_dir, 'cache') scripts_dir = os.path.join(urlwatch_dir, 'lib') hooks_py = os.path.join(scripts_dir, 'hooks.py') +xmpp_txt = os.path.join(urlwatch_dir, 'xmpp.txt') # Check if we are installed in the system already (prefix, bindir) = os.path.split(os.path.dirname(os.path.abspath(sys.argv[0]))) @@ -164,7 +165,10 @@ parser.add_option('-f', '--mailfrom', dest='email_from', metavar='ADDRESS', help='Alternate From: address for e-mail (--mailto)') parser.add_option('-s', '--smtp', dest='email_smtp', metavar='SERVER', help='SMTP server for e-mail (--mailto)') - parser.set_defaults(verbose=False, display_errors=False) + parser.add_option('-x', '--xmpp', action='store_true', dest='xmpp', help='Send a message to XMPP clients') + parser.add_option('', '--xmpp-file', dest='xmpp_file', metavar='FILE', help='Read XMPP login data and recipients from [FILE] instead') + + parser.set_defaults(verbose=False, display_errors=False, xmpp=False) (options, args) = parser.parse_args(sys.argv) @@ -217,6 +221,9 @@ log.error('%s is not a file' % options.hooks) print 'Error: %s is not a file' % options.hooks sys.exit(1) + + if options.xmpp_file: + options.xmpp = True # Created all needed folders for needed_dir in (urlwatch_dir, cache_dir, scripts_dir): @@ -236,6 +243,52 @@ if not options.hooks and os.path.exists(hooks_py_example) and not os.path.exists(hooks_py_fn): shutil.copy(hooks_py_example, hooks_py_fn) sys.exit(1) + + if options.xmpp: + try: + import xmpp + except ImportError: + log.error('python-xmpp not installed') + print 'Error: You need python-xmpp installed to use the -x switch' + sys.exit(1) + + if options.xmpp_file: + if os.path.isfile(options.xmpp_file): + xmpp_txt = options.xmpp_file + log.info('using %s as xmpp.txt' % xmpp_txt) + else: + log.error('no such file: %s' % options.xmpp_file) + print 'Error: There is no such file: %s' % options.xmpp_file + sys.exit(1) + + try: + xmpp_filehandle = open(xmpp_txt, 'r') + except IOError: + log.error('No xmpp.txt file') + print 'Error: You need to create a xmpp.txt file first.' + print '' + print 'Place it in %s' % os.path.dirname(xmpp_txt) + print '' + print '' + print 'Syntax is:' + print '' + print '\tsender-username@server.tld senderpassword' + print '\tfirst-recipient@jabberserver1.tld' + print '\tsecond-recipient@jabberserver2.tld' + print '\tthird-recipient@foobarserver.tld' + print '\t...' + print '' + sys.exit(1) + + xmpp_lines = xmpp_filehandle.readlines() + xmpp_filehandle.close() + for i in xrange(len(xmpp_lines)): + xmpp_lines[i] = xmpp_lines[i].strip("\n") + (xmpp_from, xmpp_pass) = xmpp_lines[0].split(' ') + xmpp_to = [] + for i in xrange(1, len(xmpp_lines)): + xmpp_to.append(xmpp_lines[i]) + log.info('using %s to send status messages to %s' % (xmpp_from, xmpp_to)) headers = { 'User-agent': user_agent, @@ -359,18 +412,36 @@ short_summary = '' # Output everything - if len(summary) > 1: + if len(summary) > 0: log.info('printing summary with %d items' % len(summary)) short_summary = '-'*line_length + '\n' short_summary += 'summary: %d changes' % (len(summary),) + '\n\n' + msg = '' for id, line in enumerate(summary): short_summary += '%02d. %s' % (id+1, line) + '\n' + msg += "\n" + '%02d. %s' % (id+1, line) short_summary += '-'*line_length + '\n' short_summary += '\n\n\n' print short_summary + + if (options.xmpp): + try: + (xmpp_user, xmpp_server) = xmpp_from.split('@') + client = xmpp.Client(xmpp_server) + client.connect(server=(xmpp_server,5223)) + client.auth(xmpp_user, xmpp_pass, 'urlwatch') + client.sendInitPresence() + for to in xmpp_to: + message = xmpp.Message(to, msg) + message.setAttr('type', 'chat') + client.send(message) + except: + log.error('Could not send message to %s' % xmpp_to) + print 'Error: Could not send message to %s' % xmpp_to + else: log.info('summary is too short - not printing') - if len(details) > 1: + if len(details) > 1 and not options.xmpp: log.info('printing details with %d items' % len(details)) print '\n'.join(details) print '-- '