Package pyplusplus :: Package code_creators :: Module include_directories

# Source Code for Module pyplusplus.code_creators.include_directories

     1  # Copyright 2004-2008 Roman Yakovenko.
     2  # Distributed under the Boost Software License, Version 1.0. (See
     3  # accompanying file LICENSE_1_0.txt or copy at
     4  # http://www.boost.org/LICENSE_1_0.txt)
     5
     6  import os
     7  import pprint
     8  import instruction
     9
    10 -class include_directories_t(instruction.instruction_t):
    11      """
    12      The instance of this class holds a list of user defined directories.
    13      L{include_t} and {precompiled_header_t} code creators use it to generate
    14      relative include directives.
    15      """
    16 -    def __init__(self):
    17          instruction.instruction_t.__init__(self)
    18          self._user_defined = []
    19          self._std = []
    20
    21      @staticmethod
    22 -    def normalize( path ):
    23          return os.path.normpath( os.path.normcase( path ) )
    24
    25 -    def _get_user_defined(self):
    26          self._user_defined = map( self.normalize, self._user_defined )
    27          return self._user_defined
    28 -    def _set_user_defined(self, includes):
    29          self._user_defined = includes
    30      user_defined = property( _get_user_defined, _set_user_defined )
    31
    32 -    def _get_std(self):
    33          self._std = map( self.normalize, self._std )
    34          return self._std
    35 -    def _set_std(self, includes):
    36          self._std = includes
    37      std = property( _get_std, _set_std )
    38
    39 -    def is_std( self, header ):
    40          headers = self.std[:]
    41          headers.append( self.normalize( header ) )
    42          dname = os.path.commonprefix( headers )
    43          return dname in headers[:-1]
    44
    45 -    def is_user_defined(self, header):
    46          return not self.is_std( header )
    47
    48 -    def _remove_common_prefix( self, header, headers ):
    49          lcp = ''# longest common path
    50          for predefined_header in headers:
    51              dname = os.path.commonprefix( [ predefined_header, header ] )
    52              if dname == predefined_header and len( dname ) > len( lcp ):
    53                  lcp = dname
    54          if not lcp:
    55              return header
    56          new_header = header[ len( lcp ): ]
    57          if lcp and new_header and new_header[0] in '/\\':
    58              new_header = new_header[1:]
    59          return new_header
    60
    61 -    def normalize_header(self, header ):
    62          headers = self.std + self.user_defined
    63          answer = self._remove_common_prefix( header, headers )
    64          return answer.replace( '\\', '/' )
    65
    66 -    def _generate_description(self):
    67          desc = ["std directories: " + pprint.pformat( self.std )]
    68          temp = pprint.pformat( self.user_defined )
    69          if os.linesep not in temp:
    70              #fixing bug on windows where linesep == \n\r
    71              #while pformat uses \n
    72              temp = temp.replace( '\n', os.linesep )
    73          desc.append( "user defined directories: " + temp )
    74          return os.linesep.join( desc )
    75