def _generateFileFromTemplates(templateFileNames, outputFilePath, replacementDict):
 installPath = os.path.dirname(__file__)
 outputFile = open(outputFilePath, 'w')
 outputLines = []
 inputLines = []
 firstFile = True
 for templateFileName in templateFileNames:
  if (not firstFile):
   inputLines.extend(([os.linesep] * 2))
  firstFile = False
  inputFilePath = os.path.join(installPath, templateFileName)
  inputFile = open(inputFilePath)
  inputLines.extend(inputFile.readlines())
  inputFile.close()
 print 'Writing ', len(inputLines), 'lines...'
 for line in inputLines:
  tempLine = line
  for (k, v) in replacementDict.iteritems():
   if (v is None):
    v = 'None'
   tempLine = re.sub(k, v, tempLine)
  outputFile.write(tempLine)
 outputFile.close()

def _generateFileFromTemplates ( templateFileNames , outputFilePath , replacementDict ) : installPath = os . path . dirname ( __file__ ) outputFile = open ( outputFilePath , 'w' ) outputLines = [ ] inputLines = [ ] firstFile = True for templateFileName in templateFileNames : if ( not firstFile ) : inputLines . extend ( ( [ os . linesep ] * 2 ) ) firstFile = False inputFilePath = os . path . join ( installPath , templateFileName ) inputFile = open ( inputFilePath ) inputLines . extend ( inputFile . readlines ( ) ) inputFile . close ( ) print 'Writing ' , len ( inputLines ) , 'lines...' for line in inputLines : tempLine = line for ( k , v ) in replacementDict . iteritems ( ) : if ( v is None ) : v = 'None' tempLine = re . sub ( k , v , tempLine ) outputFile . write ( tempLine ) outputFile . close ( )
generates a file by applying token replacements to the given template file templatefilename: a list of template file names; these files are assumed to be in the same directory as the running expgenerator .