##// END OF EJS Templates
Updated hgignore to skip .idea config files
Updated hgignore to skip .idea config files

File last commit:

r3797:d7488551 beta
r3831:bd39c1f7 beta
Show More
pygrack.py
201 lines | 6.9 KiB | text/x-python | PythonLexer
changed dulwich git interface to gitweb + subprocessio
r2382 import os
import socket
import logging
import subprocess
more logging in pygrack
r2875 import traceback
changed dulwich git interface to gitweb + subprocessio
r2382
from webob import Request, Response, exc
git executable is now configurable via .ini files
r3376 import rhodecode
synced vcs with upstream...
r3797 from rhodecode.lib.vcs import subprocessio
changed dulwich git interface to gitweb + subprocessio
r2382
log = logging.getLogger(__name__)
class FileWrapper(object):
def __init__(self, fd, content_length):
self.fd = fd
self.content_length = content_length
self.remain = content_length
def read(self, size):
if size <= self.remain:
try:
data = self.fd.read(size)
except socket.error:
raise IOError(self)
self.remain -= size
elif self.remain:
data = self.fd.read(self.remain)
self.remain = 0
else:
data = None
return data
def __repr__(self):
return '<FileWrapper %s len: %s, read: %s>' % (
self.fd, self.content_length, self.content_length - self.remain
)
class GitRepository(object):
git_folder_signature = set(['config', 'head', 'info', 'objects', 'refs'])
commands = ['git-upload-pack', 'git-receive-pack']
Implemented basic locking functionality....
r2726 def __init__(self, repo_name, content_path, extras):
changed dulwich git interface to gitweb + subprocessio
r2382 files = set([f.lower() for f in os.listdir(content_path)])
if not (self.git_folder_signature.intersection(files)
== self.git_folder_signature):
raise OSError('%s missing git signature' % content_path)
self.content_path = content_path
self.valid_accepts = ['application/x-%s-result' %
c for c in self.commands]
self.repo_name = repo_name
Implemented basic locking functionality....
r2726 self.extras = extras
changed dulwich git interface to gitweb + subprocessio
r2382
def _get_fixedpath(self, path):
"""
Small fix for repo_path
:param path:
:type path:
"""
return path.split(self.repo_name, 1)[-1].strip('/')
def inforefs(self, request, environ):
"""
WSGI Response producer for HTTP GET Git Smart
HTTP /info/refs request.
"""
Implemented basic locking functionality....
r2726 git_command = request.GET.get('service')
changed dulwich git interface to gitweb + subprocessio
r2382 if git_command not in self.commands:
log.debug('command %s not allowed' % git_command)
return exc.HTTPMethodNotAllowed()
# note to self:
# please, resist the urge to add '\n' to git capture and increment
# line count by 1.
# The code in Git client not only does NOT need '\n', but actually
# blows up if you sprinkle "flush" (0000) as "0001\n".
# It reads binary, per number of bytes specified.
# if you do add '\n' as part of data, count it.
reset response charset to fix Egit/JGit issues
r2579 server_advert = '# service=%s' % git_command
packet_len = str(hex(len(server_advert) + 4)[2:].rjust(4, '0')).lower()
git executable is now configurable via .ini files
r3376 _git_path = rhodecode.CONFIG.get('git_path', 'git')
changed dulwich git interface to gitweb + subprocessio
r2382 try:
out = subprocessio.SubprocessIOChunker(
git executable is now configurable via .ini files
r3376 r'%s %s --stateless-rpc --advertise-refs "%s"' % (
_git_path, git_command[4:], self.content_path),
changed dulwich git interface to gitweb + subprocessio
r2382 starting_values=[
reset response charset to fix Egit/JGit issues
r2579 packet_len + server_advert + '0000'
changed dulwich git interface to gitweb + subprocessio
r2382 ]
)
except EnvironmentError, e:
more logging in pygrack
r2875 log.error(traceback.format_exc())
changed dulwich git interface to gitweb + subprocessio
r2382 raise exc.HTTPExpectationFailed()
resp = Response()
resp.content_type = 'application/x-%s-advertisement' % str(git_command)
reset response charset to fix Egit/JGit issues
r2579 resp.charset = None
changed dulwich git interface to gitweb + subprocessio
r2382 resp.app_iter = out
return resp
def backend(self, request, environ):
"""
WSGI Response producer for HTTP POST Git Smart HTTP requests.
Reads commands and data from HTTP POST's body.
returns an iterator obj with contents of git command's
response to stdout
"""
git_command = self._get_fixedpath(request.path_info)
if git_command not in self.commands:
log.debug('command %s not allowed' % git_command)
return exc.HTTPMethodNotAllowed()
if 'CONTENT_LENGTH' in environ:
inputstream = FileWrapper(environ['wsgi.input'],
request.content_length)
else:
inputstream = environ['wsgi.input']
try:
Added handling of git hooks, extract pushed revisions and store them inside...
r2402 gitenv = os.environ
# forget all configs
gitenv['GIT_CONFIG_NOGLOBAL'] = '1'
opts = dict(
changed scope of calling EXTENSIONS from rhodecode for githooks to be able to execute them
r2406 env=gitenv,
cwd=os.getcwd()
Added handling of git hooks, extract pushed revisions and store them inside...
r2402 )
more logging in pygrack
r2875 cmd = r'git %s --stateless-rpc "%s"' % (git_command[4:],
self.content_path),
log.debug('handling cmd %s' % cmd)
changed dulwich git interface to gitweb + subprocessio
r2382 out = subprocessio.SubprocessIOChunker(
more logging in pygrack
r2875 cmd,
Added handling of git hooks, extract pushed revisions and store them inside...
r2402 inputstream=inputstream,
**opts
)
changed dulwich git interface to gitweb + subprocessio
r2382 except EnvironmentError, e:
more logging in pygrack
r2875 log.error(traceback.format_exc())
changed dulwich git interface to gitweb + subprocessio
r2382 raise exc.HTTPExpectationFailed()
if git_command in [u'git-receive-pack']:
# updating refs manually after each push.
# Needed for pre-1.7.0.4 git clients using regular HTTP mode.
git executable is now configurable via .ini files
r3376 _git_path = rhodecode.CONFIG.get('git_path', 'git')
cmd = (u'%s --git-dir "%s" '
'update-server-info' % (_git_path, self.content_path))
more logging in pygrack
r2875 log.debug('handling cmd %s' % cmd)
subprocess.call(cmd, shell=True)
changed dulwich git interface to gitweb + subprocessio
r2382
resp = Response()
resp.content_type = 'application/x-%s-result' % git_command.encode('utf8')
reset charset for git rpc cals also
r2581 resp.charset = None
changed dulwich git interface to gitweb + subprocessio
r2382 resp.app_iter = out
return resp
def __call__(self, environ, start_response):
request = Request(environ)
_path = self._get_fixedpath(request.path_info)
if _path.startswith('info/refs'):
app = self.inforefs
elif [a for a in self.valid_accepts if a in request.accept]:
app = self.backend
try:
resp = app(request, environ)
except exc.HTTPException, e:
resp = e
more logging in pygrack
r2875 log.error(traceback.format_exc())
changed dulwich git interface to gitweb + subprocessio
r2382 except Exception, e:
more logging in pygrack
r2875 log.error(traceback.format_exc())
changed dulwich git interface to gitweb + subprocessio
r2382 resp = exc.HTTPInternalServerError()
return resp(environ, start_response)
class GitDirectory(object):
Implemented basic locking functionality....
r2726 def __init__(self, repo_root, repo_name, extras):
changed dulwich git interface to gitweb + subprocessio
r2382 repo_location = os.path.join(repo_root, repo_name)
if not os.path.isdir(repo_location):
raise OSError(repo_location)
self.content_path = repo_location
self.repo_name = repo_name
self.repo_location = repo_location
Implemented basic locking functionality....
r2726 self.extras = extras
changed dulwich git interface to gitweb + subprocessio
r2382
def __call__(self, environ, start_response):
content_path = self.content_path
try:
Implemented basic locking functionality....
r2726 app = GitRepository(self.repo_name, content_path, self.extras)
changed dulwich git interface to gitweb + subprocessio
r2382 except (AssertionError, OSError):
fixed #545, exception during cloning of non-bare repositories
r2764 content_path = os.path.join(content_path, '.git')
if os.path.isdir(content_path):
app = GitRepository(self.repo_name, content_path, self.extras)
changed dulwich git interface to gitweb + subprocessio
r2382 else:
fix http NotFound call in pygrack
r2594 return exc.HTTPNotFound()(environ, start_response)
changed dulwich git interface to gitweb + subprocessio
r2382 return app(environ, start_response)
Implemented basic locking functionality....
r2726 def make_wsgi_app(repo_name, repo_root, extras):
return GitDirectory(repo_root, repo_name, extras)