bthci/bthci2/CommandsEvents/generator/mmp.py
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 # Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Write a mmp file
       
    15 # Template substitution values are partially deduced from 'datafiles'.
       
    16 # Substitutions are:
       
    17 # $FILENAME: the name of the file generated.
       
    18 # $SOURCES: source files to add.
       
    19 # $GENERATE_TIME_STAMP: timestamp showing when the generator produced the file
       
    20 # 
       
    21 #
       
    22 
       
    23 import ConfigParser
       
    24 from datainput import getLines
       
    25 from time import strftime
       
    26 from utils import doTimeStampCompareAndWrite
       
    27 
       
    28 # Reads .ini file looking for two things, either a 'Datafile' for multiple source file or a 'Source' entry for a single source file.
       
    29 # SOURCEPATH and SOURCE specifiers to the mmp file. Entries can have a 'Postfix' which will be appended to source file names.
       
    30 def makeSources(aIni):
       
    31     cfg = ConfigParser.ConfigParser()
       
    32     cfg.readfp(file(aIni))
       
    33     src = ''
       
    34     
       
    35     for s in cfg.sections():
       
    36         print('Processing SOURCEPATH for %s...' % s)
       
    37         src += 'SOURCEPATH\t\t' + cfg.get(s, 'SourcePath') + '\n'
       
    38 
       
    39         print('Processing SOURCE for %s...' % s)
       
    40         
       
    41         if cfg.has_option(s, 'Datafile'):
       
    42             entries = getLines(filter(lambda(e): e[0] != '#', file(cfg.get(s, 'Datafile')).readlines()))
       
    43             for e in entries:
       
    44 			#To remove checksource build warnings the following check is made to ensure mmp file is generated with the same case filenames as in Perforce. 
       
    45 				if e[0] == "WriteLocalName" and cfg.get(s, 'Postfix') == "command":
       
    46 					src += 'SOURCE\t\t\t' + e[0] + 'Command' + '.cpp\n'
       
    47 				elif e[0] == "ReadLocalName":
       
    48 					if cfg.get(s, 'Postfix') == "command":
       
    49 						src += 'SOURCE\t\t\t' + e[0] + 'Command' + '.cpp\n'
       
    50 					elif cfg.get(s, 'Postfix') == "completeevent":
       
    51 						src += 'SOURCE\t\t\t' + e[0] + 'CompleteEvent' + '.cpp\n'
       
    52 				else:
       
    53 					src += 'SOURCE\t\t\t' + e[0].lower() + (cfg.get(s, 'Postfix')).lower() + '.cpp\n'
       
    54                 
       
    55         elif cfg.has_option(s, 'Source'):
       
    56             src += 'SOURCE\t\t\t' + cfg.get(s, 'Source') + '\n'
       
    57                 
       
    58         src += '\n'
       
    59                 
       
    60         print('Done, %s source files.\n' % len(entries))
       
    61         
       
    62     return src
       
    63 
       
    64 def writeMMPFile(aIni, aTemplate, aDst):
       
    65     t = {'FILENAME': aDst.lower(),
       
    66          'SOURCES': makeSources(aIni),
       
    67          'GENERATE_TIME_STAMP': strftime("%a, %d %b %Y %H:%M:%S") + ' (time stamp)'}
       
    68 
       
    69     #file(aDst.lower(), 'w+').write(aTemplate.substitute(t))
       
    70     doTimeStampCompareAndWrite(aDst.lower(), aTemplate.substitute(t))
       
    71     
       
    72