Mercurial > public > src > rhodecode
comparison pylons_app/lib/middleware/simplehg.py @ 257:66f617f162f8
added custom messages for remote responses.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 05 Jun 2010 17:09:03 +0200 |
parents | 3782a6d698af |
children | c961b78ff0a0 |
comparison
equal
deleted
inserted
replaced
256:c49010829e4d | 257:66f617f162f8 |
---|---|
35 from pylons_app.model import meta | 35 from pylons_app.model import meta |
36 from pylons_app.model.db import UserLog, User | 36 from pylons_app.model.db import UserLog, User |
37 from webob.exc import HTTPNotFound | 37 from webob.exc import HTTPNotFound |
38 import logging | 38 import logging |
39 import os | 39 import os |
40 from itertools import chain | |
40 log = logging.getLogger(__name__) | 41 log = logging.getLogger(__name__) |
41 | 42 |
42 class SimpleHg(object): | 43 class SimpleHg(object): |
43 | 44 |
44 def __init__(self, application, config): | 45 def __init__(self, application, config): |
87 self.__invalidate_cache(repo_name) | 88 self.__invalidate_cache(repo_name) |
88 | 89 |
89 if action: | 90 if action: |
90 username = self.__get_environ_user(environ) | 91 username = self.__get_environ_user(environ) |
91 self.__log_user_action(username, action, repo_name) | 92 self.__log_user_action(username, action, repo_name) |
92 | 93 messages = ['thanks for using hg app !'] |
93 return app(environ, start_response) | 94 return self.msg_wrapper(app, environ, start_response, messages) |
95 | |
96 | |
97 def msg_wrapper(self, app, environ, start_response, messages): | |
98 """ | |
99 Wrapper for custom messages that come out of mercurial respond messages | |
100 is a list of messages that the user will see at the end of response from | |
101 merurial protocol actions that involves remote answers | |
102 @param app: | |
103 @param environ: | |
104 @param start_response: | |
105 """ | |
106 def custom_messages(msg_list): | |
107 for msg in msg_list: | |
108 yield msg + '\n' | |
109 org_response = app(environ, start_response) | |
110 return chain(org_response, custom_messages(messages)) | |
94 | 111 |
95 def __make_app(self): | 112 def __make_app(self): |
96 hgserve = hgweb(self.repo_path) | 113 hgserve = hgweb(self.repo_path) |
97 return self.__load_web_settings(hgserve) | 114 return self.__load_web_settings(hgserve) |
98 | 115 |