Parse project file to get mcu definition

def get_mcu_definition(self, project_file):
        """ Parse project file to get mcu definition """
        # TODO: check the extension here if it's valid IAR project or we
        # should at least check if syntax is correct check something IAR defines and return error if not
        project_file = join(getcwd(), project_file)
        ewp_dic = xmltodict.parse(file(project_file), dict_constructor=dict)

        mcu = MCU_TEMPLATE

        try:
            ewp_dic['project']['configuration']
        except KeyError:
            # validity check for iar project
            logging.debug("The project_file %s seems to be not valid .ewp file.")
            return mcu

        # Fill in only must-have values, fpu will be added if defined for mcu
        mcu['tool_specific'] = {
            'iar' : {
                # MCU selection
                'OGChipSelectEditMenu' : {
                    'state' : [],
                },
                # we use mcu
                'OGCoreOrChip' : {
                    'state' : [1],
                },
            }
        }


        # we take 0 configuration or just configuration, as multiple configuration possible
        # debug, release, for mcu - does not matter, try and adjust
        try:
            index_general = self._get_option(ewp_dic['project']['configuration'][0]['settings'], 'General')
            configuration = ewp_dic['project']['configuration'][0]
        except KeyError:
            index_general = self._get_option(ewp_dic['project']['configuration']['settings'], 'General')
            configuration = ewp_dic['project']['configuration']
        index_option = self._get_option(configuration['settings'][index_general]['data']['option'], 'OGChipSelectEditMenu')
        OGChipSelectEditMenu = configuration['settings'][index_general]['data']['option'][index_option]
        mcu['tool_specific']['iar']['OGChipSelectEditMenu']['state'].append(OGChipSelectEditMenu['state'].replace('\t', ' ', 1))
        # we keep this as the internal version. FPU - version 1, FPU2 version 2. 
        # TODO:We shall look at IAR versioning to get this right
        fileVersion = 1
        try:
            if self._get_option(configuration['settings'][index_general]['data']['option'], 'FPU2'):
                fileVersion = 2
        except TypeError:
            pass

        index_option = self._get_option(configuration['settings'][index_general]['data']['option'], 'GBECoreSlave')
        GBECoreSlave = configuration['settings'][index_general]['data']['option'][index_option]
        mcu['tool_specific']['iar']['GBECoreSlave'] = { 'state': [int(GBECoreSlave['state'])] }

        if fileVersion == 2:
            index_option = self._get_option(configuration['settings'][index_general]['data']['option'], 'GFPUCoreSlave2')
            GFPUCoreSlave2 = configuration['settings'][index_general]['data']['option'][index_option]
            mcu['tool_specific']['iar']['GFPUCoreSlave2'] = { 'state': [int(GFPUCoreSlave2['state'])] }
            index_option = self._get_option(configuration['settings'][index_general]['data']['option'], 'CoreVariant')
            CoreVariant = configuration['settings'][index_general]['data']['option'][index_option]
            mcu['tool_specific']['iar']['CoreVariant'] = { 'state': [int(CoreVariant['state'])] }
        else:
            index_option = self._get_option(configuration['settings'][index_general]['data']['option'], 'GFPUCoreSlave')
            GFPUCoreSlave = configuration['settings'][index_general]['data']['option'][index_option]
            mcu['tool_specific']['iar']['GFPUCoreSlave'] = { 'state': [int(GFPUCoreSlave['state'])] }
            index_option = self._get_option(configuration['settings'][index_general]['data']['option'], 'Variant')
            Variant = configuration['settings'][index_general]['data']['option'][index_option]
            mcu['tool_specific']['iar']['Variant'] = { 'state': [int(Variant['state'])] }
        return mcu