def get_source(self, source): if isinstance(source, basestring): source = self.__config.sources[source] logger.debug('Trying to parse source %r' % source.name) if source not in self.__source_results: parser = source.parser.load(self.__locator) if isinstance(parser, type) and issubclass(parser, SourceBase): parser = parser() if not isinstance(parser, SourceBase): raise BuilderError("Parser reference %s could not be loaded" % parser) res = parser.load(source.resource, self.__locator) if isinstance(res, etree._ElementTree): res = res.getroot() for transform in source.transform: modtrans = transform.load(self.__locator) res = modtrans(res) self.__source_results[source] = res logger.info('Source %r successfuly parsed' % source.name) else: logger.debug('Source already parsed') return self.__source_results[source]
def exclude_files(filename): exclude = (filename[-4:] == '.pyc' or os.path.basename(filename)[0] == '.') if exclude: logger.debug('File %r not included', filename) else: logger.info('Adding file %r', filename) return exclude
def prepare(self, argv): logger.debug('Preparing arguments') try: parser = optparse.OptionParser(option_list=self._option_list) self._opts, self._args = parser.parse_args(argv) return True except SystemExit, e: if e.code: logger.error('Option parser exited with error code %d', e.code) return False
def get_handler(self, source, context): '''Try to generate source with each contained generator instance''' heap = list(self._generators) while heap: _, (gen, matcher) = heapq.heappop(heap) if matcher is None or matcher(source, context): logger.debug('Generating source %r with priority generator %r (matching sub-generator %r)' % (source, self, gen)) return gen raise ValueError("Source cannot be generated")
def _collect(self): '''Collect subgenerators from instance''' for factory, generator in collect_marked_bound(self, 'generator'): priority = get_mark_default(generator, 'priority', PRI_BASE) matchers = get_mark_default(generator, 'matchers', []) logger.info('Registering sub-generator %r into generator %r; priority=%d, matchers=%r', generator, self, priority, matchers) if factory is not None: logger.debug('Factory found for sub-generator %r: %r', generator, factory) generator = factory(generator) self.register(generator, priority=priority, matcher=ObjectGenerator.__get_internal_matcher(matchers))
def remove_dest_file(self, relpath): logger.debug('Trying to remove %r' % relpath) try: destination = self.get_target_path(relpath) except BuilderError: logger.debug('Path containing %r not found' % relpath) return if os.path.isfile(destination): logger.info('Removing file %s' % destination) os.unlink(destination) else: logger.debug('File %r not found' % relpath)
def __replace(match): logger.debug('Match found: %s' % match.group()) name = match.group()[1:-1] return os.getenv(name)