3 # * Copyright 2001 Rod Senra <Rodrigo.Senra@ic.unicamp.br>
5 # * This file is free software; you can redistribute it and/or modify it
6 # * under the terms of the GNU General Public License as published by
7 # * the Free Software Foundation; either version 2 of the License, or
8 # * (at your option) any later version.
10 # * This program is distributed in the hope that it will be useful, but
11 # * WITHOUT ANY WARRANTY; without even the implied warranty of
12 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # * General Public License for more details.
15 # * You should have received a copy of the GNU General Public License
16 # * along with this program; if not, write to the Free Software
17 # * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 header = """<?xml version="1.0" encoding="ISO-8859-1"?>
38 def printGroupRec(fd,name,members):
39 """ Print XML group record from r-tuple"""
40 fd.write(" <group name=\"%s\">\n"%(name))
43 fd.write(" </group>\n")
45 def printRec(fd,r,ident):
46 """ Print XML group record from r-tuple"""
47 fd.write("%s<item>\n"%(ident) )
48 fd.write("%s <name>%s</name>\n"%(ident,r[0]))
49 fd.write("%s <address>%s</address>\n"%(ident,r[1]))
50 fd.write("%s <remarks>%s</remarks>\n"%(ident,r[2]))
51 fd.write("%s</item>\n"%(ident))
53 outfd = open('addressbook.xml','w')
59 for line in open(sys.argv[1]).readlines():
60 line = line[:-1].strip() # clean string
63 if rec.has_key('description'):
64 str = rec['description']
65 elif rec.has_key('xmozillanickname'):
66 str = rec['xmozillanickname']
67 elif rec.has_key('sn'):
72 if rec.has_key('member'):
73 printGroupRec(outfd,rec['cn'].strip(),rec['member'])
74 elif rec.has_key('mail'):
75 printRec(outfd,(rec['cn'].strip(),rec['mail'].strip(),str.strip())," ")
85 key,value = line.split(':')
89 name,addr = value.split(',')
90 name = name.split('=')[1].strip()
91 addr = addr.split('=')[1].strip()
92 value = (name,addr,'')
93 if rec.has_key('member'):
94 rec['member'].append(value)
96 rec['member'] = [value]