def __call__(self, environ, start_response): start = time.time() try: return self.application(environ, start_response) finally: log = logging.getLogger('rhodecode.' + self.__class__.__name__) log.info('IP: %s Request to %s time: %.3fs' % ( _get_ip_addr(environ), safe_unicode(_get_access_path(environ)), time.time() - start) )
def _handle_push(self, repo, username, action, repo_name, revisions): """ Triggers push action hooks :param repo: SCM repo :param username: username who pushes :param action: push/push_loca/push_remote :param repo_name: name of repo :param revisions: list of revisions that we pushed """ from rhodecode import CONFIG from rhodecode.lib.base import _get_ip_addr try: from pylons import request environ = request.environ except TypeError: # we might use this outside of request context, let's fake the # environ data from webob import Request environ = Request.blank('').environ #trigger push hook extras = { 'ip': _get_ip_addr(environ), 'username': username, 'action': 'push_local', 'repository': repo_name, 'scm': repo.alias, 'config': CONFIG['__file__'], 'server_url': get_server_url(environ), 'make_lock': None, 'locked_by': [None, None] } _scm_repo = repo._repo _set_extras(extras) if repo.alias == 'hg': log_push_action(_scm_repo.ui, _scm_repo, node=revisions[0]) elif repo.alias == 'git': log_push_action(None, _scm_repo, _git_revs=revisions)
def _handle_rc_scm_extras(self, username, repo_name, repo_alias, action=None): from rhodecode import CONFIG from rhodecode.lib.base import _get_ip_addr try: from pylons import request environ = request.environ except TypeError: # we might use this outside of request context, let's fake the # environ data from webob import Request environ = Request.blank('').environ extras = { 'ip': _get_ip_addr(environ), 'username': username, 'action': action or 'push_local', 'repository': repo_name, 'scm': repo_alias, 'config': CONFIG['__file__'], 'server_url': get_server_url(environ), 'make_lock': None, 'locked_by': [None, None] } _set_extras(extras)
status = [] headers = [] exc_info = [] def change_content(new_status, new_headers, new_exc_info=None): status.append(new_status) headers.extend(new_headers) exc_info.append(new_exc_info) output = WSGIController.__call__(self, environ, change_content) output = list(output) headers.append(('Content-Length', str(len(output[0])))) replace_header(headers, 'Content-Type', 'application/json') start_response(status[0], headers, exc_info[0]) log.info('IP: %s Request to %s time: %.3fs' % ( _get_ip_addr(environ), safe_unicode(_get_access_path(environ)), time.time() - start) ) return output def _dispatch_call(self): """ Implement dispatch interface specified by WSGIController """ try: raw_response = self._inspect_call(self._func) if isinstance(raw_response, HTTPError): self._error = str(raw_response) except JSONRPCError, e: self._error = str(e) except Exception, e:
def _get_ip_addr(self, environ): return _get_ip_addr(environ)