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-Url: http://git.tremily.us/?a=commitdiff_plain;h=4bb21099733b147f7a6d733285b2cb23d7d8a67f;p=blog.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/posts/LDAP/abook-ldif-cleanup.py b/posts/LDAP/abook-ldif-cleanup.py index 5fd04f6..6eca519 100755 --- a/posts/LDAP/abook-ldif-cleanup.py +++ b/posts/LDAP/abook-ldif-cleanup.py @@ -1,6 +1,19 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # -# Copy... +# Copyright (C) 2011-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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . """Cleanup the LDIF output from abook_ using `python-ldap`_. diff --git a/posts/LDAP/ldap-jpeg.py b/posts/LDAP/ldap-jpeg.py index 15866a4..2a73073 100755 --- a/posts/LDAP/ldap-jpeg.py +++ b/posts/LDAP/ldap-jpeg.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # # Copyright (C) 2011-2012 W. Trevor King # @@ -54,7 +54,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')) @@ -81,9 +81,9 @@ def search(query, connection=None): post = '' if query: post = '*' - filterstr = '(|%s)' % ( - u' '.join([u'(%s=*%s%s)' % (field, query, post) - for field in ['cn', 'displayName' 'uid', 'mail']])) + 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'), _ldap.SCOPE_SUBTREE, diff --git a/posts/LDAP/mutt-ldap.py b/posts/LDAP/mutt-ldap.py index 7c51d85..d75f51b 100755 --- a/posts/LDAP/mutt-ldap.py +++ b/posts/LDAP/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))