summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-01-14 16:54:05 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-01-14 16:54:05 +0000
commitfd8b593f02f72fd04bfafbbdbb8169c534f53e7d (patch)
tree6594a29910668e0845fed69d37747b98102d5014
parent74df327db1727a26986cdf63294ae93cf3106081 (diff)
parent22d1bfbc91a46134dd6c9410b86a3cb3ba250887 (diff)
downloadmorph-cache-server-fd8b593f02f72fd04bfafbbdbb8169c534f53e7d.tar.gz
Merge remote-tracking branch 'origin/jannispohlmann/add-batch-sha1-and-file-queries'
-rwxr-xr-xmorph-cache-server53
1 files changed, 53 insertions, 0 deletions
diff --git a/morph-cache-server b/morph-cache-server
index 04a5710..d3e42c6 100755
--- a/morph-cache-server
+++ b/morph-cache-server
@@ -16,7 +16,9 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import base64
import cliapp
+import json
import logging
import os
import urllib
@@ -197,6 +199,31 @@ class MorphCacheServer(cliapp.Application):
except Exception, e:
response.status = 404
logging.debug('%s' % e)
+
+ @app.post('/sha1s')
+ def sha1s():
+ result = []
+ for pair in request.json:
+ repo = pair['repo']
+ ref = pair['ref']
+ try:
+ sha1, tree = repo_cache.resolve_ref(repo, ref)
+ result.append({
+ 'repo': '%s' % repo,
+ 'ref': '%s' % ref,
+ 'sha1': '%s' % sha1,
+ 'tree': '%s' % tree
+ })
+ except Exception, e:
+ logging.debug('%s' % e)
+ result.append({
+ 'repo': '%s' % repo,
+ 'ref': '%s' % ref,
+ 'error': '%s' % e
+ })
+ response.set_header('Cache-Control', 'no-cache')
+ response.set_header('Content-Type', 'application/json')
+ return json.dumps(result)
@app.get('/files')
def file():
@@ -211,6 +238,32 @@ class MorphCacheServer(cliapp.Application):
response.status = 404
logging.debug('%s' % e)
+ @app.post('/files')
+ def files():
+ result = []
+ for pair in request.json:
+ repo = pair['repo']
+ ref = pair['ref']
+ filename = pair['filename']
+ try:
+ content = repo_cache.cat_file(repo, ref, filename)
+ result.append({
+ 'repo': '%s' % repo,
+ 'ref': '%s' % ref,
+ 'filename': '%s' % filename,
+ 'data': '%s' % base64.b64encode(content),
+ })
+ except Exception, e:
+ logging.debug('%s' % e)
+ result.append({
+ 'repo': '%s' % repo,
+ 'ref': '%s' % ref,
+ 'filename': '%s' % filename,
+ 'error': '%s' % e
+ })
+ response.set_header('Content-Type', 'application/json')
+ return json.dumps(result)
+
@app.get('/trees')
def tree():
repo = self._unescape_parameter(request.query.repo)