[pygccxml-commit] SF.net SVN: pygccxml: [506] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-09-03 07:59:30
|
Revision: 506 http://svn.sourceforge.net/pygccxml/?rev=506&view=rev Author: roman_yakovenko Date: 2006-09-03 00:59:17 -0700 (Sun, 03 Sep 2006) Log Message: ----------- adding treatment to unused files Modified Paths: -------------- pyplusplus_dev/pyplusplus/file_writers/__init__.py pyplusplus_dev/pyplusplus/file_writers/multiple_files.py pyplusplus_dev/pyplusplus/module_builder/builder.py pyplusplus_dev/unittests/algorithms_tester.py Modified: pyplusplus_dev/pyplusplus/file_writers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/file_writers/__init__.py 2006-09-01 14:32:52 UTC (rev 505) +++ pyplusplus_dev/pyplusplus/file_writers/__init__.py 2006-09-03 07:59:17 UTC (rev 506) @@ -9,9 +9,9 @@ Right now 3 strategies were implemented: 1. All code is written in one file - + 2. Classic strategy of deviding classes to files: one class in one header + source files. - + 2.1 Huge classes are splitten to few source files. """ @@ -29,13 +29,15 @@ else: sf = single_file_t( data, file_path ) sf.write() - + def write_multiple_files( extmodule, dir_path ): """writes extmodule to multiple files""" mfs = multiple_files_t( extmodule, dir_path ) mfs.write() - + return mfs.written_files + def write_class_multiple_files( extmodule, dir_path, huge_classes ): """writes extmodule to multiple files and splits huge classes to few source files""" mfs = class_multiple_files_t( extmodule, dir_path, huge_classes ) - mfs.write() + mfs.write() + return mfs.written_files Modified: pyplusplus_dev/pyplusplus/file_writers/multiple_files.py =================================================================== --- pyplusplus_dev/pyplusplus/file_writers/multiple_files.py 2006-09-01 14:32:52 UTC (rev 505) +++ pyplusplus_dev/pyplusplus/file_writers/multiple_files.py 2006-09-03 07:59:17 UTC (rev 506) @@ -16,7 +16,7 @@ """ This class implements classic strategy of deviding classes to files one class in one header + source files. - """ + """ HEADER_EXT = '.pypp.hpp' SOURCE_EXT = '.pypp.cpp' @@ -27,9 +27,9 @@ @type extmodule: module_t @param directory_path: The output directory where the source files are written @type directory_path: str - - @param write_main: if it is True, the class will write out a main file - that calls all the registration methods. + + @param write_main: if it is True, the class will write out a main file + that calls all the registration methods. @type write_main: boolean """ writer.writer_t.__init__(self, extmodule) @@ -39,8 +39,13 @@ self.split_header_names = [] # List of include file names for split files self.split_method_names = [] # List of methods from the split files self.write_main = write_main + self.written_files = [] - + + def write_file( self, fpath, content ): + self.written_files.append( fpath ) + writer.writer_t.write_file( fpath, content ) + def create_dir( self, directory_path ): """Create the output directory if it doesn't already exist. """ @@ -76,7 +81,7 @@ , "%(code)s" , '' , "#endif//__%(file_name)s_hpp__pyplusplus_wrapper__" ]) - + content = '' if self.extmodule.license: content = self.extmodule.license.create() + os.linesep @@ -117,19 +122,19 @@ includes = filter( lambda creator: isinstance( creator, code_creators.include_t ) , self.extmodule.creators ) answer.extend( map( lambda creator: creator.create(), includes ) ) - + for creator in creators: header = self.find_out_value_traits_header( creator ) if header: answer.append( '#include "%s"' % header ) - + if tail_headers: answer.extend( map( lambda header: '#include "%s"' % normalize( header ) , tail_headers ) ) - + return os.linesep.join( answer ) - - def create_namespaces_code( self, creators ): + + def create_namespaces_code( self, creators ): # Write all 'global' namespace_alias_t and namespace_using_t creators first... ns_types = ( code_creators.namespace_alias_t, code_creators.namespace_using_t ) ns_creators = filter( lambda x: isinstance( x, ns_types ), self.extmodule.creators ) @@ -152,15 +157,15 @@ @returns: The content for a cpp file @rtype: str """ - + if None is declaration_creators: declaration_creators = [] creators = registration_creators + declaration_creators - + answer = [] if self.extmodule.license: answer.append( self.extmodule.license.create() ) - + head_headers = [ file_name + self.HEADER_EXT ] answer.append( self.create_include_code( creators, head_headers ) ) @@ -182,7 +187,7 @@ answer.append( '' ) answer.append( '}' ) return os.linesep.join( answer ) - + def split_class_impl( self, class_creator): function_name = 'register_%s_class' % class_creator.alias file_path = os.path.join( self.directory_path, class_creator.alias ) @@ -198,7 +203,7 @@ if class_creator.wrapper: class_wrapper = class_creator.wrapper decl_creators.append( class_creator.wrapper ) - + # Write the .cpp file... cpp_code = self.create_source( class_creator.alias , function_name @@ -239,7 +244,7 @@ Write the value_traits class to header file, that will be included from files, that uses indexing suite 2 """ - header_name = self.create_value_traits_header_name( value_traits.declaration ) + header_name = self.create_value_traits_header_name( value_traits.declaration ) file_path = os.path.join( self.directory_path, header_name ) self.write_file( file_path , self.create_header( header_name.replace( '.', '_' ) @@ -271,10 +276,10 @@ , creators )) for creator in creators: creator.create = lambda: '' - self.extmodule.body.adopt_creator( + self.extmodule.body.adopt_creator( code_creators.custom_text_t( function_name + '();' ) , registrator_pos) - self.include_creators.append( code_creators.include_t( header_name ) ) + self.include_creators.append( code_creators.include_t( header_name ) ) self.split_header_names.append(header_name) self.split_method_names.append(function_name) @@ -320,20 +325,20 @@ value_traits_classes = filter( lambda x: isinstance(x, code_creators.value_traits_t ) , self.extmodule.creators ) map( self.split_value_traits, value_traits_classes ) - + # Obtain a list of all class creators... class_creators = filter( lambda x: isinstance(x, ( code_creators.class_t, code_creators.class_declaration_t ) ) , self.extmodule.body.creators ) # ...and write a .h/.cpp file for each class map( self.split_class, class_creators ) - + self.split_enums() self.split_global_variables() self.split_free_functions() - + if self.write_main: self.include_creators.sort( cmp=lambda ic1, ic2: cmp( ic1.header, ic2.header ) ) map( lambda creator: self.extmodule.adopt_include( creator ) , self.include_creators ) main_cpp = os.path.join( self.directory_path, self.extmodule.body.name + '.main.cpp' ) - self.write_file( main_cpp, self.extmodule.create() + os.linesep ) \ No newline at end of file + self.write_file( main_cpp, self.extmodule.create() + os.linesep ) Modified: pyplusplus_dev/pyplusplus/module_builder/builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-09-01 14:32:52 UTC (rev 505) +++ pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-09-03 07:59:17 UTC (rev 506) @@ -292,7 +292,7 @@ self.__merge_user_code() file_writers.write_file( self.code_creator, file_name ) - def split_module(self, dir_name, huge_classes=None): + def split_module(self, dir_name, huge_classes=None, on_unused_file_found=os.remove): """ Writes module to multiple files @@ -300,13 +300,34 @@ @type dir_name: string @param huge_classes: list that contains reference to classes, that should be split + + @param on_unused_file_found: callable object that represents the action that should be taken on + file, which is no more in use """ self.__merge_user_code() + written_files = [] if None is huge_classes: - file_writers.write_multiple_files( self.code_creator, dir_name ) + written_files = file_writers.write_multiple_files( self.code_creator, dir_name ) else: - file_writers.write_class_multiple_files( self.code_creator, dir_name, huge_classes ) + written_files = file_writers.write_class_multiple_files( self.code_creator, dir_name, huge_classes ) + all_files = os.listdir( dir_name ) + all_files = map( lambda fname: os.path.join( dir_name, fname ), all_files ) + all_files = filter( lambda fname: os.path.isfile( fname ) \ + and os.path.splitext( fname )[1] in ( '.cpp', '.hpp' ) + , all_files ) + + unused_files = set( all_files ).difference( set( written_files ) ) + for fpath in unused_files: + try: + if on_unused_file_found is os.remove: + self.logger.info( 'removing file "%s"' % fpath ) + on_unused_file_found( fpath ) + except Exception, error: + self.logger.exception( "Exception was catched, while executing 'on_unused_file_found' function." ) + + return written_files + #select decl(s) interfaces def decl( self, name=None, function=None, header_dir=None, header_file=None, recursive=None ): """Please see L{decl_wrappers.scopedef_t} class documentation""" @@ -561,4 +582,4 @@ return decl_wrappers.calldef_t.BOOST_PYTHON_MAX_ARITY def _set_BOOST_PYTHON_MAX_ARITY( self, value ): decl_wrappers.calldef_t.BOOST_PYTHON_MAX_ARITY = value - BOOST_PYTHON_MAX_ARITY = property( _get_BOOST_PYTHON_MAX_ARITY, _set_BOOST_PYTHON_MAX_ARITY ) \ No newline at end of file + BOOST_PYTHON_MAX_ARITY = property( _get_BOOST_PYTHON_MAX_ARITY, _set_BOOST_PYTHON_MAX_ARITY ) Modified: pyplusplus_dev/unittests/algorithms_tester.py =================================================================== --- pyplusplus_dev/unittests/algorithms_tester.py 2006-09-01 14:32:52 UTC (rev 505) +++ pyplusplus_dev/unittests/algorithms_tester.py 2006-09-03 07:59:17 UTC (rev 506) @@ -9,7 +9,7 @@ import autoconfig from pygccxml import parser from pygccxml import declarations -from pyplusplus import code_creators +from pyplusplus import code_creators from pyplusplus import module_creator from pyplusplus import module_builder from pyplusplus import utils as pypp_utils @@ -21,7 +21,7 @@ class make_flatten_tester_t(unittest.TestCase): def test(self): - mb = module_builder.module_builder_t( + mb = module_builder.module_builder_t( [ module_builder.create_text_fc( 'namespace enums{ enum { OK=1 }; }' ) ] , gccxml_path=autoconfig.gccxml.executable ) mb.namespace( name='::enums' ).include() @@ -31,24 +31,24 @@ class creator_finder_tester_t( unittest.TestCase ): def test_find_by_declaration(self): - mb = module_builder.module_builder_t( + mb = module_builder.module_builder_t( [ module_builder.create_text_fc( 'namespace enums{ enum color{ red = 1}; }' )] , gccxml_path=autoconfig.gccxml.executable ) mb.namespace( name='::enums' ).include() - enum_matcher = declarations.match_declaration_t( name='color' ) + enum_matcher = declarations.match_declaration_t( name='color' ) mb.build_code_creator( 'dummy' ) - enum_found = code_creators.creator_finder.find_by_declaration( + enum_found = code_creators.creator_finder.find_by_declaration( enum_matcher , mb.code_creator.creators ) self.failUnless( enum_found ) def test_find_by_class_instance(self): - mb = module_builder.module_builder_t( + mb = module_builder.module_builder_t( [ module_builder.create_text_fc( 'namespace enums{ enum color{ red = 1}; }' )] , gccxml_path=autoconfig.gccxml.executable ) mb.namespace( name='::enums' ).include() mb.build_code_creator('dummy') - enum_found = code_creators.creator_finder.find_by_class_instance( + enum_found = code_creators.creator_finder.find_by_class_instance( code_creators.enum_t , mb.code_creator.creators , recursive=True) @@ -64,14 +64,14 @@ answer.append( base.related_class ) answer.extend( self._findout_base_classes( base.related_class ) ) return answer - + def test(self): config = parser.config_t( gccxml_path=autoconfig.gccxml.executable ) code = [] code.append('struct a{};') code.append('struct b{};') code.append('struct c{};') - code.append('struct d : public a{};') + code.append('struct d : public a{};') code.append('struct e : public a, public b{};') code.append('struct f{};') code.append('struct g : public d, public f{};') @@ -92,7 +92,7 @@ class exclude_function_with_array_arg_tester_t( unittest.TestCase ): def test(self): - mb = module_builder.module_builder_t( + mb = module_builder.module_builder_t( [ module_builder.create_text_fc( 'namespace arr{ struct x{ x( int arr[3][3], int ){} x( const x arr[3][3], int ){} }; }' )] , gccxml_path=autoconfig.gccxml.executable ) arr = mb.namespace( name='arr' ) @@ -103,8 +103,8 @@ class readme_tester_t( unittest.TestCase ): CODE = \ """ - namespace xxx{ - int do_smth(int); + namespace xxx{ + int do_smth(int); typedef int Int; struct data_t{ data_t& operator--(int a); @@ -112,7 +112,7 @@ } """ def test(self): - mb = module_builder.module_builder_t( + mb = module_builder.module_builder_t( [ module_builder.create_text_fc( self.CODE )] , gccxml_path=autoconfig.gccxml.executable ) xxx = mb.namespace( name='xxx' ) @@ -128,27 +128,29 @@ struct X{ enum EColor{ red, blue }; enum EFruit{ apple, orange }; - + X(){} X( int ){} - + void do_nothing(){} - + int do_somghing(){ return 1; } - - int m_dummy; + + int m_dummy; }; } """ def test(self): - mb = module_builder.module_builder_t( + mb = module_builder.module_builder_t( [ module_builder.create_text_fc( self.CLASS_DEF ) ] , gccxml_path=autoconfig.gccxml.executable ) mb.namespace( name='::tester' ).include() X = mb.class_( 'X' ) X.add_declaration_code( '//hello world' ) mb.build_code_creator('dummy') - mb.split_module( autoconfig.build_dir, [ mb.class_( '::tester::X' ) ] ) + mb.split_module( autoconfig.build_dir + , [ mb.class_( '::tester::X' ) ] + , on_unused_file_found=lambda fpath: fpath ) class split_sequence_tester_t(unittest.TestCase): @@ -161,7 +163,7 @@ self.failUnless( [[1,2,3]] == split( seq, 4 ) ) def create_suite(): - suite = unittest.TestSuite() + suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(class_organizer_tester_t)) suite.addTest( unittest.makeSuite(indent_tester_t)) suite.addTest( unittest.makeSuite(make_flatten_tester_t)) @@ -170,12 +172,12 @@ suite.addTest( unittest.makeSuite(class_multiple_files_tester_t)) suite.addTest( unittest.makeSuite(readme_tester_t)) suite.addTest( unittest.makeSuite(split_sequence_tester_t)) - - + + return suite def run_suite(): unittest.TextTestRunner(verbosity=2).run( create_suite() ) if __name__ == "__main__": - run_suite() \ No newline at end of file + run_suite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |