Skip to content
Snippets Groups Projects
Verified Commit d5a30f59 authored by drebs's avatar drebs
Browse files

[refactor] make get_flags() return a deferred

parent 601ed3ed
Branches
No related tags found
1 merge request!169#9007 - improve and document IBlobsBackend
...@@ -101,11 +101,12 @@ class FilesystemBlobsBackend(object): ...@@ -101,11 +101,12 @@ class FilesystemBlobsBackend(object):
def get_flags(self, user, blob_id, namespace=''): def get_flags(self, user, blob_id, namespace=''):
path = self._get_path(user, blob_id, namespace) path = self._get_path(user, blob_id, namespace)
if not os.path.isfile(path): if not os.path.isfile(path):
raise BlobNotFound return defer.fail(BlobNotFound)
if not os.path.isfile(path + '.flags'): if not os.path.isfile(path + '.flags'):
return [] return defer.succeed([])
with open(path + '.flags', 'r') as flags_file: with open(path + '.flags', 'r') as flags_file:
return json.loads(flags_file.read()) flags = json.loads(flags_file.read())
return defer.succeed(flags)
def set_flags(self, user, blob_id, flags, namespace=''): def set_flags(self, user, blob_id, flags, namespace=''):
path = self._get_path(user, blob_id, namespace) path = self._get_path(user, blob_id, namespace)
...@@ -298,8 +299,11 @@ class BlobsResource(resource.Resource): ...@@ -298,8 +299,11 @@ class BlobsResource(resource.Resource):
only_flags = request.args.get('only_flags', [False])[0] only_flags = request.args.get('only_flags', [False])[0]
try: try:
if only_flags: if only_flags:
flags = self._handler.get_flags(user, blob_id, namespace) d = self._handler.get_flags(user, blob_id, namespace)
return json.dumps(flags) d.addCallback(lambda flags: json.dumps(flags))
d.addCallback(lambda flags: request.write(flags))
d.addCallback(lambda _: request.finish())
return NOT_DONE_YET
tag = self._handler.get_tag(user, blob_id, namespace) tag = self._handler.get_tag(user, blob_id, namespace)
request.responseHeaders.setRawHeaders('Tag', [tag]) request.responseHeaders.setRawHeaders('Tag', [tag])
except BlobNotFound: except BlobNotFound:
......
...@@ -173,8 +173,8 @@ class IBlobsBackend(Interface): ...@@ -173,8 +173,8 @@ class IBlobsBackend(Interface):
:param namespace: An optional namespace for the blob. :param namespace: An optional namespace for the blob.
:type namespace: str :type namespace: str
:return: a list of flags. :return: A deferred that fires with the list of flags for a blob.
:rtype: list of str :rtype: twisted.internet.defer.Deferred
""" """
def set_flags(user, blob_id, flags, namespace=''): def set_flags(user, blob_id, flags, namespace=''):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment