def setUp(self): self.ui = myui() self.repodir = mkdtemp() # subclasses should override this to do real work self.setUpRepo() write_hgrc(self.repodir) self.repo = hg.repository(self.ui, self.repodir) # At some point create_server changed to take a hgweb.hgweb # as the second param instead of a repo. I don't know of a clean # way to feature test this, and this is just a unit test, so # the hacky way seems okay. argname = inspect.getargspec(server.create_server).args[1] arg = None if argname == "app": arg = hgweb.hgweb(self.repo.root, baseui=self.ui) elif argname == "repo": arg = self.repo if arg is None: # error, something unknown raise SystemExit("Don't know how to run hgweb in this Mercurial version!") self.server = server.create_server(self.ui, arg) self.server.handle_error = handle_error _, self.port = self.server.socket.getsockname() # run the server on a background thread so we can interrupt it threading.Thread(target=self.server.serve_forever).start()
def serve_and_exec(ui, repo, *command): other_server = ui.config(b'serve', b'other', None) if other_server: other_server = OtherServer(other_server, ui) other_server_thread = Thread(target=other_server.run) other_server_thread.start() ui.setconfig(b'web', b'push_ssl', False, b'hgweb') ui.setconfig(b'web', b'allow_push', b'*', b'hgweb') # For older versions of mercurial repo.baseui.setconfig(b'web', b'push_ssl', False, b'hgweb') repo.baseui.setconfig(b'web', b'allow_push', b'*', b'hgweb') app = hgweb.hgweb(repo, baseui=ui) service = httpservice(ui, app, { b'port': ui.configint(b'web', b'port', 8000), b'print_url': False }) service.init() service_thread = Thread(target=service.run) service_thread.start() ret = subprocess.call(command) service.httpd.shutdown() service_thread.join() if other_server: other_server.httpd.shutdown() other_server_thread.join() return ret
def setUp(self): self.ui = myui() self.repodir = mkdtemp() # subclasses should override this to do real work self.setUpRepo() write_hgrc(self.repodir) self.repo = hg.repository(self.ui, self.repodir) # At some point create_server changed to take a hgweb.hgweb # as the second param instead of a repo. I don't know of a clean # way to feature test this, and this is just a unit test, so # the hacky way seems okay. argname = inspect.getargspec(server.create_server).args[1] arg = None if argname == "app": arg = hgweb.hgweb(self.repo.root, baseui=self.ui) elif argname == "repo": arg = self.repo if arg is None: # error, something unknown raise SystemExit( "Don't know how to run hgweb in this Mercurial version!") self.server = server.create_server(self.ui, arg) self.server.handle_error = handle_error _, self.port = self.server.socket.getsockname() # run the server on a background thread so we can interrupt it threading.Thread(target=self.server.serve_forever).start()
def __init__(self, repository, ui): #Create the server app = hgweb.hgweb(repository.root, ui) self.httpd = hgweb.server.create_server(ui, app) #Compute address if self.httpd.prefix: self.prefix = self.httpd.prefix.strip('/') + '/' else: self.prefix = '' self._port = self.httpd.port self.port = ':%d' % self.httpd.port if self.port == ':80': self.port = '' self.host = self.httpd.fqaddr if ':' in self.host: self.host = '[%s]' % fqaddr self.http_address = 'http://%s%s/%s' % (self.host, self.port, self.prefix) #Start server self.thread_server = threading.Thread(target = self.httpd.serve_forever) self.thread_server.start()
def __make_app(self): """ Make an wsgi application using hgweb, and inject generated baseui instance, additionally inject some extras into ui object """ self.__inject_extras(self.baseui, self.extras) return hgweb(str(self.repo_path), baseui=self.baseui)
def main(): config = Config() manager = Manager() if config.get("debug"): manager += Debugger(events=config.get("verbose"), file=config.get("errorlog")) environ = Environment(config) SignalHandler(environ).register(environ) manager += environ if config.get("sock") is not None: bind = config.get("sock") elif ":" in config.get("bind"): address, port = config.get("bind").split(":") bind = (address, int(port)) else: bind = (config.get("bind"), config.get("port")) server = Server(bind) + Sessions() + Root(environ) + CacheControl(environ) + ErrorHandler(environ) if MemoryMonitor is not None: MemoryMonitor(channel="/memory").register(server) if not config.get("disable-logging"): server += Logger(file=config.get("accesslog", sys.stdout)) if not config.get("disable-static"): server += Static(docroot=os.path.join(config.get("theme"), "htdocs")) if not config.get("disable-hgweb"): baseui = ui() baseui.setconfig("web", "prefix", "/+hg") baseui.setconfig("web", "style", "gitweb") baseui.setconfig("web", "allow_push", "*") baseui.setconfig("web", "push_ssl", False) baseui.setconfig("web", "allow_archive", ["bz2", "gz", "zip"]) baseui.setconfig("web", "description", config.get("description")) server += Gateway({"/+hg": hgweb(environ.storage.repo_path, config.get("name"), baseui)}) if not config.get("disable-compression"): server += Compression(environ) if config.get("daemon"): manager += Daemon(config.get("pidfile")) server.register(manager) manager.run()
def hgweb_handler(environ, start_response): from mercurial import demandimport; demandimport.enable() #from mercurial.hgweb.hgwebdir_mod import hgwebdir #from mercurial.hgweb.request import wsgiapplication from mercurial.hgweb import hgweb hgweb_conf = '/etc/mercurial/hgweb.conf' #make_web_app = hgwebdir(hgweb_conf) hg_webapp = hgweb(hgweb_conf) #hg_webapp = wsgiapplication(make_web_app) return hg_webapp(environ, start_response)
def hgweb_handler(environ, start_response): from mercurial import demandimport demandimport.enable() #from mercurial.hgweb.hgwebdir_mod import hgwebdir #from mercurial.hgweb.request import wsgiapplication from mercurial.hgweb import hgweb hgweb_conf = '/etc/mercurial/hgweb.conf' #make_web_app = hgwebdir(hgweb_conf) hg_webapp = hgweb(hgweb_conf) #hg_webapp = wsgiapplication(make_web_app) return hg_webapp(environ, start_response)
def serve_and_exec(ui, repo, *command): ui.setconfig('web', 'push_ssl', False, 'hgweb') ui.setconfig('web', 'allow_push', '*', 'hgweb') # For older versions of mercurial repo.baseui.setconfig('web', 'push_ssl', False, 'hgweb') repo.baseui.setconfig('web', 'allow_push', '*', 'hgweb') app = hgweb.hgweb(repo, baseui=ui) service = httpservice(ui, app, {'port': 8000}) print command service.init() service_thread = Thread(target=service.run) service_thread.start() ret = subprocess.call(command) service.httpd.shutdown() service_thread.join() return ret
def serve_and_exec(ui, repo, *command): ui.setconfig('web', 'push_ssl', False, 'hgweb') ui.setconfig('web', 'allow_push', 'foo', 'hgweb') # For older versions of mercurial repo.baseui.setconfig('web', 'push_ssl', False, 'hgweb') repo.baseui.setconfig('web', 'allow_push', 'foo', 'hgweb') app = hgweb.hgweb(repo, baseui=ui) service = httpservice(ui, app, {'port': 8000}) print command service.init() service_thread = Thread(target=service.run) service_thread.start() ret = subprocess.call(command) service.httpd.shutdown() service_thread.join() return ret
def serve_and_exec(ui, repo, *command): other_server = os.environ.get('OTHER_SERVER') if other_server: other_server = OtherServer(other_server) other_server_thread = Thread(target=other_server.run) other_server_thread.start() ui.setconfig('web', 'push_ssl', False, 'hgweb') ui.setconfig('web', 'allow_push', '*', 'hgweb') # For older versions of mercurial repo.baseui.setconfig('web', 'push_ssl', False, 'hgweb') repo.baseui.setconfig('web', 'allow_push', '*', 'hgweb') app = hgweb.hgweb(repo, baseui=ui) service = httpservice(ui, app, {'port': 8000, 'print_url': False}) print command service.init() service_thread = Thread(target=service.run) service_thread.start() ret = subprocess.call(command) service.httpd.shutdown() service_thread.join() if other_server: other_server.httpd.shutdown() other_server_thread.join() return ret
def serve_and_exec(ui, repo, *command): other_server = os.environ.get('OTHER_SERVER') if other_server: other_server = OtherServer(other_server) other_server_thread = Thread(target=other_server.run) other_server_thread.start() ui.setconfig('web', 'push_ssl', False, 'hgweb') ui.setconfig('web', 'allow_push', '*', 'hgweb') # For older versions of mercurial repo.baseui.setconfig('web', 'push_ssl', False, 'hgweb') repo.baseui.setconfig('web', 'allow_push', '*', 'hgweb') app = hgweb.hgweb(repo, baseui=ui) service = httpservice(ui, app, {'port': 8000, 'print_url': False}) print(command) service.init() service_thread = Thread(target=service.run) service_thread.start() ret = subprocess.call(command) service.httpd.shutdown() service_thread.join() if other_server: other_server.httpd.shutdown() other_server_thread.join() return ret
#!/usr/bin/env python # # An example hgweb CGI script, edit as necessary # See also http://mercurial.selenic.com/wiki/PublishingRepositories # Path to repo or hgweb config to serve (see 'hg help hgweb') config = "hgweb.ini" # Uncomment and adjust if Mercurial is not installed system-wide # (consult "installed modules" path from 'hg debuginstall'): # import sys; sys.path.insert(0, "/path/to/python/lib") # Uncomment to send python tracebacks to the browser if an error occurs: import cgitb cgitb.enable() from mercurial import demandimport demandimport.enable() from mercurial.hgweb import hgweb, wsgicgi application = hgweb(config) wsgicgi.launch(application)
import os from mercurial import demandimport, ui as uimod, hg from mercurial.hgweb import hgweb, wsgicgi demandimport.enable() try: u = uimod.ui.load() except AttributeError: # For installations earlier than Mercurial 4.1 u = uimod.ui() u.setconfig('web', 'push_ssl', 'false') u.setconfig('web', 'allow_read', '*') u.setconfig('web', 'allow_push', '*') u.setconfig('hooks', 'changegroup.scm', 'python:scmhooks.postHook') u.setconfig('hooks', 'pretxnchangegroup.scm', 'python:scmhooks.preHook') # pass SCM_HTTP_POST_ARGS to enable experimental httppostargs protocol of mercurial # SCM_HTTP_POST_ARGS is set by HgCGIServlet # Issue 970: https://goo.gl/poascp u.setconfig('experimental', 'httppostargs', os.environ['SCM_HTTP_POST_ARGS']) # open repository # SCM_REPOSITORY_PATH contains the repository path and is set by HgCGIServlet r = hg.repository(u, os.environ['SCM_REPOSITORY_PATH']) application = hgweb(r) wsgicgi.launch(application)
def repo_detail(request, pattern): slug = pattern.split('/')[0] repo = get_object_or_404(Repository, slug=slug) response = HttpResponse() hgr = HgRequestWrapper( request, response, script_name=repo.get_absolute_url(), ) """ Authenticate on all requests. To authenticate only against 'POST' requests, uncomment the line below the comment. Currently, repositories are only viewable by authenticated users. If authentication is only done on 'POST' request, then repositories are readable by anyone. but only authenticated users can push. """ realm = hgwebproxy_settings.AUTH_REALM # Change if you want. if is_mercurial(request): # This is a request by a mercurial client # If slash not present then add slash regardless of APPEND_SLASH setting # since hgweb returns 404 if it isn't present. if not request.path.endswith('/'): new_url = [request.get_host(), request.path+'/'] if new_url[0]: newurl = "%s://%s%s" % ( request.is_secure() and 'https' or 'http', new_url[0], urlquote(new_url[1])) else: newurl = urlquote(new_url[1]) if request.GET: newurl += '?' + request.META['QUERY_STRING'] return HttpResponsePermanentRedirect(newurl) authed = basic_auth(request, realm, repo) else: # This is a standard web request if not repo.has_view_permission(request.user): raise PermissionDenied(_("You do not have access to this repository")) authed = request.user.username #if not request.user.is_authenticated(): # return HttpResponseRedirect('%s?next=%s' % # (settings.LOGIN_URL,request.path)) #else: # authed = request.user.username if not authed: response.status_code = 401 response['WWW-Authenticate'] = '''Basic realm="%s"''' % realm return response else: hgr.set_user(authed) """ Run the `hgwebdir` method from Mercurial directly, with our incognito request wrapper, output will be buffered. Wrapped in a try:except: since `hgweb` *can* crash. Mercurial now sends the content through as a generator. We need to iterate over the output in order to get all of the content """ template_dir = os.path.join(os.path.dirname(__file__), 'templates') hgserve = hgweb(str(repo.location)) hgserve.reponame = repo.slug if hgwebproxy_settings.TEMPLATE_PATHS is not None: hgserve.templatepath = hgwebproxy_settings.TEMPLATE_PATHS hgserve.repo.ui.setconfig('web', 'description', smart_str(repo.description)) hgserve.repo.ui.setconfig('web', 'name', smart_str(hgserve.reponame)) # encode('utf-8') FIX "decoding Unicode is not supported" exception on mercurial hgserve.repo.ui.setconfig('web', 'contact', smart_str(repo.owner.get_full_name())) hgserve.repo.ui.setconfig('web', 'allow_archive', repo.allow_archive) # Set the style style = repo.style or hgwebproxy_settings.STYLE if not templater.templatepath(style): raise ImproperlyConfigured(_("'%s' is not an available style. Please check the HGPROXY_STYLE property in your settings.py" % style)) hgserve.repo.ui.setconfig('web', 'style', style) hgserve.repo.ui.setconfig('web', 'baseurl', repo.get_absolute_url() ) # Allow push to the current user hgserve.repo.ui.setconfig('web', 'allow_push', authed) #Allow serving static content from a seperate URL if not settings.DEBUG: hgserve.repo.ui.setconfig('web', 'staticurl', hgwebproxy_settings.STATIC_URL) if settings.DEBUG or hgwebproxy_settings.ALLOW_HTTP_PUSH: # Allow pushing in using http when debugging hgserve.repo.ui.setconfig('web', 'push_ssl', 'false') # Allow hgweb errors to propagate response.write(''.join([each for each in hgserve.run_wsgi(hgr)])) return response
def cgiserve(ui, repo, **opts): application = hgweb(repo) wsgicgi.launch(application)
#!/usr/bin/env python # # An example hgweb CGI script, edit as necessary # See also http://mercurial.selenic.com/wiki/PublishingRepositories # Path to repo or hgweb config to serve (see 'hg help hgweb') config = "/var/www/cgi-bin/tinycm/content" # Uncomment and adjust if Mercurial is not installed system-wide # (consult "installed modules" path from 'hg debuginstall'): #import sys; sys.path.insert(0, "/path/to/python/lib") # Uncomment to send python tracebacks to the browser if an error occurs: #import cgitb; cgitb.enable() from mercurial import demandimport demandimport.enable() from mercurial.hgweb import hgweb, wsgicgi application = hgweb(config) wsgicgi.launch(application)
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # http://bitbucket.org/sdorra/scm-manager # # import os, sys pythonPath = os.environ['SCM_PYTHON_PATH'] if len(pythonPath) > 0: pathParts = pythonPath.split(os.pathsep) for i in range(len(pathParts)): sys.path.insert(i, pathParts[i]) repositoryPath = os.environ['SCM_REPOSITORY_PATH'] from mercurial import demandimport; demandimport.enable() from mercurial.hgweb import hgweb, wsgicgi application = hgweb(repositoryPath) wsgicgi.launch(application)
username, password = decoded.split(':', 1) return username == password and username.startswith("abc") def password_prompt(self, environ, start_response): start_response( '401 Authentication Required', [ ('Content-Type', 'text/html'), ('WWW-Authenticate', 'Basic realm="HGLogin"'), ]) return [b'Please login'] def dummy_app(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) return [b'Hello, world!'] if __name__ == '__main__': # httpd = make_server('', PORT, TrivialAuth(dummy_app)) httpd = make_server('', PORT, TrivialAuth(hgweb(CONFIG_PATH))) # application = hgweb(config_path) # httpd = make_server('', 8080, TrivialAuth(application)) print('Serving on port 8080...') try: httpd.serve_forever() except KeyboardInterrupt: pass
def repo_detail(request, username, pattern): """ Repository detail view. """ repo_name = pattern.split('/')[0] repo = get_object_or_404(Repository, slug=repo_name, owner__username=username) """ Instance the hgweb wrapper """ response = HttpResponse() hgr = HgRequestWrapper(request, response, script_name=repo.get_absolute_url()) """ Authenticate on all requests. To authenticate only against 'POST' requests """ realm = hgwebproxy_settings.AUTH_REALM mercurial_request = is_mercurial(request) if mercurial_request: """ If a slash is not present, would be added a slash regardless of APPEND_SLASH django setting since hgweb returns 404 if it isn't present. """ if not request.path.endswith('/'): new_url = [request.get_host(), request.path + '/'] if new_url[0]: newurl = "%s://%s%s" % (request.is_secure() and 'https' or 'http', new_url[0], urlquote(new_url[1])) else: newurl = urlquote(new_url[1]) if request.GET: newurl += '?' + request.META['QUERY_STRING'] return HttpResponseRedirect(newurl) authed = basic_auth(request, realm, repo) else: if not repo.can_browse(request.user): raise PermissionDenied( _("You do not have access to this repository")) authed = request.user.username if not authed: response.status_code = 401 response['WWW-Authenticate'] = '''Basic realm="%s"''' % realm if request.META['REQUEST_METHOD'] == 'POST' and request.META[ 'QUERY_STRING'].startswith("cmd=unbundle"): # drain request, this is a fix/workaround for http://mercurial.selenic.com/btw/issue1876 hgr.drain() return response else: hgr.set_user(authed) hgserve = hgweb(str(repo.location)) hgserve.reponame = repo.slug # TODO: is it Possible to charge the settings just for one time? hgserve.repo.ui.setconfig('web', 'name', smart_str(hgserve.reponame)) hgserve.repo.ui.setconfig('web', 'description', smart_str(repo.description)) hgserve.repo.ui.setconfig('web', 'contact', smart_str(repo.owner.get_full_name())) hgserve.repo.ui.setconfig('web', 'allow_archive', repo.allow_archive) if os.path.exists(hgwebproxy_settings.STYLES_PATH): template_paths = templater.templatepath() template_paths.insert(0, hgwebproxy_settings.STYLES_PATH) hgserve.repo.ui.setconfig('web', 'templates', template_paths) hgserve.templatepath = hgserve.repo.ui.config('web', 'templates', template_paths) if hgwebproxy_settings.ALLOW_CUSTOM_STYLE: hgserve.repo.ui.setconfig('web', 'style', repo.style) else: hgserve.repo.ui.setconfig('web', 'style', hgwebproxy_settings.DEFAULT_STYLE) hgserve.repo.ui.setconfig('web', 'baseurl', repo.get_absolute_url()) hgserve.repo.ui.setconfig('web', 'allow_push', authed) #Allow push to the current user hgserve.repo.ui.setconfig('web', 'staticurl', hgwebproxy_settings.STATIC_URL) if settings.DEBUG: hgserve.repo.ui.setconfig('web', 'push_ssl', 'false') else: hgserve.repo.ui.setconfig('web', 'push_ssl', repo.allow_push_ssl) # Catch hgweb error to show as Django Exceptions try: response.write(''.join(each for each in hgserve.run_wsgi(hgr))) except KeyError: return HttpResponseServerError('Mercurial has crashed', mimetype='text/html') if mercurial_request: return response # make sure we return the response without wrapping if content-type is # either a binary stream or text/plain (for raw changesets). if response['content-type'].split(';')[0] in ('application/octet-stream', 'text/plain'): return response context = { 'content': response.content, 'reponame': hgserve.reponame, 'static_url': hgwebproxy_settings.STATIC_URL, 'slugpath': request.path.replace(repo.get_absolute_url(), ''), 'is_root': request.path == repo.get_absolute_url(), 'repo': repo, } if request.path.endswith(repo_name + '/rss-log') or request.path.endswith(repo_name + '/atom-log'): return HttpResponse(response.content, mimetype='application/xml') else: return render_to_response("hgwebproxy/wrapper.html", context, RequestContext(request))
def explore(self, request, id, *args): opts = self.model._meta app_label = opts.app_label response = HttpResponse() repo = get_object_or_404(Repository, pk=id) if not self.has_view_permission(request, repo): raise PermissionDenied hgr = HgRequestWrapper( request, response, script_name=repo.get_admin_explore_url(), ) hgr.set_user(request.user.username) """ Run the `hgwebdir` method from Mercurial directly, with our incognito request wrapper, output will be buffered. Wrapped in a try:except: since `hgweb` *can* crash. Mercurial now sends the content through as a generator. We need to iterate over the output in order to get all of the content """ template_dir = os.path.join(os.path.dirname(__file__), 'templates') hgserve = hgweb(str(repo.location)) hgserve.reponame = repo.slug # TODO: A more flexible way to get the default template path of mercurial hgserve.templatepath = (template_dir, '/usr/share/mercurial/templates') hgserve.repo.ui.setconfig('web', 'description', smart_str(repo.description)) hgserve.repo.ui.setconfig('web', 'name', smart_str(hgserve.reponame)) # encode('utf-8') FIX "decoding Unicode is not supported" exception on mercurial hgserve.repo.ui.setconfig('web', 'contact', smart_str(repo.owner.get_full_name())) hgserve.repo.ui.setconfig('web', 'allow_archive', repo.allow_archive) hgserve.repo.ui.setconfig('web', 'style', 'monoblue_plain') hgserve.repo.ui.setconfig('web', 'baseurl', repo.get_admin_explore_url()) hgserve.repo.ui.setconfig('web', 'staticurl', STATIC_URL) try: response.write(''.join([each for each in hgserve.run_wsgi(hgr)])) except KeyError: response['content-type'] = 'text/html' response.write('hgweb crashed.') # if hgweb crashed you can do what you like, throw a 404 or continue on # hgweb tends to throw these on invalid requests..? pass context = { 'app_label': app_label, 'opts': opts, 'has_change_permission': self.has_change_permission(request, repo), 'original': repo, 'content': response.content, 'reponame' : hgserve.reponame, 'static_url' : STATIC_URL, 'slugpath': request.path.replace(repo.get_admin_explore_url(), '') or 'summary', 'is_root': request.path == repo.get_admin_explore_url(), } """ In cases of downloading raw files or tarballs, we don't want to pass the output to our template, so instead we just return it as-is. """ if response.has_header('content-type'): if not response['content-type'].startswith("text/html"): return response """ Otherwise, send the content on to the template, for any kind of custom layout you want around it. """ return render_to_response("admin/hgwebproxy/repository/explore.html", context, RequestContext(request))
def repo_detail(request, username, pattern): """ Repository detail view. """ repo_name = pattern.split('/')[0] repo = get_object_or_404(Repository, slug=repo_name, owner__username=username) """ Instance the hgweb wrapper """ response = HttpResponse() hgr = HgRequestWrapper(request, response, script_name=repo.get_absolute_url()) """ Authenticate on all requests. To authenticate only against 'POST' requests """ realm = hgwebproxy_settings.AUTH_REALM mercurial_request = is_mercurial(request) if mercurial_request: """ If a slash is not present, would be added a slash regardless of APPEND_SLASH django setting since hgweb returns 404 if it isn't present. """ if not request.path.endswith('/'): new_url = [request.get_host(), request.path + '/'] if new_url[0]: newurl = "%s://%s%s" % ( request.is_secure() and 'https' or 'http', new_url[0], urlquote(new_url[1])) else: newurl = urlquote(new_url[1]) if request.GET: newurl += '?' + request.META['QUERY_STRING'] return HttpResponseRedirect(newurl) authed = basic_auth(request, realm, repo) else: if not repo.can_browse(request.user): raise PermissionDenied(_("You do not have access to this repository")) authed = request.user.username if not authed: response.status_code = 401 response['WWW-Authenticate'] = '''Basic realm="%s"''' % realm if request.META['REQUEST_METHOD']=='POST' and request.META['QUERY_STRING'].startswith("cmd=unbundle"): # drain request, this is a fix/workaround for http://mercurial.selenic.com/btw/issue1876 hgr.drain() return response else: hgr.set_user(authed) hgserve = hgweb(str(repo.location)) hgserve.reponame = repo.slug # TODO: is it Possible to charge the settings just for one time? hgserve.repo.ui.setconfig('web', 'name', smart_str(hgserve.reponame)) hgserve.repo.ui.setconfig('web', 'description', smart_str(repo.description)) hgserve.repo.ui.setconfig('web', 'contact', smart_str(repo.owner.get_full_name())) hgserve.repo.ui.setconfig('web', 'allow_archive', repo.allow_archive) if os.path.exists(hgwebproxy_settings.STYLES_PATH): template_paths = templater.templatepath() template_paths.insert(0, hgwebproxy_settings.STYLES_PATH) hgserve.repo.ui.setconfig('web', 'templates', template_paths) hgserve.templatepath = hgserve.repo.ui.config('web', 'templates', template_paths) if hgwebproxy_settings.ALLOW_CUSTOM_STYLE: hgserve.repo.ui.setconfig('web', 'style', repo.style) else: hgserve.repo.ui.setconfig('web', 'style', hgwebproxy_settings.DEFAULT_STYLE) hgserve.repo.ui.setconfig('web', 'baseurl', repo.get_absolute_url()) hgserve.repo.ui.setconfig('web', 'allow_push', authed) #Allow push to the current user hgserve.repo.ui.setconfig('web', 'staticurl', hgwebproxy_settings.STATIC_URL) if settings.DEBUG: hgserve.repo.ui.setconfig('web', 'push_ssl', 'false') else: hgserve.repo.ui.setconfig('web', 'push_ssl', repo.allow_push_ssl) # Catch hgweb error to show as Django Exceptions try: response.write(''.join(each for each in hgserve.run_wsgi(hgr))) except KeyError: return HttpResponseServerError('Mercurial has crashed', mimetype='text/html') if mercurial_request: return response # make sure we return the response without wrapping if content-type is # either a binary stream or text/plain (for raw changesets). if response['content-type'].split(';')[0] in ('application/octet-stream', 'text/plain'): return response context = { 'content': response.content, 'reponame' : hgserve.reponame, 'static_url' : hgwebproxy_settings.STATIC_URL, 'slugpath': request.path.replace(repo.get_absolute_url(), ''), 'is_root': request.path == repo.get_absolute_url(), 'repo': repo, } if request.path.endswith(repo_name + '/rss-log') or request.path.endswith(repo_name + '/atom-log'): return HttpResponse(response.content, mimetype='application/xml') else: return render_to_response("hgwebproxy/wrapper.html", context, RequestContext(request))
def wsgi_handler(repository): return hgweb(repository, baseui=repository.ui)
def make_application(wsgi_dir): set_env() config = os.path.join(wsgi_dir, 'hgweb.config') return hgweb(config)
# and/or other materials provided with the distribution. # 3. Neither the name of SCM-Manager; nor the names of its # contributors may be used to endorse or promote products derived from this # software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # http://bitbucket.org/sdorra/scm-manager # # import os from mercurial import demandimport from mercurial.hgweb import hgweb, wsgicgi repositoryPath = os.environ['SCM_REPOSITORY_PATH'] demandimport.enable() application = hgweb(repositoryPath) wsgicgi.launch(application)
def main(): config = Config() manager = Manager() if config.get("debug"): manager += Debugger( events=config.get("verbose"), file=config.get("errorlog"), ) environ = Environment(config) SignalHandler(environ).register(environ) manager += environ if config.get("sock") is not None: bind = config.get("sock") elif ":" in config.get("bind"): address, port = config.get("bind").split(":") bind = ( address, int(port), ) else: bind = ( config.get("bind"), config.get("port"), ) server = (Server(bind) + Sessions() + Root(environ) + CacheControl(environ) + ErrorHandler(environ)) if MemoryMonitor is not None: MemoryMonitor(channel="/memory").register(server) if not config.get("disable-logging"): server += Logger(file=config.get("accesslog", sys.stdout)) if not config.get("disable-static"): server += Static(docroot=os.path.join(config.get("theme"), "htdocs")) if not config.get("disable-hgweb"): baseui = ui() baseui.setconfig("web", "prefix", "/+hg") baseui.setconfig("web", "style", "gitweb") baseui.setconfig("web", "allow_push", "*") baseui.setconfig("web", "push_ssl", False) baseui.setconfig("web", "allow_archive", ["bz2", "gz", "zip"]) baseui.setconfig("web", "description", config.get("description")) server += Gateway({ "/+hg": hgweb(environ.storage.repo_path, config.get("name"), baseui) }) if not config.get("disable-compression"): server += Compression(environ) if config.get("daemon"): manager += Daemon(config.get("pidfile")) server.register(manager) manager.run()