# Copyright CERN, CH-1211 Geneva 23, 2004-2005, All rights reserved.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose is hereby granted without fee, provided that this copyright and
# permissions notice appear in all copies and derivatives.
#
# This software is provided "as is" without express or implied warranty.

import os, sys, string

model = """
# This file has been generated by genreflex with the --rootmap option
#--Final End
"""

#----------------------------------------------------------------------------------
def genRootMap(mapfile, dicfile, libfile, classes) :
  startmark = '#--Begin ' + dicfile + '\n'
  endmark   = '#--End   ' + dicfile + '\n'
  finalmark = '#--Final End\n'
  transtable = string.maketrans(': ', '@$')

  new_lines = []
  if libfile.rfind('/') != -1 : libfile =  libfile[libfile.rfind('/')+1:]
  for c in classes :
    nc = string.translate(str(c), transtable)
    nc = nc.replace(' ','')
    new_lines += '%-45s %s\n' % ('Library.' + nc + ':', libfile )
  if not os.path.exists(mapfile) :
    lines = [ line+'\n' for line in model.split('\n')]
  else :
    f = open(mapfile,'r') 
    lines = [ line for line in f.readlines()]
    f.close()
  if startmark in lines and endmark in lines :
    lines[lines.index(startmark)+1 : lines.index(endmark)] = new_lines
  else :
    lines[lines.index(finalmark):lines.index(finalmark)] = [startmark]+new_lines+[endmark]
  f = open(mapfile,'w')
  f.writelines(lines)
  f.close()



@@ -61,20 +61,18 @@
 eserved.
-%0D
 %0A#
-%0D
 %0A# Permi
@@ -135,17 +135,16 @@
  for any
-%0D
 %0A# purpo
@@ -209,17 +209,16 @@
 ight and
-%0D
 %0A# permi
@@ -272,12 +272,10 @@
 ves.
-%0D
 %0A#
-%0D
 %0A# T
@@ -343,19 +343,17 @@
 arranty.
-%0D%0A%0D
+%0A
 %0Aimport 
@@ -367,19 +367,17 @@
 , string
-%0D%0A%0D
+%0A
 %0Amodel =
@@ -380,17 +380,16 @@
 el = %22%22%22
-%0D
 %0A# This 
@@ -450,17 +450,16 @@
 p option
-%0D
 %0A#--Fina
@@ -467,16 +467,13 @@
  End
-%0D
 %0A%22%22%22
-%0D%0A%0D
+%0A
 %0A#--
@@ -552,17 +552,16 @@
 --------
-%0D
 %0Adef gen
@@ -605,17 +605,16 @@
 asses) :
-%0D
 %0A  start
@@ -648,17 +648,16 @@
 e + '%5Cn'
-%0D
 %0A  endma
@@ -691,17 +691,16 @@
 e + '%5Cn'
-%0D
 %0A  final
@@ -722,17 +722,16 @@
 l End%5Cn'
-%0D
 %0A  trans
@@ -767,14 +767,12 @@
 , '@
-$')%0D%0A%0D
+-')%0A
 %0A  n
@@ -784,17 +784,16 @@
 nes = %5B%5D
-%0D
 %0A  if li
@@ -858,17 +858,16 @@
 '/')+1:%5D
-%0D
 %0A  for c
@@ -875,25 +875,24 @@
 in classes :
-%0D
 %0A    nc = st
@@ -925,17 +925,16 @@
 nstable)
-%0D
 %0A    nc 
@@ -953,17 +953,16 @@
 (' ','')
-%0D
 %0A    new
@@ -1019,17 +1019,16 @@
 ibfile )
-%0D
 %0A  if no
@@ -1054,17 +1054,16 @@
 pfile) :
-%0D
 %0A    lin
@@ -1109,17 +1109,16 @@
 t('%5Cn')%5D
-%0D
 %0A  else 
@@ -1114,25 +1114,24 @@
 ')%5D%0A  else :
-%0D
 %0A    f = ope
@@ -1145,17 +1145,16 @@
 le,'r') 
-%0D
 %0A    lin
@@ -1191,17 +1191,16 @@
 lines()%5D
-%0D
 %0A    f.c
@@ -1205,17 +1205,16 @@
 .close()
-%0D
 %0A  if st
@@ -1252,17 +1252,16 @@
  lines :
-%0D
 %0A    lin
@@ -1323,17 +1323,16 @@
 ew_lines
-%0D
 %0A  else 
@@ -1332,17 +1332,16 @@
   else :
-%0D
 %0A    lin
@@ -1423,17 +1423,16 @@
 endmark%5D
-%0D
 %0A  f = o
@@ -1447,17 +1447,16 @@
 ile,'w')
-%0D
 %0A  f.wri
@@ -1469,17 +1469,16 @@
 s(lines)
-%0D
 %0A  f.clo
@@ -1485,10 +1485,7 @@
 se()
-%0D%0A%0D%0A%0D
+%0A%0A
 %0A

Use a dash (-) as the character replacing a space in a rootmap file