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-04 17:55:03 +0100 |
commit | 1572c3015f4aead481140fde85807ec341bbd130 (patch) | |
tree | 4cd76bb338dbb6e5714a7e1e21064c6dfdab088c | |
parent | cc5f95fa563c4817cdcffc428da18e263bd02ae2 (diff) | |
download | morph-cache-server-1572c3015f4aead481140fde85807ec341bbd130.tar.gz |
Add /postartifacts
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 | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/morph-cache-server b/morph-cache-server index dbf6785..ad102bf 100755 --- a/morph-cache-server +++ b/morph-cache-server @@ -303,7 +303,32 @@ class MorphCacheServer(cliapp.Application): else: response.status = 404 logging.debug('artifact %s does not exist' % basename) - + + @app.get('/postartifacts') + def artifact(): + return ''' + <form action="/postartifacts" method="post"> + artifacts: <input name="artifacts" type="text" /> + </form> + ''' + + @app.post('/postartifacts') + def do_artifacts(): + artifacts = request.forms.get('artifacts').split(',') + results = {} + + logging.debug('Received a POST request for /postartifacts') + + 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) + + return results + root = Bottle() root.mount(app, '/1.0') |