pyplusplus.file_writers

Package pyplusplus :: Package file_writers |

# Source Code for Package pyplusplus.file_writers

     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  """
     7  This package contains few classes, that writes L{code_creators.module_t} to files.
     8
     9  Right now 3 strategies were implemented:
    10
    11      1. All code is written in one file
    12
    13      2. Classic strategy of deviding classes to files: one class in one header + source files.
    14
    15          2.1 Huge classes are splitten to few source files.
    16
    17  """
    18
    19  import types
    20  from writer import writer_t
    21  from single_file import single_file_t
    22  from multiple_files import multiple_files_t
    23  from balanced_files import balanced_files_t
    24  from class_multiple_files import class_multiple_files_t
    25  from md5sum_repository import repository_t
    26  from md5sum_repository import cached_repository_t
    27
    28 -def has_pypp_extenstion( fname ):
    29      """returns True if file has Py++ specific extension, otherwise False"""
    30      for ext in ( multiple_files_t.HEADER_EXT, multiple_files_t.SOURCE_EXT ):
    31          if fname.endswith( ext ):
    32              return True
    33      return False
    34
    35 -def write_file( data, file_path, encoding='ascii' ):
    36      """writes data to file"""
    37      if isinstance( data, types.StringTypes ):
    38          writer_t.write_file( data, file_path, encoding=encoding )
    39      else:
    40          sf = single_file_t( data, file_path, encoding=encoding )
    41          sf.write()
    42
    43 -def write_multiple_files( extmodule, dir_path, files_sum_repository=None, encoding='ascii' ):
    44      """writes extmodule to multiple files"""
    45      mfs = multiple_files_t( extmodule, dir_path, files_sum_repository=files_sum_repository, encoding=encoding )
    46      mfs.write()
    47      return mfs.written_files
    48
    49 -def write_balanced_files( extmodule, dir_path, number_of_buckets, files_sum_repository=None, encoding='ascii' ):
    50      """writes extmodule to fixed number of multiple cpp files"""
    51      mfs = balanced_files_t( extmodule, dir_path, number_of_buckets, files_sum_repository=files_sum_repository, encoding=encoding )
    52      mfs.write()
    53      return mfs.written_files
    54
    55 -def write_class_multiple_files( extmodule, dir_path, huge_classes, files_sum_repository, encoding='ascii' ):
    56      """writes extmodule to multiple files and splits huge classes to few source files"""
    57      mfs = class_multiple_files_t( extmodule, dir_path, huge_classes, files_sum_repository=files_sum_repository, encoding=encoding )
    58      mfs.write()
    59      return mfs.written_files
    60