From: W. Trevor King Date: Fri, 28 Sep 2012 00:08:16 +0000 (-0400) Subject: posts:ldap: update Python scripts to explicitly use Python 2. X-Git-Tag: v0.1~28 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d15e3b71efd30ae3d900991fe1918c67f077a9e5;p=mutt-ldap.git posts:ldap: update Python scripts to explicitly use Python 2. python-ldap doesn't have a Python 3 version yet. I made a few other changes to increase Python 3 compatibility, and added a full copyright blurb to abook-ldif-cleanup.py. --- diff --git a/mutt-ldap.py b/mutt-ldap.py index 7c51d85..d75f51b 100755 --- a/mutt-ldap.py +++ b/mutt-ldap.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # -# Copyright (C) 2008-2011 W. Trevor King +# Copyright (C) 2008-2012 W. Trevor King # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -59,7 +59,7 @@ def connect(): protocol = 'ldap' if CONFIG.getboolean('connection', 'ssl'): protocol = 'ldaps' - url = '%s://%s:%s' % ( + url = '{}://{}:{}'.format( protocol, CONFIG.get('connection', 'server'), CONFIG.get('connection', 'port')) @@ -85,8 +85,8 @@ def search(query, connection=None): post = '' if query: post = '*' - filterstr = '(|%s)' % ( - u' '.join([u'(%s=*%s%s)' % (field, query, post) + filterstr = u'(|{})'.format( + u' '.join([u'({}=*{}{})'.format(field, query, post) for field in ['cn', 'displayName', 'uid', 'mail']])) r = connection.search_s( CONFIG.get('connection', 'basedn'), @@ -112,5 +112,5 @@ if __name__ == '__main__': entries = search(query) addresses = list(itertools.chain( *[format_entry(e) for e in sorted(entries)])) - print '%d addresses found:' % len(addresses) - print '\n'.join(addresses) + print('{} addresses found:'.format(len(addresses))) + print('\n'.join(addresses))