Files
@ ffd45b185016
Branch filter:
Location: kallithea/rhodecode/lib/middleware/pygrack.py - annotation
ffd45b185016
7.0 KiB
text/x-python
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3§14 and other relevant sections of GPLv3.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3§14 and other relevant sections of GPLv3.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 f68522e3df79 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 e67b2ef07a8e d7488551578e 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 aa17c7a1b8a5 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 aa17c7a1b8a5 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 aa17c7a1b8a5 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 c344a7fca2a7 c344a7fca2a7 e67b2ef07a8e 034e4fe1ebb2 034e4fe1ebb2 e67b2ef07a8e ffd45b185016 034e4fe1ebb2 c344a7fca2a7 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 f68522e3df79 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 c344a7fca2a7 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 ffd45b185016 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 2eeb2ed72e55 2eeb2ed72e55 2eeb2ed72e55 2eeb2ed72e55 7be31af5bc78 ffd45b185016 2eeb2ed72e55 ffd45b185016 ffd45b185016 f68522e3df79 034e4fe1ebb2 f68522e3df79 2eeb2ed72e55 2eeb2ed72e55 2eeb2ed72e55 034e4fe1ebb2 f68522e3df79 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 ee980eadc4b1 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 f68522e3df79 034e4fe1ebb2 f68522e3df79 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 aa17c7a1b8a5 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 aa17c7a1b8a5 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 aa17c7a1b8a5 034e4fe1ebb2 c7a27b04ce58 c7a27b04ce58 c7a27b04ce58 034e4fe1ebb2 3a54e1e121d5 034e4fe1ebb2 034e4fe1ebb2 034e4fe1ebb2 aa17c7a1b8a5 ffd45b185016 ffd45b185016 ffd45b185016 | import os
import socket
import logging
import traceback
from webob import Request, Response, exc
import rhodecode
from rhodecode.lib.vcs import subprocessio
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']
def __init__(self, repo_name, content_path, extras):
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
self.extras = extras
def _get_fixedpath(self, path):
"""
Small fix for repo_path
:param 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.
"""
git_command = request.GET.get('service')
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.
server_advert = '# service=%s' % git_command
packet_len = str(hex(len(server_advert) + 4)[2:].rjust(4, '0')).lower()
_git_path = rhodecode.CONFIG.get('git_path', 'git')
try:
out = subprocessio.SubprocessIOChunker(
r'%s %s --stateless-rpc --advertise-refs "%s"' % (
_git_path, git_command[4:], self.content_path),
starting_values=[
packet_len + server_advert + '0000'
]
)
except EnvironmentError, e:
log.error(traceback.format_exc())
raise exc.HTTPExpectationFailed()
resp = Response()
resp.content_type = 'application/x-%s-advertisement' % str(git_command)
resp.charset = None
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_path = rhodecode.CONFIG.get('git_path', 'git')
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:
gitenv = os.environ
# forget all configs
gitenv['GIT_CONFIG_NOGLOBAL'] = '1'
opts = dict(
env=gitenv,
cwd=self.content_path,
)
cmd = r'%s %s --stateless-rpc "%s"' % (_git_path, git_command[4:],
self.content_path),
log.debug('handling cmd %s' % cmd)
out = subprocessio.SubprocessIOChunker(
cmd,
inputstream=inputstream,
**opts
)
except EnvironmentError, e:
log.error(traceback.format_exc())
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.
from rhodecode.lib.vcs import get_repo
from dulwich.server import update_server_info
repo = get_repo(self.content_path)
if repo:
update_server_info(repo._repo)
resp = Response()
resp.content_type = 'application/x-%s-result' % git_command.encode('utf8')
resp.charset = None
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
log.error(traceback.format_exc())
except Exception, e:
log.error(traceback.format_exc())
resp = exc.HTTPInternalServerError()
return resp(environ, start_response)
class GitDirectory(object):
def __init__(self, repo_root, repo_name, extras):
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
self.extras = extras
def __call__(self, environ, start_response):
content_path = self.content_path
try:
app = GitRepository(self.repo_name, content_path, self.extras)
except (AssertionError, OSError):
content_path = os.path.join(content_path, '.git')
if os.path.isdir(content_path):
app = GitRepository(self.repo_name, content_path, self.extras)
else:
return exc.HTTPNotFound()(environ, start_response)
return app(environ, start_response)
def make_wsgi_app(repo_name, repo_root, extras):
from dulwich.web import LimitedInputFilter, GunzipFilter
app = GitDirectory(repo_root, repo_name, extras)
return GunzipFilter(LimitedInputFilter(app))
|