Screenshots
Shell access
Browser access
Source code
""" plugin_h_mercurial.py
Author: Hans Christian v. Stockhausen <hc at vst.io>
Date: 2010-12-09
This is a plugin for web2py. It consists of the single controller file
plugin_mercurial.py. It wraps Mercurial's hgwebdir wsgi app and allows
one to interact with the mercurial repository of the web2py application
either from a webbrowser or the hg client.
Notes:
- I am new to Mercurial. Not sure whether this is really useful or just
plain dangerous.
- Not sure to what degree this overlaps with web2py's built in Mercurial
support, but I didn't get the impression that one can use HTTP pulls...
"""
from mercurial import hgweb
def index():
""" Controller to wrap hgweb
You can access this endpoint either from a browser in which case the
hgweb interface is displayed or from the mercurial client.
hg clone http://localhost:8000/myapp/plugin_mercurial/index myapp
To be able to push to the repository you need to edit/create the file
application/<myapp>/.hg/hgrc and add the following entries for example.
[web]
allow_push = *
push_ssl = False
Clearly this is recommended for a trusted environment only. Also see the
hgrc documentation at http://www.selenic.com/mercurial/hgrc.5.html#web.
"""
# HACK - hgweb expects the wsgi version to be reported in a tuple
wsgi_version = request.wsgi.environ['wsgi.version']
request.wsgi.environ['wsgi.version'] = (wsgi_version, 0)
# map this controller's URL to the repository location and instantiate app
config = {URL(r=request).xml():'applications/'+request.application}
wsgi_app = hgweb.hgwebdir(config)
# invoke wsgi app and return results via web2py API
# http://web2py.com/book/default/chapter/04#WSGI
items = wsgi_app(request.wsgi.environ, request.wsgi.start_response)
for item in items:
response.write(item, escape=False)
return response.body.getvalue()
hg push
You can also push to the repository. See the docstring for index()
above.
multiple repositories
The hgwebdir
wsgi application can expose multiple repositories although for a web2py application-specific plugin this is probably not what you want. If you do however want just that, try tweaking the config
variable that is passed to the hgwebdir
constructor. For example you could pass the name of the repository to access through request.args[0]. URLs are even longer then, so you might want to setup some rules in routes.py.
config = dict(
'myapp/plugin_mercurial/index/repo1'='path/to/repo1',
'myapp/plugin_mercurial/index/repo2'='path/to/repo2',
'myapp/plugin_mercurial/index/repo3'='path/to/repo3'
)
Comments (4)
0
hcvst 14 years ago
0
mrfreeze 14 years ago
0
mrfreeze 14 years ago
0
hcvst 14 years ago