def _runcog(options, files, uncog=False): """Common function for the cog and runcog tasks.""" from paver.cog import Cog options.order('cog', 'sphinx', add_rest=True) c = Cog() if uncog: c.options.bNoGenerate = True c.options.bReplace = True c.options.bDeleteCode = options.get("delete_code", False) includedir = options.get('includedir', None) if includedir: include = Includer(includedir, cog=c, include_markers=options.get("include_markers")) # load cog's namespace with our convenience functions. c.options.defines['include'] = include c.options.defines['sh'] = _cogsh(c) c.sBeginSpec = options.get('beginspec', '[[[cog') c.sEndSpec = options.get('endspec', ']]]') c.sEndOutput = options.get('endoutput', '[[[end]]]') basedir = options.get('basedir', None) if basedir is None: basedir = path(options.get('docroot', "docs")) / options.get('sourcedir', "") basedir = path(basedir) if not files: pattern = options.get("pattern", "*.rst") if pattern: files = basedir.walkfiles(pattern) else: files = basedir.walkfiles() for f in files: dry("cog %s" % f, c.processOneFile, f)