Skip to content
Browse files

Moved initial paster app_factory to dulwich.contrib.paster.

Added 2 new filter_factories: make_gzip_filter and
make_limit_input_filter.
Updated sample paster config in docs/paster.ini to use new filters.
  • Loading branch information...
1 parent 1bf449e commit e3f4151bd6c4929e7b6fd9a626e03e40197904dc @davidblewett committed
Showing with 137 additions and 95 deletions.
  1. +6 −0 NEWS
  2. +13 −1 docs/paster.ini
  3. 0 dulwich/contrib/__init__.py
  4. +113 −0 dulwich/contrib/paster.py
  5. +0 −93 dulwich/web.py
  6. +5 −1 setup.py
View
6 NEWS
@@ -28,6 +28,12 @@
able to determine how to create an instance of HTTPGitApplication.
(David Blewett)
+ * Added support for Paster to serve instances of HTTPGitApplication.
+ Powered by 3 new entry points: dulwich.contrib.paster.make_app,
+ dulwich.contrib.paster.make_gzip_filter and
+ dulwich.contrib.paster.make_limit_input_filter.
+ (David Blewett)
+
CHANGES
* unittest2 or python >= 2.7 is now required for the testsuite.
View
14 docs/paster.ini
@@ -1,7 +1,19 @@
-[app:main]
+[app:dulwich]
use = egg:dulwich
[server:main]
use = egg:Paste#http
host = localhost
port = 8000
+
+[filter:gzip]
+use = egg:dulwich#gzip
+
+[filter:limitinput]
+use = egg:dulwich#limitinput
+
+[pipeline:main]
+pipeline =
+ gzip
+ limitinput
+ dulwich
View
0 dulwich/contrib/__init__.py
No changes.
View
113 dulwich/contrib/paster.py
@@ -0,0 +1,113 @@
+import os
+
+from dulwich import log_utils
+from dulwich.errors import NotGitRepository
+from dulwich.repo import Repo
+from dulwich.server import DictBackend
+from dulwich.web import (
+ GunzipFilter,
+ HTTPGitApplication,
+ LimitedInputFilter,
+)
+
+def make_app(global_config, **local_conf):
+ """Factory function for a Paster WSGI app
+ append_git=True will make each served git repo have .git appended to its
+ served URL.
+
+ Two options to serve: serve_dirs and individual URL path to operating
+ system path mappings.
+ Example:
+ File-system layout:
+ +-/var/lib/git
+ |-foo
+ |-bar
+ `-baz
+
+ +-/home/git
+ |-bing
+ `-bang
+
+ paster.ini:
+ [app:main]
+ use = egg:dulwich
+ append_git = True
+ serve_dirs =
+ /var/lib/git
+ /home/git
+ blerg = /home/dannyboy/src/blerg
+
+ Will result in the following being served:
+ /foo.git => /var/lib/git/foo
+ /bar.git => /var/lib/git/bar
+ /baz.git => /var/lib/git/baz
+ /bing.git => /home/git/bing
+ /bang.git => /home/git/bang
+ /blerg.git => /home/dannyboy/src/blerg
+
+ NOTE: The last name definition wins. Whatever directory in serve_dirs is
+ last, or the last explicit mapping for the same name is what will
+ be mapped.
+ """
+ from paste.deploy.converters import asbool
+ from paste.deploy.converters import aslist
+ repos = {}
+ append_git = asbool(local_conf.pop('append_git', False))
+ serve_dirs = aslist(local_conf.pop('serve_dir', None))
+ log_utils.default_logging_config()
+
+ def add_repo(mapping, path, gitdir):
+ try:
+ mapping[path] = Repo(gitdir)
+ except NotGitRepository:
+ logger.error('Not a git repository, cannot serve: "%s".',
+ gitdir)
+
+ if not local_conf:
+ add_repo(repos, '/', os.getcwd())
+ else:
+ if serve_dirs:
+ for top_dir in serve_dirs:
+ if not os.path.isdir(top_dir):
+ logger.error('Not a directory, cannot serve: "%s".',
+ top_dir)
+
+ for d in os.listdir(top_dir):
+ repo_path = '/'.join(('', d))
+ gitdir = os.path.sep.join(top_dir, d)
+ add_repo(repos, repo_path, gitdir)
+
+ for repo_name, gitdir in local_conf.items():
+ repo_path = '/'.join(('', repo_name))
+ add_repo(repos, repo_path, gitdir)
+
+ if not repos:
+ msg = 'No repositories to serve, check the ini file: "%s".'
+ logger.error(msg, global_config['__file__'])
+ raise IndexError(msg % global_config['__file__'])
+
+ if append_git:
+ new_repos = {}
+ for rpath, repo in repos.items():
+ if rpath.endswith('.git'):
+ # Don't be redundant...
+ new_repos[rpath] = repo
+ logger.debug('Not renaming, already ends in .git: "%s".',
+ rpath)
+ else:
+ new_repos['.'.join((rpath, 'git'))] = repo
+ backend = DictBackend(new_repos)
+ else:
+ backend = DictBackend(repos)
+ return HTTPGitApplication(backend)
+
+
+def make_gzip_filter(global_config):
+ """Factory function to wrap a given WSGI application in a GunzipFilter,
+ to transparently decode Content-Encoding: gzip requests.
+ """
+ return GunzipFilter
+
+
+def make_limit_input_filter(global_config):
+ return LimitedInputFilter
View
93 dulwich/web.py
@@ -29,7 +29,6 @@
except ImportError:
from dulwich._compat import parse_qs
from dulwich import log_utils
-from dulwich.errors import NotGitRepository
from dulwich.gzip import GzipConsumer
from dulwich.protocol import (
ReceivableProtocol,
@@ -414,98 +413,6 @@ def make_wsgi_chain(backend, dumb=False, handlers=None):
return wrapped_app
-def make_paster_app(global_config, **local_conf):
- """Factory function for a Paster WSGI app
- append_git=True will make each served git repo have .git appended to its
- served URL.
-
- Two options to serve: serve_dirs and individual URL path to operating
- system path mappings.
- Example:
- File-system layout:
- +-/var/lib/git
- |-foo
- |-bar
- `-baz
-
- +-/home/git
- |-bing
- `-bang
-
- paster.ini:
- [app:main]
- use = egg:dulwich
- append_git = True
- serve_dirs =
- /var/lib/git
- /home/git
- blerg = /home/dannyboy/src/blerg
-
- Will result in the following being served:
- /foo.git => /var/lib/git/foo
- /bar.git => /var/lib/git/bar
- /baz.git => /var/lib/git/baz
- /bing.git => /home/git/bing
- /bang.git => /home/git/bang
- /blerg.git => /home/dannyboy/src/blerg
-
- NOTE: The last name definition wins. Whatever directory in serve_dirs is
- last, or the last explicit mapping for the same name is what will
- be mapped.
- """
- from paste.deploy.converters import asbool
- from paste.deploy.converters import aslist
- repos = {}
- append_git = asbool(local_conf.pop('append_git', False))
- serve_dirs = aslist(local_conf.pop('serve_dir', None))
- log_utils.default_logging_config()
-
- def add_repo(mapping, path, gitdir):
- try:
- mapping[path] = Repo(gitdir)
- except NotGitRepository:
- logger.error('Not a git repository, cannot serve: "%s".',
- gitdir)
-
- if not local_conf:
- add_repo(repos, '/', os.getcwd())
- else:
- if serve_dirs:
- for top_dir in serve_dirs:
- if not os.path.isdir(top_dir):
- logger.error('Not a directory, cannot serve: "%s".',
- top_dir)
-
- for d in os.listdir(top_dir):
- repo_path = '/'.join(('', d))
- gitdir = os.path.sep.join(top_dir, d)
- add_repo(repos, repo_path, gitdir)
-
- for repo_name, gitdir in local_conf.items():
- repo_path = '/'.join(('', repo_name))
- add_repo(repos, repo_path, gitdir)
-
- if not repos:
- msg = 'No repositories to serve, check the ini file: "%s".'
- logger.error(msg, global_config['__file__'])
- raise IndexError(msg % global_config['__file__'])
-
- if append_git:
- new_repos = {}
- for rpath, repo in repos.items():
- if rpath.endswith('.git'):
- # Don't be redundant...
- new_repos[rpath] = repo
- logger.debug('Not renaming, already ends in .git: "%s".',
- rpath)
- else:
- new_repos['.'.join((rpath, 'git'))] = repo
- backend = DictBackend(new_repos)
- else:
- backend = DictBackend(repos)
- return HTTPGitApplication(backend)
-
-
# The reference server implementation is based on wsgiref, which is not
# distributed with python 2.4. If wsgiref is not present, users will not be able
# to use the HTTP server without a little extra work.
View
6 setup.py
@@ -91,7 +91,11 @@ def runcmd(cmd, env):
],
distclass=DulwichDistribution,
entry_points={
- 'paste.app_factory': 'main=dulwich.web:make_paster_app'
+ 'paste.app_factory': 'main=dulwich.contrib.paster:make_app',
+ 'paste.filter_factory': [
+ 'gzip=dulwich.contrib.paster:make_gzip_filter',
+ 'limitinput=dulwich.contrib.paster:make_limit_input_filter',
+ ]
},
**setup_kwargs
)

0 comments on commit e3f4151

Please sign in to comment.
Something went wrong with that request. Please try again.