Mercurial > kallithea
comparison rhodecode/lib/middleware/pygrack.py @ 2402:2eeb2ed72e55 beta
Added handling of git hooks, extract pushed revisions and store them inside
rhodecode journal. F.I.N.A.L.Y !
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 06 Jun 2012 19:51:16 +0200 |
parents | 378b0247e938 |
children | 7be31af5bc78 |
comparison
equal
deleted
inserted
replaced
2401:e2af60e480ce | 2402:2eeb2ed72e55 |
---|---|
39 | 39 |
40 class GitRepository(object): | 40 class GitRepository(object): |
41 git_folder_signature = set(['config', 'head', 'info', 'objects', 'refs']) | 41 git_folder_signature = set(['config', 'head', 'info', 'objects', 'refs']) |
42 commands = ['git-upload-pack', 'git-receive-pack'] | 42 commands = ['git-upload-pack', 'git-receive-pack'] |
43 | 43 |
44 def __init__(self, repo_name, content_path): | 44 def __init__(self, repo_name, content_path, username): |
45 files = set([f.lower() for f in os.listdir(content_path)]) | 45 files = set([f.lower() for f in os.listdir(content_path)]) |
46 if not (self.git_folder_signature.intersection(files) | 46 if not (self.git_folder_signature.intersection(files) |
47 == self.git_folder_signature): | 47 == self.git_folder_signature): |
48 raise OSError('%s missing git signature' % content_path) | 48 raise OSError('%s missing git signature' % content_path) |
49 self.content_path = content_path | 49 self.content_path = content_path |
50 self.valid_accepts = ['application/x-%s-result' % | 50 self.valid_accepts = ['application/x-%s-result' % |
51 c for c in self.commands] | 51 c for c in self.commands] |
52 self.repo_name = repo_name | 52 self.repo_name = repo_name |
53 self.username = username | |
53 | 54 |
54 def _get_fixedpath(self, path): | 55 def _get_fixedpath(self, path): |
55 """ | 56 """ |
56 Small fix for repo_path | 57 Small fix for repo_path |
57 | 58 |
113 request.content_length) | 114 request.content_length) |
114 else: | 115 else: |
115 inputstream = environ['wsgi.input'] | 116 inputstream = environ['wsgi.input'] |
116 | 117 |
117 try: | 118 try: |
119 gitenv = os.environ | |
120 from rhodecode import CONFIG | |
121 from rhodecode.lib.base import _get_ip_addr | |
122 gitenv['RHODECODE_USER'] = self.username | |
123 gitenv['RHODECODE_CONFIG_IP'] = _get_ip_addr(environ) | |
124 # forget all configs | |
125 gitenv['GIT_CONFIG_NOGLOBAL'] = '1' | |
126 # we need current .ini file used to later initialize rhodecode | |
127 # env and connect to db | |
128 gitenv['RHODECODE_CONFIG_FILE'] = CONFIG['__file__'] | |
129 opts = dict( | |
130 env=gitenv | |
131 ) | |
118 out = subprocessio.SubprocessIOChunker( | 132 out = subprocessio.SubprocessIOChunker( |
119 r'git %s --stateless-rpc "%s"' % (git_command[4:], | 133 r'git %s --stateless-rpc "%s"' % (git_command[4:], |
120 self.content_path), | 134 self.content_path), |
121 inputstream=inputstream | 135 inputstream=inputstream, |
122 ) | 136 **opts |
137 ) | |
123 except EnvironmentError, e: | 138 except EnvironmentError, e: |
124 log.exception(e) | 139 log.exception(e) |
125 raise exc.HTTPExpectationFailed() | 140 raise exc.HTTPExpectationFailed() |
126 | 141 |
127 if git_command in [u'git-receive-pack']: | 142 if git_command in [u'git-receive-pack']: |
154 return resp(environ, start_response) | 169 return resp(environ, start_response) |
155 | 170 |
156 | 171 |
157 class GitDirectory(object): | 172 class GitDirectory(object): |
158 | 173 |
159 def __init__(self, repo_root, repo_name): | 174 def __init__(self, repo_root, repo_name, username): |
160 repo_location = os.path.join(repo_root, repo_name) | 175 repo_location = os.path.join(repo_root, repo_name) |
161 if not os.path.isdir(repo_location): | 176 if not os.path.isdir(repo_location): |
162 raise OSError(repo_location) | 177 raise OSError(repo_location) |
163 | 178 |
164 self.content_path = repo_location | 179 self.content_path = repo_location |
165 self.repo_name = repo_name | 180 self.repo_name = repo_name |
166 self.repo_location = repo_location | 181 self.repo_location = repo_location |
182 self.username = username | |
167 | 183 |
168 def __call__(self, environ, start_response): | 184 def __call__(self, environ, start_response): |
169 content_path = self.content_path | 185 content_path = self.content_path |
170 try: | 186 try: |
171 app = GitRepository(self.repo_name, content_path) | 187 app = GitRepository(self.repo_name, content_path, self.username) |
172 except (AssertionError, OSError): | 188 except (AssertionError, OSError): |
173 if os.path.isdir(os.path.join(content_path, '.git')): | 189 if os.path.isdir(os.path.join(content_path, '.git')): |
174 app = GitRepository(self.repo_name, | 190 app = GitRepository(self.repo_name, |
175 os.path.join(content_path, '.git')) | 191 os.path.join(content_path, '.git')) |
176 else: | 192 else: |
177 return exc.HTTPNotFound()(environ, start_response) | 193 return exc.HTTPNotFound()(environ, start_response, self.username) |
178 return app(environ, start_response) | 194 return app(environ, start_response) |
179 | 195 |
180 | 196 |
181 def make_wsgi_app(repo_name, repo_root): | 197 def make_wsgi_app(repo_name, repo_root, username): |
182 return GitDirectory(repo_root, repo_name) | 198 return GitDirectory(repo_root, repo_name, username) |