configurationengine/source/plugins/symbian/ConeHCRPlugin/hcrplugin/header_writer.py
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
equal deleted inserted replaced
-1:000000000000 0:2e8eeb919028
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 import os
       
    18 
       
    19 class HeaderWriter(object):
       
    20     def __init__(self,output_file, output_obj):
       
    21         self.output_obj = output_obj
       
    22         self.output_file = output_file
       
    23 
       
    24     def write(self):
       
    25         header_guard = os.path.basename(self.output_file).upper()
       
    26         header_guard = header_guard.replace('/', '_').replace('\\', '_').replace('.', '_')
       
    27         lines = [
       
    28             "#ifndef %s" % header_guard,
       
    29             "#define %s" % header_guard,
       
    30             "",
       
    31             "#include <hcr.h>",
       
    32             "",
       
    33         ]
       
    34         
       
    35         # Sort by category UID to make testing easier
       
    36         categories = sorted(self.output_obj.categories, key=lambda c: c.category_uid)
       
    37         for i, category in enumerate(categories):
       
    38             lines.append('const HCR::TCategoryUid %s = 0x%08X;' % (category.name, category.category_uid))
       
    39             lines.append('')
       
    40             
       
    41             # Again, sort for testability
       
    42             settings = sorted(category.settings, key=lambda s: s.id)
       
    43             max_name_len = max([len(s.name) for s in settings])
       
    44             format = "const HCR::TElementId %%-%ds = 0x%%08X;" % max_name_len
       
    45             for setting in settings:
       
    46                 if setting.comment: lines.append("// %s" % setting.comment)
       
    47                 lines.append(format % (setting.name, setting.id))
       
    48             
       
    49             if i + 1 != len(categories):
       
    50                 lines.append('')
       
    51                 lines.append('// ' + 70 * '-')
       
    52                 lines.append('')
       
    53             
       
    54         lines.extend([
       
    55             "",
       
    56             "#endif",
       
    57         ])
       
    58         
       
    59         f = open(self.output_file, 'wb')
       
    60         try:        f.write(os.linesep.join(lines))
       
    61         finally:    f.close()