def read_file(self, filename, namespace=None): """ Parse a file. """ # Only parse the file if we haven't parsed it before or it has been # modified since we last parsed it! module, mod_time = self._database.get(filename, (None, None)) if module is None or mod_time != os.stat(filename)[stat.ST_MTIME]: # Event notification. self.parsing_module = filename logger.debug('parsing module %s' % filename) module_factory = ModuleFactory() try: module = module_factory.from_file(filename, namespace) # Event notification. self.parsed_module = module logger.debug('parsed module %s' % filename) # Add the parsed module to the database. self._database[filename] = (module, os.stat(filename)[stat.ST_MTIME]) self._database_changed = True except 'ddd': logger.debug('error parsing module %s' % filename) return module
def read_file(self, filename, namespace=None): """ Parse a file. """ # Only parse the file if we haven't parsed it before or it has been # modified since we last parsed it! module, mod_time = self._database.get(filename, (None, None)) if module is None or mod_time != os.stat(filename)[stat.ST_MTIME]: # Event notification. self.parsing_module = filename logger.debug('parsing module %s' % filename) module_factory = ModuleFactory() try: module = module_factory.from_file(filename, namespace) # Event notification. self.parsed_module = module logger.debug('parsed module %s' % filename) # Add the parsed module to the database. self._database[filename] = ( module, os.stat(filename)[stat.ST_MTIME] ) self._database_changed = True except 'ddd': logger.debug('error parsing module %s' % filename) return module
def read_file(filename, namespace=None): """ Parses a file. """ global MODULES global MODULES_CHANGED module, mod_time = MODULES.get(filename, (None, None)) if module is None or mod_time != os.stat(filename)[stat.ST_MTIME]: logger.debug('parsing module %s' % filename) module_factory = ModuleFactory() try: module = module_factory.from_file(filename, namespace) # Add the parsed module to the cache. MODULES[filename] = (module, os.stat(filename)[stat.ST_MTIME]) MODULES_CHANGED = True except: logger.exception('error parsing file %s' % filename) return module