diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-04-03 14:41:31 +0100 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-04-07 12:12:12 +0100 |
commit | b74c262506001c1fb43684777483a5b127cafdac (patch) | |
tree | cbefcd127dca417c9db0171d74e0511ae9248a2f | |
parent | cc5f95fa563c4817cdcffc428da18e263bd02ae2 (diff) | |
download | morph-cache-server-b74c262506001c1fb43684777483a5b127cafdac.tar.gz |
Add post request for /artifactsbaserock/richardipsum/post_artifacts
With this we can request the state of a set of artifacts
in a single request. Artifacts are sent in a post request
as a comma separated list. We check whether each artifact
is in the cache or not and send our findings back to the
client as a json list.
-rwxr-xr-x | morph-cache-server | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/morph-cache-server b/morph-cache-server index dbf6785..4ea5fb4 100755 --- a/morph-cache-server +++ b/morph-cache-server @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright (C) 2013 Codethink Limited +# Copyright (C) 2013, 2014 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ import logging import os import urllib import urllib2 +import urlparse import shutil from bottle import Bottle, request, response, run, static_file @@ -303,7 +304,27 @@ class MorphCacheServer(cliapp.Application): else: response.status = 404 logging.debug('artifact %s does not exist' % basename) - + + @app.post('/artifacts') + def post_artifacts(): + artifacts = urlparse.parse_qs( + request.body.read())['artifacts'][0].split(',') + results = {} + + logging.debug('Received a POST request for /artifacts') + + for artifact in artifacts: + logging.debug('Checking whether artifact %s is in the cache' + % artifact) + basename = self._unescape_parameter(artifact) + filename = os.path.join(self.settings['artifact-dir'], basename) + + results[artifact] = os.path.exists(filename) + logging.debug('%s is%s in the cache' % + (artifact, '' if results[artifact] else "n't")) + + return results + root = Bottle() root.mount(app, '/1.0') |