#!/usr/bin/python # # Copyright (C) 2007 Scott Draves # # 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 2 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, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # release 0.1 2007.02.01 import sys,ldif def format(y, x): z = y.get(x) if None==z: return '' return z[0] class MyParser(ldif.LDIFParser): def handle(self,dn,entry): first = format(entry,'givenName') last = format(entry,'sn') tel = format(entry,'telephoneNumber') mob = format(entry,'mobile') em = format(entry,'mail') if tel != '' or mob != '': print first + ',' + last + ',' + em + ',' + tel + ',' + mob print 'First Name,Last Name,E-mail Address,Mobile Phone,Home Phone' MyParser(sys.stdin).parse()