annotate pylons_app/lib/simplehg.py @ 111:70b1e5d1e20d

simplehg, cleanup
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 28 Apr 2010 00:16:08 +0200
parents
children cc5cf1a93902
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 import os
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 import cgi
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 from mercurial import util
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 from mercurial.hgweb.request import wsgirequest, normalize
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from mercurial.hgweb import hgweb
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 from pylons.controllers.util import Response
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 from mercurial.hgweb.request import wsgiapplication
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 class SimpleHg(object):
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 def __init__(self, application, config):
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 self.application = application
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 self.config = config
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 def __call__(self, environ, start_response):
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 if not is_mercurial(environ):
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 return self.application(environ, start_response)
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 else:
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 from pprint import pprint
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 pprint(environ)
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 repo_path = os.path.join('/home/marcink/python_workspace/', environ['PATH_INFO'].replace('/', ''))
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 def _make_app():return hgweb(repo_path, "Name")
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 app = wsgiapplication(_make_app)
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 return app(environ, start_response)
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 def is_mercurial(environ):
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 """
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 Returns True if request's target is mercurial server - header
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 """
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 http_accept = environ.get('HTTP_ACCEPT')
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 if http_accept and http_accept.startswith('application/mercurial'):
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 return True
70b1e5d1e20d simplehg, cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 return False