[pygccxml-commit] SF.net SVN: pygccxml: [289] pygccxml_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-07-10 12:33:57
|
Revision: 289 Author: roman_yakovenko Date: 2006-07-10 05:33:25 -0700 (Mon, 10 Jul 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=289&view=rev Log Message: ----------- adding different loggers for different functionality removing verbose flag Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/scopedef.py pygccxml_dev/pygccxml/parser/config.py pygccxml_dev/pygccxml/parser/declarations_cache.py pygccxml_dev/pygccxml/parser/project_reader.py pygccxml_dev/pygccxml/parser/scanner.py pygccxml_dev/pygccxml/parser/source_reader.py pygccxml_dev/pygccxml/utils/__init__.py pygccxml_dev/unittests/declarations_cache_tester.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/pyplusplus/module_builder/__init__.py pyplusplus_dev/pyplusplus/module_builder/builder.py Modified: pygccxml_dev/pygccxml/declarations/scopedef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/scopedef.py 2006-07-09 19:53:40 UTC (rev 288) +++ pygccxml_dev/pygccxml/declarations/scopedef.py 2006-07-10 12:33:25 UTC (rev 289) @@ -75,7 +75,11 @@ self._type2decls_nr = {} self._type2name2decls_nr = {} self._all_decls = None - + + def _get_logger( self ): + return utils.loggers.queries_engine + _logger = property( _get_logger ) + def _get__cmp__scope_items(self): raise NotImplementedError() @@ -148,7 +152,7 @@ Those hashtables allows to search declaration very quick. """ if self.name == '::': - utils.logger.debug( "preparing data structures for query optimizer - started" ) + self._logger.debug( "preparing data structures for query optimizer - started" ) start_time = time.clock() self.clear_optimizer() @@ -178,7 +182,7 @@ map( lambda decl: decl.init_optimizer() , filter( lambda decl: isinstance( decl, scopedef_t ), self.declarations ) ) if self.name == '::': - utils.logger.debug( "preparing data structures for query optimizer - done( %f seconds ). " + self._logger.debug( "preparing data structures for query optimizer - done( %f seconds ). " % ( time.clock() - start_time ) ) self._optimized = True @@ -226,15 +230,15 @@ matcher = match_class( **matcher_args ) if keywds['function']: - utils.logger.debug( 'running query: %s and <user defined function>' % str( matcher ) ) + self._logger.debug( 'running query: %s and <user defined function>' % str( matcher ) ) return lambda decl: matcher( decl ) and keywds['function'](decl) else: - utils.logger.debug( 'running query: %s' % str( matcher ) ) + self._logger.debug( 'running query: %s' % str( matcher ) ) return matcher def __findout_range( self, name, decl_type, recursive ): if not self._optimized: - utils.logger.debug( 'running non optimized query - optimization has not been done' ) + self._logger.debug( 'running non optimized query - optimization has not been done' ) decls = self.declarations if recursive: decls = algorithm.make_flatten( self.declarations ) @@ -245,34 +249,34 @@ if matcher.is_full_name(): name = matcher.decl_name_only if recursive: - utils.logger.debug( 'query has been optimized on type and name' ) + self._logger.debug( 'query has been optimized on type and name' ) if self._type2name2decls[decl_type].has_key( name ): return self._type2name2decls[decl_type][name] else: return [] else: - utils.logger.debug( 'non recursive query has been optimized on type and name' ) + self._logger.debug( 'non recursive query has been optimized on type and name' ) if self._type2name2decls_nr[decl_type].has_key( name ): return self._type2name2decls_nr[decl_type][name] else: return [] elif decl_type: if recursive: - utils.logger.debug( 'query has been optimized on type' ) + self._logger.debug( 'query has been optimized on type' ) return self._type2decls[ decl_type ] else: - utils.logger.debug( 'non recursive query has been optimized on type' ) + self._logger.debug( 'non recursive query has been optimized on type' ) return self._type2decls_nr[ decl_type ] else: if recursive: - utils.logger.debug( 'query has not been optimized ( hint: query does not contain type and/or name )' ) + self._logger.debug( 'query has not been optimized ( hint: query does not contain type and/or name )' ) return self._all_decls else: - utils.logger.debug( 'non recursive query has not been optimized ( hint: query does not contain type and/or name )' ) + self._logger.debug( 'non recursive query has not been optimized ( hint: query does not contain type and/or name )' ) return self.declarations def _find_single( self, match_class, **keywds ): - utils.logger.debug( 'find single query execution - started' ) + self._logger.debug( 'find single query execution - started' ) start_time = time.clock() norm_keywds = self.__normalize_args( **keywds ) matcher = self.__create_matcher( match_class, **norm_keywds ) @@ -280,11 +284,11 @@ recursive_ = self.__findout_recursive( **norm_keywds ) decls = self.__findout_range( norm_keywds['name'], dtype, recursive_ ) found = matcher_module.matcher.get_single( matcher, decls, False ) - utils.logger.debug( 'find single query execution - done( %f seconds )' % ( time.clock() - start_time ) ) + self._logger.debug( 'find single query execution - done( %f seconds )' % ( time.clock() - start_time ) ) return found def _find_multiple( self, match_class, **keywds ): - utils.logger.debug( 'find all query execution - started' ) + self._logger.debug( 'find all query execution - started' ) start_time = time.clock() norm_keywds = self.__normalize_args( **keywds ) matcher = self.__create_matcher( match_class, **norm_keywds ) @@ -294,8 +298,8 @@ decls = self.__findout_range( norm_keywds['name'], dtype, recursive_ ) found = matcher_module.matcher.find( matcher, decls, False ) mfound = mdecl_wrapper.mdecl_wrapper_t( found ) - utils.logger.debug( '%d declaration(s) that match query' % len(mfound) ) - utils.logger.debug( 'find single query execution - done( %f seconds )' + self._logger.debug( '%d declaration(s) that match query' % len(mfound) ) + self._logger.debug( 'find single query execution - done( %f seconds )' % ( time.clock() - start_time ) ) if not mfound and not allow_empty: raise RuntimeError( "Multi declaration query returned 0 declarations." ) Modified: pygccxml_dev/pygccxml/parser/config.py =================================================================== --- pygccxml_dev/pygccxml/parser/config.py 2006-07-09 19:53:40 UTC (rev 288) +++ pygccxml_dev/pygccxml/parser/config.py 2006-07-10 12:33:25 UTC (rev 289) @@ -27,7 +27,6 @@ , define_symbols=None , undefine_symbols=None , start_with_declarations=None - , verbose=False , ignore_gccxml_output=False , cflags=""): """Constructor. @@ -52,7 +51,6 @@ start_with_declarations = [] self.__start_with_declarations = start_with_declarations - self.__verbose = verbose self.__ignore_gccxml_output = ignore_gccxml_output self.__cflags = cflags @@ -63,7 +61,6 @@ , define_symbols=self.__define_symbols[:] , undefine_symbols=self.__undefine_symbols[:] , start_with_declarations=self.__start_with_declarations[:] - , verbose=self.verbose , ignore_gccxml_output=self.ignore_gccxml_output , cflags=self.cflags) @@ -95,12 +92,6 @@ return self.__start_with_declarations start_with_declarations = property( __get_start_with_declarations ) - def __get_verbose(self): - return self.__verbose - def __set_verbose(self, val=True): - self.__verbose = val - verbose = property( __get_verbose, __set_verbose ) - def __get_ignore_gccxml_output(self): return self.__ignore_gccxml_output def __set_ignore_gccxml_output(self, val=True): Modified: pygccxml_dev/pygccxml/parser/declarations_cache.py =================================================================== --- pygccxml_dev/pygccxml/parser/declarations_cache.py 2006-07-09 19:53:40 UTC (rev 288) +++ pygccxml_dev/pygccxml/parser/declarations_cache.py 2006-07-10 12:33:25 UTC (rev 289) @@ -8,7 +8,7 @@ import md5 import time import cPickle -from pygccxml.utils import logger +from pygccxml import utils def file_signature( filename ): @@ -44,9 +44,11 @@ sig.update(str(u)) return sig.hexdigest() -class cache_base_t( object ): +class cache_base_t( object ): + logger = utils.loggers.declarations_cache + def __init__( self ): - object.__init__(self) + object.__init__(self) def flush(self): """ Flush (write out) the cache to disk if needed. """ @@ -146,7 +148,7 @@ """ @param name: name of the cache file. """ - cache_base_t.__init__( self ) + cache_base_t.__init__( self ) self.__name = name # Name of cache file self.__cache = self.__load( self.__name ) # Map record_key to record_t self.__needs_flushed = not bool( self.__cache ) # If empty then we need to flush @@ -163,15 +165,16 @@ return {} cache_file_obj = file( file_name, 'rb' ) try: - logger.info( "Loading cache file ..." ) + file_cache_t.logger.info( 'Loading cache file "%s".' % file_name ) start_time = time.clock() cache = cPickle.load( cache_file_obj ) - logger.info( "Cache file has been loaded in %.1f secs"%( time.clock() - start_time ) ) - logger.info( "Found cache in file: [%s] entries: %s" - % ( file_name, len( cache.keys() ) ) ) - except Exception: + file_cache_t.logger.debug( "Cache file has been loaded in %.1f secs"%( time.clock() - start_time ) ) + file_cache_t.logger.debug( "Found cache in file: [%s] entries: %s" + % ( file_name, len( cache.keys() ) ) ) + except Exception, error: + file_cache_t.logger.exception( "Error occured while reading cache file: %s", error ) cache_file_obj.close() - logger.info( "Invalid cache file: [%s] Regenerating." % file_name ) + file_cache_t.logger.info( "Invalid cache file: [%s] Regenerating." % file_name ) file(file_name, 'w+b').close() # Create empty file cache = {} # Empty cache return cache @@ -180,7 +183,7 @@ def flush(self): # If not marked as needing flushed, then return immediately if not self.__needs_flushed: - logger.info("Cache did not change, ignoring flush.") + self.logger.debug("Cache did not change, ignoring flush.") return # Remove entries that did not get a cache hit @@ -190,7 +193,7 @@ num_removed += 1 del self.__cache[key] if num_removed > 0: - logger.info( "There are %s removed entries from cache." % num_removed ) + self.logger.debug( "There are %s removed entries from cache." % num_removed ) # Save out the cache to disk cache_file = file( self.__name, 'w+b' ) cPickle.dump( self.__cache, cache_file, cPickle.HIGHEST_PROTOCOL ) Modified: pygccxml_dev/pygccxml/parser/project_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/project_reader.py 2006-07-09 19:53:40 UTC (rev 288) +++ pygccxml_dev/pygccxml/parser/project_reader.py 2006-07-10 12:33:25 UTC (rev 289) @@ -9,7 +9,7 @@ import source_reader import declarations_cache import pygccxml.declarations -from pygccxml.utils import logger +from pygccxml import utils class COMPILATION_MODE: ALL_AT_ONCE = 'all at once' @@ -179,7 +179,9 @@ self.__decl_factory = decl_factory if not decl_factory: self.__decl_factory = pygccxml.declarations.decl_factory_t() - + + self.logger = utils.loggers.gccxml + def get_os_file_names( files ): """Returns a list of OS file names @@ -219,14 +221,13 @@ "Unable to parse files using ALL_AT_ONCE mode. " , "There is some file configuration that is not file. " , "pygccxml.parser.project_reader_t switches to FILE_BY_FILE mode." ]) - logger.info( msg ) + self.logger.warning( msg ) return self.__parse_file_by_file(files) def __parse_file_by_file(self, files): namespaces = [] config = self.__config.clone() - if config.verbose: - logger.info( "Reading project files: file by file" ) + self.logger.debug( "Reading project files: file by file" ) for prj_file in files: reader = None header = None @@ -259,35 +260,28 @@ else: decls = reader.read_string( header ) namespaces.append( decls ) - if config.verbose: - logger.info( "Flushing cache... " ) + self.logger.debug( "Flushing cache... " ) start_time = time.clock() self.__dcache.flush() - if config.verbose: - logger.info( "Cache has been flushed in %.1f secs" - % ( time.clock() - start_time ) ) + self.logger.debug( "Cache has been flushed in %.1f secs" % ( time.clock() - start_time ) ) answer = [] - if config.verbose: - logger.info( "Joining namespaces ..." ) + self.logger.debug( "Joining namespaces ..." ) for file_nss in namespaces: answer = self._join_top_namespaces( answer, file_nss ) - if config.verbose: - logger.info( "Joining declarations ..." ) + self.logger.debug( "Joining declarations ..." ) for ns in answer: if isinstance( ns, pygccxml.declarations.namespace_t ): self._join_declarations( ns ) leaved_classes = self._join_class_hierarchy( answer ) types = self.__declarated_types(answer) - if config.verbose: - logger.info( "Relinking declared types ..." ) + self.logger.debug( "Relinking declared types ..." ) self._relink_declarated_types( leaved_classes, types ) source_reader.bind_aliases( pygccxml.declarations.make_flatten( answer ) ) return answer def __parse_all_at_once(self, files): config = self.__config.clone() - if config.verbose: - logger.info( "Reading project files: all at once" ) + self.logger.debug( "Reading project files: all at once" ) header_content = [] for header in files: if isinstance( header, file_configuration_t ): @@ -430,18 +424,16 @@ key = create_key(decl_wrapper_type.declaration) if leaved_classes.has_key( key ): decl_wrapper_type.declaration = leaved_classes[ create_key(decl_wrapper_type.declaration) ] - else: + else: + if decl_wrapper_type.declaration._name.startswith( '__vmi_class_type_info_pseudo' ): + continue msg = [] msg.append( "Unable to find out actual class definition: '%s'." % decl_wrapper_type.declaration._name ) msg.append( "Class definition has been changed from one compilation to an other." ) msg.append( "Why did it happen to me? Here is a short list of reasons: " ) msg.append( " 1. There are different preprocessor definitions applied on same file during compilation" ) - msg.append( " 2. GCC implementation details. Diamand class hierarchy will reproduce this behavior." ) - msg.append( " If name starts with '__vmi_class_type_info_pseudo' you can ignore this message." ) - msg.append( " 3. Bug in pygccxml." ) - logger.error( os.linesep.join(msg) ) - #'__vmi_class_type_info_pseudo1' - + msg.append( " 2. Bug in pygccxml." ) + self.logger.error( os.linesep.join(msg) ) def _join_declarations( self, declref ): self._join_namespaces( declref ) Modified: pygccxml_dev/pygccxml/parser/scanner.py =================================================================== --- pygccxml_dev/pygccxml/parser/scanner.py 2006-07-09 19:53:40 UTC (rev 288) +++ pygccxml_dev/pygccxml/parser/scanner.py 2006-07-10 12:33:25 UTC (rev 289) @@ -10,7 +10,7 @@ import warnings import xml.sax.handler from pygccxml.declarations import * -from pygccxml.utils import logger +from pygccxml import utils ##convention #XML_NN - XML Node Name @@ -75,7 +75,8 @@ class scanner_t( xml.sax.handler.ContentHandler ): def __init__(self, gccxml_file, decl_factory, *args ): - xml.sax.handler.ContentHandler.__init__(self, *args ) + xml.sax.handler.ContentHandler.__init__(self, *args ) + self.logger = utils.loggers.gccxml self.gccxml_file = gccxml_file #defining parsing tables self.__readers = { @@ -191,12 +192,12 @@ elif isinstance( obj, types.StringTypes ): self.__files[ attrs[XML_AN_ID] ] = obj else: - logger.warning( 'Unknown object type has been found.' - + ' Please report this bug to pygccxml development team.' ) + self.logger.warning( 'Unknown object type has been found.' + + ' Please report this bug to pygccxml development team.' ) except Exception, error: msg = 'error occured, while parsing element with name "%s" and attrs "%s".' msg = msg + os.linesep + 'Error: %s.' % str( error ) - logger.error( msg % ( name, pprint.pformat( attrs.keys() ) ) ) + self.logger.error( msg % ( name, pprint.pformat( attrs.keys() ) ) ) raise def endElement(self, name): Modified: pygccxml_dev/pygccxml/parser/source_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/source_reader.py 2006-07-09 19:53:40 UTC (rev 288) +++ pygccxml_dev/pygccxml/parser/source_reader.py 2006-07-10 12:33:25 UTC (rev 289) @@ -12,7 +12,7 @@ import declarations_cache import patcher from pygccxml.declarations import * -from pygccxml.utils import logger +from pygccxml import utils class gccxml_runtime_error_t( RuntimeError ): def __init__( self, msg ): @@ -72,7 +72,8 @@ @param decl_factory: declarations factory, if not given default declarations factory L{decl_factory_t} will be used - """ + """ + self.logger = utils.loggers.gccxml self.__search_directories = [] self.__config = config self.__search_directories.append( config.working_directory ) @@ -145,7 +146,7 @@ cmd_line = ' '.join(cmd) if 'win32' in sys.platform : cmd_line = '"%s"' % cmd_line - logger.debug( 'gccxml cmd: %s' % cmd_line ) + self.logger.info( 'gccxml cmd: %s' % cmd_line ) return cmd_line def create_xml_file( self, header, destination=None ): @@ -174,8 +175,6 @@ if not os.path.isabs( ffname ): ffname = self.__file_full_name(header) command_line = self.__create_command_line( ffname, gccxml_file ) - if self.__config.verbose: - logger.info( " Command line for GCC-XML: %s" % command_line ) input_, output = os.popen4( command_line ) input_.close() gccxml_reports = [] @@ -231,19 +230,15 @@ gccxml_file = '' try: ffname = self.__file_full_name(source_file) - if self.__config.verbose: - logger.info( "Reading source file: [%s]." % ffname ) + self.logger.debug( "Reading source file: [%s]." % ffname ) declarations = self.__dcache.cached_value( ffname, self.__config ) if not declarations: - if self.__config.verbose: - logger.info( "File has not been found in cache, parsing..." ) + self.logger.debug( "File has not been found in cache, parsing..." ) gccxml_file = self.create_xml_file( ffname ) declarations, files = self.__parse_gccxml_created_file( gccxml_file ) self.__dcache.update( ffname, self.__config, declarations, files ) else: - if self.__config.verbose: - logger.info( "File has not been changed, reading declarations from cache." ) - + self.logger.debug( "File has not been changed, reading declarations from cache." ) except Exception, error: if gccxml_file: pygccxml.utils.remove_file_no_raise( gccxml_file ) @@ -261,8 +256,7 @@ @return: declarations tree """ - if self.__config.verbose: - logger.info( "Reading xml file: [%s]" % gccxml_created_file ) + self.logger.debug( "Reading xml file: [%s]" % gccxml_created_file ) declarations, files = self.__parse_gccxml_created_file( gccxml_created_file ) return declarations Modified: pygccxml_dev/pygccxml/utils/__init__.py =================================================================== --- pygccxml_dev/pygccxml/utils/__init__.py 2006-07-09 19:53:40 UTC (rev 288) +++ pygccxml_dev/pygccxml/utils/__init__.py 2006-07-10 12:33:25 UTC (rev 289) @@ -7,14 +7,22 @@ import sys import logging import tempfile + +def _create_logger_( name ): + logger = logging.getLogger('name') + __handler = logging.StreamHandler(sys.stdout) + __handler.setFormatter( logging.Formatter( '%(levelname)s %(message)s' ) ) + logger.addHandler(__handler) + logger.setLevel(logging.INFO) + return logger + +class loggers: + root = _create_logger_( 'pygccxml' ) + gccxml = _create_logger_( 'pygccxml.gccxml' ) + queries_engine = _create_logger_( 'pygccxml.queries_engine' ) + declarations_cache = _create_logger_( 'pygccxml.declarations_cache' ) + all = [ root, gccxml, queries_engine, declarations_cache ] - -logger = logging.getLogger('pygccxml') -__handler = logging.StreamHandler(sys.stdout) -__handler.setFormatter( logging.Formatter('%(message)s') ) -logger.addHandler(__handler) -logger.setLevel(logging.DEBUG) - def remove_file_no_raise(file_name ): try: if os.path.exists(file_name): Modified: pygccxml_dev/unittests/declarations_cache_tester.py =================================================================== --- pygccxml_dev/unittests/declarations_cache_tester.py 2006-07-09 19:53:40 UTC (rev 288) +++ pygccxml_dev/unittests/declarations_cache_tester.py 2006-07-10 12:33:25 UTC (rev 289) @@ -41,11 +41,7 @@ #start_decls_changed = def_cfg.clone() #start_decls_changed.start_with_declarations = "test object" #self.assert_(configuration_signature(start_decls_changed) == def_sig) - - verbose_changed = def_cfg.clone() - verbose_changed.verbose = True - self.assert_(configuration_signature(verbose_changed) == def_sig) - + ignore_changed = def_cfg.clone() ignore_changed.ignore_gccxml_output = True self.assert_(configuration_signature(ignore_changed) == def_sig) @@ -101,7 +97,7 @@ """ Return a list of configurations that all differ. """ cfg_list = [] def_cfg = config_t("gccxml_path",'.',['tmp'],['sym'],['unsym'], - None,False,False,"") + None,False,"") cfg_list.append(def_cfg) # Test changes that should cause sig changes @@ -117,21 +113,21 @@ #inc_changed.include_paths = ["/var/tmp"] #self.assert_(configuration_signature(inc_changed) != def_sig) inc_changed = config_t("gccxml_path",'.',['/var/tmp'],['sym'],['unsym'], - None,False,False,"") + None,False,"") cfg_list.append(inc_changed) #def_changed = def_cfg.clone() #def_changed.define_symbols = ["symbol"] #self.assert_(configuration_signature(def_changed) != def_sig) def_changed = config_t("gccxml_path",'.',['/var/tmp'],['new-sym'],['unsym'], - None,False,False,"") + None,False,"") cfg_list.append(def_changed) #undef_changed = def_cfg.clone() #undef_changed.undefine_symbols = ["symbol"] #self.assert_(configuration_signature(undef_changed) != def_sig) undef_changed = config_t("gccxml_path",'.',['/var/tmp'],['sym'],['new-unsym'], - None,False,False,"") + None,False,"") cfg_list.append(undef_changed) cflags_changed = def_cfg.clone() Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-07-09 19:53:40 UTC (rev 288) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-07-10 12:33:25 UTC (rev 289) @@ -172,7 +172,8 @@ def _exportable_impl( self ): if not self.name: - return 'pyplusplus can not expose unnamed classes.' + return 'pyplusplus can not expose unnamed classes.' + #it is possible to do so, but not for unnamed classes defined under namespace. if isinstance( self.parent, declarations.namespace_t ): return '' if not self in self.parent.public_members: Modified: pyplusplus_dev/pyplusplus/module_builder/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/__init__.py 2006-07-09 19:53:40 UTC (rev 288) +++ pyplusplus_dev/pyplusplus/module_builder/__init__.py 2006-07-10 12:33:25 UTC (rev 289) @@ -50,6 +50,7 @@ from pygccxml import utils as __pygccxml_utils from pyplusplus import _logging_ as __pyplusplus_logging -def set_logger_level( level ): - __pygccxml_utils.logger.setLevel( level ) +def set_logger_level( level ): + for l in __pygccxml_utils.loggers.all: + l.setLevel( level ) __pyplusplus_logging.logger.setLevel( level ) \ No newline at end of file Modified: pyplusplus_dev/pyplusplus/module_builder/builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-07-09 19:53:40 UTC (rev 288) +++ pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-07-10 12:33:25 UTC (rev 289) @@ -62,7 +62,6 @@ , define_symbols=define_symbols , undefine_symbols=undefine_symbols , start_with_declarations=start_with_declarations - , verbose=compilation_verbose , ignore_gccxml_output=ignore_gccxml_output) #may be in future I will add those directories to user_defined_directories This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |