usermode/library/configuration/helper.py

00001 import os
00002 import string
00003 import SCons.Environment
00004 from SCons.Script import Dir
00005 from SCons.Variables import Variables, EnumVariable, BoolVariable
00006 import sys
00007 
00008 class Directives:
00009         """
00010                 Creates a list of C preprocessor directives.
00011         """
00012 
00013         def __init__(self, cfg_name, module_name, cmd_line_args, bool_vars, enum_vars, other_vars):
00014                 self._cfg_name = cfg_name
00015                 self._module_name = module_name
00016                 self._cmd_line_args = cmd_line_args
00017                 self._bool_vars = bool_vars
00018                 self._enum_vars = enum_vars
00019                 self._other_vars = other_vars
00020                 self._env = SCons.Environment.Environment()
00021                 self.updateVariables()
00022                 self.updateValues()
00023 
00024         def updateValues(self):
00025                 self._variables.Update(self._env)
00026 
00027         def updateVariables(self):
00028                 """
00029                         Retrieve and define help options for configuration variables.
00030                 """
00031                 rootdir = Dir('#').abspath
00032                 cfg_files = [
00033                         rootdir + "/library/configuration/" + self._cfg_name + "/" + self._module_name + ".py",
00034                 ]
00035                 
00036                 cfgVars = Variables(cfg_files, self._cmd_line_args)
00037                 [cfgVars.Add(BoolVariable(name, helptext, default)) for name, helptext, default in self._bool_vars]
00038                 [cfgVars.Add(EnumVariable(name, helptext, default, valid)) for name, helptext, default, valid in self._enum_vars]
00039                 [cfgVars.Add(option) for option in self._other_vars]
00040 
00041                 self._variables = cfgVars
00042 
00043         def getBooleanDirectives(self, vars):
00044                 """
00045                         Takes the boolean directives of this instance and composes them
00046                         into a list where each entry is 'X' if X is True.
00047                 """
00048                 directives = []
00049                 for name, helptext, default in vars:
00050                         if self._env[name] is True:
00051                                 directive = '%s' % name
00052                                 directives.append(directive)
00053                 return directives
00054 
00055         def getDirectives(self, vars):
00056                 """
00057                         Takes a list of vars and returns composes them
00058                         into a list where each entry is 'NAME=VAL'.
00059                 """
00060                 directives = []
00061                 for option in vars:
00062                         directive = '%s=%s' % (option[0], self._env[option[0]])
00063                         directives.append(directive)
00064                 return directives
00065 
00066         def getPreprocessorDefinitions(self):
00067                 """
00068                         Takes the input configuration and generates a string of preprocessor definitions
00069                         appropriate to the environment as the configuration demands.
00070                 """
00071                 bool_directives = self.getBooleanDirectives(self._bool_vars)
00072                 enum_directives = self.getDirectives(self._enum_vars)
00073                 other_directives = self.getDirectives(self._other_vars)
00074                 all_directives = bool_directives + enum_directives + other_directives
00075 
00076                 return all_directives

Generated on Sat Apr 23 11:43:35 2011 for Mnemosyne by  doxygen 1.4.7