summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-04-18 17:14:11 +0100
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-04-18 17:14:11 +0100
commit6b762c363224860833ea20c9ba8109c0c210d419 (patch)
treea41776ac5c08759edee98d56e967a983ac8b67a9
parent8f3b7be2e1130a94cf4de5e9e1b5a18d382efff8 (diff)
downloadmorph-cache-server-6b762c363224860833ea20c9ba8109c0c210d419.tar.gz
Add untested support for bundles.
-rwxr-xr-xmorph-cache-server18
-rw-r--r--morphcacheserver/repocache.py13
2 files changed, 25 insertions, 6 deletions
diff --git a/morph-cache-server b/morph-cache-server
index 60c3105..5554481 100755
--- a/morph-cache-server
+++ b/morph-cache-server
@@ -20,12 +20,14 @@ import cliapp
import logging
import urllib
-from bottle import Bottle, request, response, run
+from bottle import Bottle, request, response, run, static_file
+
from morphcacheserver.repocache import RepoCache
defaults = {
'repo-dir': '/var/cache/morph-cache-server/gits',
+ 'bundle-dir': '/var/cache/morph-cache-server/bundles',
}
@@ -36,11 +38,17 @@ class MorphCacheServer(cliapp.Application):
'path to the repository cache directory',
metavar='PATH',
default=defaults['repo-dir'])
+ self.settings.string(['bundle-dir'],
+ 'path to the bundle cache directory',
+ metavar='PATH',
+ default=defaults['bundle-dir'])
def process_args(self, args):
app = Bottle()
- repo_cache = RepoCache(self, self.settings['repo-dir'])
+ repo_cache = RepoCache(self,
+ self.settings['repo-dir'],
+ self.settings['bundles'])
@app.get('/sha1s')
def sha1():
@@ -70,6 +78,12 @@ class MorphCacheServer(cliapp.Application):
except Exception, e:
response.status = 404
logging.debug('%s' % e)
+
+ @app.get('/bundles')
+ def bundle():
+ repo = self._unescape_parameter(request.query.repo)
+ filename = repo_cache.get_bundle_filename(repo)
+ return static_file(filename, download=True)
root = Bottle()
root.mount(app, '/1.0')
diff --git a/morphcacheserver/repocache.py b/morphcacheserver/repocache.py
index 1b6862c..e6ab640 100644
--- a/morphcacheserver/repocache.py
+++ b/morphcacheserver/repocache.py
@@ -44,13 +44,14 @@ class UnresolvedNamedReferenceError(cliapp.AppException):
class RepoCache(object):
- def __init__(self, app, dirname):
+ def __init__(self, app, repo_cache_dir, bundle_cache_dir):
self.app = app
- self.dirname = dirname
+ self.repo_cache_dir = repo_cache_dir
+ self.bundle_cache_dir = bundle_cache_dir
def resolve_ref(self, repo_url, ref):
quoted_url = self._quote_url(repo_url)
- repo_dir = os.path.join(self.dirname, quoted_url)
+ repo_dir = os.path.join(self.repo_cache_dir, quoted_url)
if not os.path.exists(repo_dir):
raise RepositoryNotFoundError(repo_url)
try:
@@ -68,7 +69,7 @@ class RepoCache(object):
def cat_file(self, repo_url, ref, filename):
quoted_url = self._quote_url(repo_url)
- repo_dir = os.path.join(self.dirname, quoted_url)
+ repo_dir = os.path.join(self.repo_cache_dir, quoted_url)
if not self._is_valid_sha1(ref):
raise UnresolvedNamedReferenceError(repo_url, ref)
if not os.path.exists(repo_dir):
@@ -79,6 +80,10 @@ class RepoCache(object):
raise InvalidReferenceError(repo_url, ref)
return self._cat_file(repo_dir, sha1, filename)
+
+ def get_bundle_filename(self, repo_url):
+ quoted_url = self._quote_url(repo_url)
+ return os.path.join(self.bundle_dir, '%s.bndl' % quoted_url)
def _quote_url(self, url):
valid_chars = string.digits + string.letters + '%_'