4
from paste import request
5
from paste import httpexceptions
6
from paste.wsgiwrappers import WSGIRequest, WSGIResponse
8
from loggerhead.apps import static_app
9
from loggerhead.changecache import FileChangeCache
10
from loggerhead.controllers.changelog_ui import ChangeLogUI
11
from loggerhead.controllers.inventory_ui import InventoryUI
12
from loggerhead.controllers.annotate_ui import AnnotateUI
13
from loggerhead.controllers.revision_ui import RevisionUI
14
from loggerhead.controllers.atom_ui import AtomUI
15
from loggerhead.controllers.download_ui import DownloadUI
16
from loggerhead.controllers.bundle_ui import BundleUI
17
from loggerhead.history import History
18
from loggerhead import util
21
logging.getLogger().setLevel(logging.DEBUG)
23
class BranchWSGIApp(object):
25
def __init__(self, branch_url, friendly_name=None, config={}):
26
self.branch_url = branch_url
29
self.friendly_name = friendly_name
30
self.log = logging.getLogger(friendly_name)
34
if (self._history is None) or self._history.out_of_date():
35
self.log.debug('Reload branch history...')
36
_history = self._history = History.from_folder(self.branch_url)
37
cache_path = self._config.get('cachepath', None)
38
if cache_path is not None:
39
_history.use_file_cache(FileChangeCache(_history, cache_path))
42
def url(self, *args, **kw):
43
if isinstance(args[0], list):
46
for k, v in kw.iteritems():
48
qs.append('%s=%s'%(k, urllib.quote(v)))
50
return request.construct_url(
51
self._environ, script_name=self._url_base,
52
path_info='/'.join(args),
55
def context_url(self, *args, **kw):
56
kw = util.get_context(**kw)
57
return self.url(*args, **kw)
59
def static_url(self, path):
60
return self._static_url_base + path
63
'annotate': AnnotateUI,
64
'changes': ChangeLogUI,
66
'revision': RevisionUI,
67
'download': DownloadUI,
72
def last_updated(self):
74
change = h.get_changes([ h.last_revid ])[0]
78
return self.history.get_config().get_user_option('public_branch')
80
def app(self, environ, start_response):
81
req = WSGIRequest(environ)
82
response = WSGIResponse()
83
response.headers['Content-Type'] = 'text/plain'
84
self._url_base = environ['SCRIPT_NAME']
85
self._static_url_base = environ.get('loggerhead.static.url')
86
if self._static_url_base is None:
87
self._static_url_base = self._url_base
88
self._environ = environ
89
path = request.path_info_pop(environ)
91
raise httpexceptions.HTTPMovedPermanently(
92
self._url_base + '/changes')
94
return static_app(environ, start_response)
95
cls = self.controllers_dict.get(path)
97
raise httpexceptions.HTTPNotFound()
99
c.default(req, response)
100
return response(environ, start_response)