1   
  2   
  3   
  4   
  5   
  6  """This module contains the implementation of the L{config_t} class. 
  7  """ 
  8   
  9  import os 
 10  import sys 
 11  import copy 
 14      """Configuration object to collect parameters for invoking C++ parser 
 15   
 16      This class serves as a base class for the parameters that can be used 
 17      to customize the call to C++ parser. This class also allows users to work with 
 18      relative files paths. In this case files are searched in the following order: 
 19   
 20      1. current directory 
 21   
 22      2. working directory 
 23   
 24      3. additional include paths specified by the user 
 25   
 26      """ 
 27 -    def __init__( self 
 28                    , working_directory='.' 
 29                    , include_paths=None 
 30                    , define_symbols=None 
 31                    , undefine_symbols=None 
 32                    , cflags="" 
 33                    , compiler=None): 
  54   
 56          raise NotImplementedError( self.__class__.__name__ ) 
  57   
 59          return self.__working_directory 
  61          self.__working_directory=working_dir 
  62      working_directory = property( __get_working_directory, __set_working_directory ) 
 63   
 64      @property 
 66          """list of include paths to look for header files""" 
 67          return self.__include_paths 
  68   
 69      @property 
 71          """list of "define" directives """ 
 72          return self.__define_symbols 
  73   
 74      @property 
 76          """list of "undefine" directives """ 
 77          return self.__undefine_symbols 
  78   
 79      @property 
 81          """compiler name to simulate""" 
 82          return self.__compiler 
  83   
 88      cflags = property( __get_cflags, __set_cflags 
 89                        , doc="additional flags to pass to compiler" ) 
 90   
 92          if os.path.isdir( dir_path ): 
 93              return 
 94          msg = None 
 95          if os.path.exists( self.working_directory ): 
 96              raise RuntimeError( '%s("%s") does not exist!' % ( meaning, dir_path ) ) 
 97          else: 
 98              raise RuntimeError( '%s("%s") should be "directory", not a file.' % ( meaning, dir_path ) ) 
  99   
100   
102          """validates the configuration settings and raises RuntimeError on error""" 
103          self.__ensure_dir_exists( self.working_directory, 'working directory' ) 
104          map( lambda idir: self.__ensure_dir_exists( idir, 'include directory' ) 
105               , self.include_paths ) 
  106   
109      """Configuration object to collect parameters for invoking gccxml. 
110   
111      This class serves as a container for the parameters that can be used 
112      to customize the call to gccxml. 
113      """ 
114 -    def __init__( self 
115                    , gccxml_path='' 
116                    , working_directory='.' 
117                    , include_paths=None 
118                    , define_symbols=None 
119                    , undefine_symbols=None 
120                    , start_with_declarations=None 
121                    , ignore_gccxml_output=False 
122                    , cflags="" 
123                    , compiler=None): 
 141   
143          return copy.deepcopy( self ) 
 144   
146          return self.__gccxml_path 
 148          self.__gccxml_path = new_path 
 149      gccxml_path = property( __get_gccxml_path, __set_gccxml_path 
150                              , doc="gccxml binary location" ) 
151   
152      @property 
154          """list of declarations gccxml should start with, when it dumps declaration tree""" 
155          return self.__start_with_declarations 
 156   
158          return self.__ignore_gccxml_output 
 160          self.__ignore_gccxml_output = val 
 161      ignore_gccxml_output = property( __get_ignore_gccxml_output, __set_ignore_gccxml_output 
162                                      , doc="set this property to True, if you want pygccxml to ignore any error\\warning that comes from gccxml" ) 
163   
164   
166          super( gccxml_configuration_t, self ).raise_on_wrong_settings() 
167          if os.path.isfile( self.gccxml_path ): 
168              return 
169          if sys.platform == 'win32': 
170              gccxml_name = 'gccxml' + '.exe' 
171              environment_var_delimiter = ';' 
172          elif sys.platform == 'linux2' or sys.platform == 'darwin': 
173              gccxml_name = 'gccxml' 
174              environment_var_delimiter = ':' 
175          else: 
176              raise RuntimeError( 'unable to find out location of gccxml' ) 
177          may_be_gccxml = os.path.join( self.gccxml_path, gccxml_name ) 
178          if os.path.isfile( may_be_gccxml ): 
179              self.gccxml_path = may_be_gccxml 
180          else: 
181              for path in os.environ['PATH'].split( environment_var_delimiter ): 
182                  gccxml_path = os.path.join( path, gccxml_name ) 
183                  if os.path.isfile( gccxml_path ): 
184                      self.gccxml_path = gccxml_path 
185                      break 
186              else: 
187                  msg = 'gccxml_path("%s") should exists or to be a valid file name.' \ 
188                        % self.gccxml_path 
189                  raise RuntimeError( msg ) 
  190   
191  config_t = gccxml_configuration_t  
192