def callView(self, config, path): from pyramid.router import Router from pyramid.testing import DummyRequest router = Router(config.registry) request = DummyRequest(path=path, registry=config.registry) return router.handle_request(request)
def build(self): with main_module(self.site): self.registry.notify(PreBuild(self)) paths = self.get_paths() router = Router(self.registry) extensions = self.registry.queryUtility(IRequestExtensions) for path in paths: request = _make_request(path, registry=self.registry) if extensions is not None: request._set_extensions(extensions) response = router.handle_request(request) self.write(path, response)
def callView(self, config, path, matchdict=None, GET=None, POST=None, iface=None): from pyramid.router import Router from pyramid.testing import DummyRequest router = Router(config.registry) request = DummyRequest(path=path, registry=config.registry) request.matchdict = matchdict or {} if GET: request.GET = GET if POST: request.POST = POST if iface: directlyProvides(request, iface) return router.handle_request(request)
def build(self): with main_module(self.site): __import__("__main__.config") config = self.site.config.config self.registry = config.registry config.add_request_method(static_path) config.add_request_method(relroute_path) config.commit() self.registry['path'] = self.path self.siteconfig = config.registry.queryUtility( IConfigFactory, default=DefaultConfigFactory)(self.registry) self.siteconfig.setdefault('site', {}) self.siteconfig['site'].setdefault('outpath', 'output') self.registry['root'] = config.registry.queryUtility(IRootFactory) self.registry['siteconfig'] = self.siteconfig self.registry.registerUtility(lambda h, r: h, ITweens) written_paths = set() self.registry.notify(PreBuild(self)) paths = self.get_paths() router = Router(self.registry) extensions = self.registry.queryUtility(IRequestExtensions) for path in paths: request = _make_request(path, registry=self.registry) self.threadlocal_manager.push(dict( registry=self.registry, request=request)) try: if extensions is not None: request._set_extensions(extensions) response = router.handle_request(request) finally: self.threadlocal_manager.pop() written_paths.add(self.write(path[1:], response)) all_paths = dirtools.Dir(self.siteconfig['site']['outpath']) for path in set(all_paths.files()).difference(written_paths): fn = os.path.join(self.siteconfig['site']['outpath'], path) log.info("Deleting '%s'." % path) os.unlink(fn) for path in all_paths.subdirs(sort_reverse=True): fn = os.path.join(self.siteconfig['site']['outpath'], path) try: os.rmdir(fn) log.info("Removed '%s'." % path) except OSError as ex: if ex.errno != errno.ENOTEMPTY: raise