[pygccxml-commit] SF.net SVN: pygccxml: [345] pygccxml_dev/pygccxml/utils
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-07-25 06:25:46
|
Revision: 345 Author: roman_yakovenko Date: 2006-07-24 23:25:20 -0700 (Mon, 24 Jul 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=345&view=rev Log Message: ----------- 1. renaming multilineformatter.py to multi_line_formatter.py 2. removing os.linesep from messages 3. changing a little bit a way multi_line_formatter_t works Modified Paths: -------------- pygccxml_dev/pygccxml/utils/__init__.py pyplusplus_dev/pyplusplus/_logging_/__init__.py pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py pyplusplus_dev/pyplusplus/module_builder/builder.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/pyplusplus/module_creator/types_database.py Added Paths: ----------- pyplusplus_dev/pyplusplus/_logging_/multi_line_formatter.py Removed Paths: ------------- pyplusplus_dev/pyplusplus/_logging_/multilineformatter.py Modified: pygccxml_dev/pygccxml/utils/__init__.py =================================================================== --- pygccxml_dev/pygccxml/utils/__init__.py 2006-07-24 20:26:03 UTC (rev 344) +++ pygccxml_dev/pygccxml/utils/__init__.py 2006-07-25 06:25:20 UTC (rev 345) @@ -10,9 +10,9 @@ def _create_logger_( name ): logger = logging.getLogger(name) - __handler = logging.StreamHandler(sys.stdout) - __handler.setFormatter( logging.Formatter( os.linesep + '%(levelname)s %(message)s' ) ) - logger.addHandler(__handler) + handler = logging.StreamHandler(sys.stdout) + handler.setFormatter( logging.Formatter( os.linesep + '%(levelname)s %(message)s' ) ) + logger.addHandler(handler) logger.setLevel(logging.INFO) return logger Modified: pyplusplus_dev/pyplusplus/_logging_/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/_logging_/__init__.py 2006-07-24 20:26:03 UTC (rev 344) +++ pyplusplus_dev/pyplusplus/_logging_/__init__.py 2006-07-25 06:25:20 UTC (rev 345) @@ -12,13 +12,13 @@ import os import sys import logging -from multilineformatter import multi_line_formatter_t +from multi_line_formatter import multi_line_formatter_t def _create_logger_( name ): logger = logging.getLogger(name) - __handler = logging.StreamHandler(sys.stdout) - __handler.setFormatter( multi_line_formatter_t( os.linesep + '%(levelname)s: %(message)s' ) ) - logger.addHandler(__handler) + handler = logging.StreamHandler(sys.stdout) + handler.setFormatter( multi_line_formatter_t( os.linesep + '%(levelname)s: %(message)s' ) ) + logger.addHandler(handler) logger.setLevel(logging.INFO) return logger Copied: pyplusplus_dev/pyplusplus/_logging_/multi_line_formatter.py (from rev 344, pyplusplus_dev/pyplusplus/_logging_/multilineformatter.py) =================================================================== --- pyplusplus_dev/pyplusplus/_logging_/multi_line_formatter.py (rev 0) +++ pyplusplus_dev/pyplusplus/_logging_/multi_line_formatter.py 2006-07-25 06:25:20 UTC (rev 345) @@ -0,0 +1,85 @@ +# Copyright 2004 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# Initial version by Matthias Baas (ba...@ir...). + +import os, logging, textwrap + +class multi_line_formatter_t(logging.Formatter): + """Custom log formatter to split long message into several lines. + + This formatter is used for the default stream handler that outputs + its messages to stdout. + """ + + def __init__(self, fmt=None, datefmt=None, width=70): + """Constructor. + + See the Python standard library reference for a documentation + of fmt and datefmt. + width is the maximum width of the generated text blocks. + """ + logging.Formatter.__init__(self, fmt, datefmt) + self._width = width + + def format(self, record): + """This method overwrites the original one. + + The first thing that is done in the original format() method + is the creation of the record.message attribute: + + record.message = record.getMessage() + + Now this method temporarily replaces the getMessage() method of + the record by a version that returns a pregenerated message that + spans several lines. Then the original format() method is called + which will invoke the 'fake' method. + """ + # Get the original single-line message + message = record.getMessage() + # Distribute the message among several lines... + message = self.formatMessage(message, width=self._width) + # ...and temporarily replace the getMessage() method so that the + # reformatted message is used + mth = record.getMessage + record.getMessage = lambda x=message: x + # Invoke the inherited format() method + res = logging.Formatter.format(self, record) + # Restore the original method + record.getMessage = mth + return res + + @staticmethod + def formatMessage(msgline, width=70): + """Format a long single line message so that it is easier to read. + + msgline is a string containing a single message. It can either be + a plain message string which is reformatted using the textwrap + module or it can be of the form <decl>;<msg> where <decl> is the + declaration string and <msg> an arbitrary message. Lines of this + form will be separated so that the declaration and the message + appear in individual text blocks separated by the string '->'. + + In any case the return string will be indented except for the first + line. + + width is the maximum width of any text blocks (without indendation). + """ + txts = msgline.split(";") + # Ensure that there are no more than two items in txts + if len( txts ) != 2: + #If message is not in format we expected, just return it + return os.linesep.join( textwrap.wrap( msgline, width ) ) + + lines = [ txts[0] ] #I don't want to break declaration string to few lines + + # Insert a separator if there are two parts (=decl and msg) + # Apply the text wrapper to shorten the maximum line length + wrapped_lines = textwrap.wrap( txts[1], width ) + lines.extend( map( lambda s: "> " + s.strip(), wrapped_lines ) ) + + return os.linesep.join(lines) + + Deleted: pyplusplus_dev/pyplusplus/_logging_/multilineformatter.py =================================================================== --- pyplusplus_dev/pyplusplus/_logging_/multilineformatter.py 2006-07-24 20:26:03 UTC (rev 344) +++ pyplusplus_dev/pyplusplus/_logging_/multilineformatter.py 2006-07-25 06:25:20 UTC (rev 345) @@ -1,89 +0,0 @@ -# Copyright 2004 Roman Yakovenko. -# Distributed under the Boost Software License, Version 1.0. (See -# accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -# Initial version by Matthias Baas (ba...@ir...). - -import os, logging, textwrap - -class multi_line_formatter_t(logging.Formatter): - """Custom log formatter to split long message into several lines. - - This formatter is used for the default stream handler that outputs - its messages to stdout. - """ - - def __init__(self, fmt=None, datefmt=None, width=70): - """Constructor. - - See the Python standard library reference for a documentation - of fmt and datefmt. - width is the maximum width of the generated text blocks. - """ - logging.Formatter.__init__(self, fmt, datefmt) - self._width = width - - def format(self, record): - """This method overwrites the original one. - - The first thing that is done in the original format() method - is the creation of the record.message attribute: - - record.message = record.getMessage() - - Now this method temporarily replaces the getMessage() method of - the record by a version that returns a pregenerated message that - spans several lines. Then the original format() method is called - which will invoke the 'fake' method. - """ - # Get the original single-line message - message = record.getMessage() - # Distribute the message among several lines... - message = self.formatMessage(message, width=self._width) - # ...and temporarily replace the getMessage() method so that the - # reformatted message is used - mth = record.getMessage - record.getMessage = lambda x=message: x - # Invoke the inherited format() method - res = logging.Formatter.format(self, record) - # Restore the original method - record.getMessage = mth - return res - - @staticmethod - def formatMessage(msgline, width=70): - """Format a long single line message so that it is easier to read. - - msgline is a string containing a single message. It can either be - a plain message string which is reformatted using the textwrap - module or it can be of the form <decl>;<msg> where <decl> is the - declaration string and <msg> an arbitrary message. Lines of this - form will be separated so that the declaration and the message - appear in individual text blocks separated by the string '->'. - - In any case the return string will be indented except for the first - line. - - width is the maximum width of any text blocks (without indendation). - """ - txts = msgline.split(";") - # Ensure that there are no more than two items in txts - if len(txts)>2: - txts = [txts[0], ";".join(txts[1:])] - - # Insert a separator if there are two parts (=decl and msg) - if len(txts)==2: - txts.insert(1, "->") - - # Apply the text wrapper to shorten the maximum line length - lines = [] - for txt in txts: - txt = txt.strip().replace(os.linesep, " ") - lines.extend(textwrap.wrap(txt, width)) - - # Indent the text (except for the first line) - lines[1:] = map(lambda s: (2*" ")+s, lines[1:]) - return os.linesep.join(lines) - - Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-07-24 20:26:03 UTC (rev 344) +++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-07-25 06:25:20 UTC (rev 345) @@ -6,12 +6,6 @@ import os import decl_wrapper from pygccxml import declarations -##May be in future I will enable this functionality again, right now it seems -##that this is useless -##def is_finalizable(self): - ##if not self.wrapper: - ##return False - ##return self.declaration.virtuality != declarations.VIRTUALITY_TYPES.PURE_VIRTUAL class calldef_t(decl_wrapper.decl_wrapper_t): @@ -131,20 +125,20 @@ #TODO: functions that takes as argument pointer to pointer to smth, could not be exported #see http://www.boost.org/libs/python/doc/v2/faq.html#funcptr if len( self.arguments ) > calldef_t.BOOST_PYTHON_MAX_ARITY: - tmp = [ "Function '%s' has more than %d arguments ( %d ). " ] - tmp.append( os.linesep + "\tYou should adjust BOOST_PYTHON_MAX_ARITY." ) - tmp.append( os.linesep + "\tFor more information see: http://mail.python.org/pipermail/c++-sig/2002-June/001554.html" ) - tmp = ''.join( tmp ) - msgs.append( tmp % ( self.decl_string, calldef_t.BOOST_PYTHON_MAX_ARITY, len( self.arguments ) ) ) + tmp = [ "The function has more than %d arguments ( %d ). " ] + tmp.append( "You should adjust BOOST_PYTHON_MAX_ARITY macro." ) + tmp.append( "For more information see: http://mail.python.org/pipermail/c++-sig/2002-June/001554.html" ) + tmp = ' '.join( tmp ) + msgs.append( tmp % ( calldef_t.BOOST_PYTHON_MAX_ARITY, len( self.arguments ) ) ) if suspicious_type( self.return_type ) and None is self.call_policies: - msgs.append( 'Function "%s" returns non-const reference to C++ fundamental type - value can not be modified from Python.' % str( self ) ) + msgs.append( 'The function "%s" returns non-const reference to C++ fundamental type - value can not be modified from Python.' % str( self ) ) for index, arg in enumerate( self.arguments ): if suspicious_type( arg.type ): - tmpl = 'Function "%s" takes as argument (name=%s, pos=%d ) ' \ - + 'non-const reference to C++ fundamental type - ' \ - + 'function could not be called from Python.' - msgs.append( tmpl % ( str( self ), arg.name, index ) ) + tmpl = [ 'The function takes as argument (name=%s, pos=%d ) ' ] + tmpl.append( 'non-const reference to C++ fundamental type - ' ) + tmpl.append( 'function could not be called from Python.' ) + msgs.append( ''.join( tmpl ) % ( arg.name, index ) ) if False == self.overridable: msgs.append( self.get_overridable.__doc__ ) @@ -200,7 +194,7 @@ if not operators_helper.is_supported( oper ): msg = [ '"operator%s" is not supported. ' % oper.symbol ] msg.append( 'See Boost.Python documentation: http://www.boost.org/libs/python/doc/v2/operators.html#introduction.' ) - return os.linesep.join( msg ) + return ' '.join( msg ) return '' exportable = staticmethod( exportable ) Modified: pyplusplus_dev/pyplusplus/module_builder/builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-07-24 20:26:03 UTC (rev 344) +++ pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-07-25 06:25:20 UTC (rev 345) @@ -110,7 +110,7 @@ decls = reader.read_files( files, compilation_mode ) self.logger.debug( 'parsing files - done( %f seconds )' % ( time.clock() - start_time ) ) - self.logger.debug( 'settings declarations defaults- started' ) + self.logger.debug( 'settings declarations defaults - started' ) global_ns = decls_package.matcher.get_single( decls_package.namespace_matcher_t( name='::' ) Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-07-24 20:26:03 UTC (rev 344) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-07-25 06:25:20 UTC (rev 345) @@ -151,12 +151,10 @@ if reason in DO_NOT_REPORT_MSGS: continue readme = readme[1:] - msgstr = "%s;%s"%(decl, reason.replace(os.linesep, " ")) - self.decl_logger.warn( msgstr ) + self.decl_logger.warn( "%s;%s" % ( decl, reason ) ) for msg in readme: - msgstr = "%s;%s"%(decl, msg.replace(os.linesep, " ")) - self.decl_logger.warn( msgstr ) + self.decl_logger.warn( "%s;%s" % ( decl, msg ) ) #leave only declarations defined under namespace, but remove namespaces decls = filter( lambda x: not isinstance( x, declarations.namespace_t ) \ Modified: pyplusplus_dev/pyplusplus/module_creator/types_database.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/types_database.py 2006-07-24 20:26:03 UTC (rev 344) +++ pyplusplus_dev/pyplusplus/module_creator/types_database.py 2006-07-25 06:25:20 UTC (rev 345) @@ -72,13 +72,14 @@ try: check_extraction = container_cls.indexing_suite.element_type - except RuntimeError, error: - msg = [] - msg.append( 'pyplusplus found template class instantiation "%s" declaration ( not definition ). ' % container_cls.name ) - msg.append( '\tpyplusplus can not find out container value_type( mapped_type )!' ) - msg.append( '\tThis class will be exported, but there is a posiblity, that generated code will not compile.' ) - msg.append( '\tThe solution to the problem is to create a variable of the class.' ) - _logging_.loggers.declarations.warn( os.linesep.join( msg ) ) + except RuntimeError, error: + msg = "%s;%s" \ + % ( str(container_cls) + , "pyplusplus can not find out container value_type( mapped_type )." + "The container class is template instantiation declaration and not definition." + "This container class will be exported, but there is a posiblity, that generated code will not compile." + "The solution to the problem is to create a variable of the class." ) + _logging_.loggers.declarations.warn( msg ) self.__containers.add( container_cls ) return True This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |