def run_wsgi(self, req): try: try: #log.debug("Inside HgRedmine::run_wsgi : " + str(req.env)) db = connect(self.dsn) self.refresh() self.findrepos(db) virtual = req.env.get("PATH_INFO", "").strip('/') tmpl = self.templater(req) ctype = tmpl('mimetype', encoding=encoding.encoding) ctype = templater.stringify(ctype) # a static file if virtual.startswith('static/') or 'static' in req.form: if virtual.startswith('static/'): fname = virtual[7:] else: fname = req.form['static'][0] static = templater.templatepath('static') return (staticfile(static, fname, req),) self._user_login(db, req) # top-level index #if not virtual: ## only administrators can list repositories #if self._is_admin(req): #req.respond(HTTP_OK, ctype) #return self.makeindex(req, tmpl) #else: #self._send_challenge(req) # navigate to hgweb project_id = virtual.split('/')[0] repos = dict(self.repos) real = repos.get(project_id) if real: req.env['REPO_NAME'] = project_id try: repo = hg.repository(self.ui.copy(), str(real)) self._setup_repo(db, repo, project_id) #log.debug("Calling HgWebRedmine with " + str(self.realm) + str(repo)) return HgwebRedmine(db, self.realm, repo).run_wsgi(req) except IOError, inst: msg = inst.strerror raise ErrorResponse(HTTP_SERVER_ERROR, msg) except error.RepoError, inst: raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
def static_file(request, file_name): # Handle static files static = templater.templatepath('static') response = HttpResponse() url = request.path req = HgRequestWrapper( request, response, script_name=url, ) response.write(''.join([each for each in (common.staticfile(static, file_name, req))])) return response
def run_wsgi(self, req): try: try: db, self.placeholder = connect(self.dsn) self.refresh() self.findrepos(db) virtual = req.env.get("PATH_INFO", "").strip('/') tmpl = self.templater(req) ctype = tmpl('mimetype', encoding=encoding.encoding) ctype = templater.stringify(ctype) # a static file if virtual.startswith('static/') or 'static' in req.form: if virtual.startswith('static/'): fname = virtual[7:] else: fname = req.form['static'][0] static = templater.templatepath('static') return (staticfile(static, fname, req),) self._user_login(db, req) # top-level index if not virtual: # nobody can list repositories self._send_challenge(req) # navigate to hgweb repository_path = '/'.join(virtual.split('/')[0:2]) repos = dict(self.repos) real = repos.get(repository_path) if real: req.env['REPO_NAME'] = repository_path req.env['PROJECT_ID'], req.env['PROJECT_OWNER_ID'] = self._project_info_from_repo_path(db, repository_path) try: repo = hg.repository(self.ui, real) self._setup_repo(db, repo, repository_path) return HgwebWide(db, self.placeholder, self.realm, repo).run_wsgi(req) except IOError, inst: msg = inst.strerror raise ErrorResponse(HTTP_SERVER_ERROR, msg) except error.RepoError, inst: raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))