#!/usr/bin/env python def main(fn_in, fn_out): ''' Import an LDIF file and re-export it to a DSML file. It takes two arguments, the existing and the new file. ''' import os import ldif import dsml filein = file(fn_in, 'r') # We make sure we don't overwrite an existing file. # We let exception rise on their own. fd = os.open(fn_out, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0666) fileout = os.fdopen(fd, 'w') ldif_content = ldif.LDIFRecordList(filein) ldif_content.parse() filein.close() dsml_out = dsml.DSMLWriter(fileout) dsml_out.writeHeader() for dn, record in ldif_content.all_records: dsml_out.writeRecord(dn, record) dsml_out.writeFooter() fileout.close() import sys if len(sys.argv) != 3: raise ValueError else: sys.exit(main(sys.argv[1], sys.argv[2]))