Package pyplusplus :: Package file_writers :: Module single_file

# Source Code for Module pyplusplus.file_writers.single_file

     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  """defines a class that writes L{code_creators.module_t} to single file"""
     7
     8  import os
     9  import writer
    10
    11 -class single_file_t(writer.writer_t):
    12      """generates all code into single cpp file"""
    13
    14 -    def __init__(self, extmodule, file_name, encoding='ascii'):
    15          writer.writer_t.__init__(self, extmodule, encoding=encoding)
    16          self.__fname = file_name
    17
    18      @property
    19 -    def file_name(self):
    20          return self.__fname
    21
    22 -    def write(self):
    23          target_dir = os.path.dirname( self.file_name )
    24          if not target_dir:
    25              target_dir = os.getcwd()
    26          if not os.path.exists( target_dir ):
    27              os.makedirs( target_dir )
    28          headers = self.get_user_headers( [self.extmodule] )
    29          map( lambda header: self.extmodule.add_include( header )
    30               , headers )
    31          self.write_code_repository( target_dir )
    32          self.write_file( self.file_name, self.extmodule.create(), encoding=self.encoding )
    33          self.save_exposed_decls_db( target_dir )
    34