Commit d2c3cced authored by Ignacio Corderi's avatar Ignacio Corderi
Browse files

Media Optimize coded and async features for back ops too

parent f711127d
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -186,12 +186,21 @@ class BaseAsync(Client):
    def getVersionAsync(self, onSuccess, onError, *args, **kwargs):
        return self._processAsync(operations.GetVersion, onSuccess, onError, *args, **kwargs)

    # @RequiresProtocol('2.0.3')
    def flushAsync(self, onSuccess, onError, *args, **kwargs):
        self._processAsync(operations.Flush, onSuccess, onError, *args, **kwargs)

    def noopAsync(self, onSuccess, onError, *args, **kwargs):
        self._processAsync(operations.Noop, onSuccess, onError, *args, **kwargs)

    # @RequiresProtocol('3.0.0')
    def mediaScanAsync(self, onSuccess, onError, *args, **kwargs):
        self._processAsync(operations.MediaScan, onSuccess, onError, *args, **kwargs)

    # @RequiresProtocol('3.0.0')
    def mediaOptimizeAsync(self, onSuccess, onError, *args, **kwargs):
        self._processAsync(operations.MediaOptimize, onSuccess, onError, *args, **kwargs)



+5 −1
Original line number Diff line number Diff line
@@ -88,9 +88,13 @@ class Client(BaseClient):
        return self._process(operations.Flush, *args, **kwargs)

    # @RequiresProtocol('3.0.0')
    def media_scan(self, *args, **kwargs):
    def mediaScan(self, *args, **kwargs):
        return self._process(operations.MediaScan, *args, **kwargs)

    # @RequiresProtocol('3.0.0')
    def mediaOptimize(self, *args, **kwargs):
        return self._process(operations.MediaOptimize, *args, **kwargs)

class KineticRangeIter(object):

    def __init__(self, client, startKey, endKey, startKeyInclusive,endKeyInclusive, prefetch):
+40 −0
Original line number Diff line number Diff line
@@ -484,6 +484,9 @@ class MediaScan(object):
        if not endKey:
            endKey = '\xFF' * common.MAX_KEY_SIZE

        if len(startKey) > common.MAX_KEY_SIZE: raise common.KineticClientException("Start key exceeds maximum size of {0} bytes.".format(common.MAX_KEY_SIZE))
        if len(endKey) > common.MAX_KEY_SIZE: raise common.KineticClientException("End key exceeds maximum size of {0} bytes.".format(common.MAX_KEY_SIZE))

        m = messages.Command()

        m.header.messageType = messages.Command.BACKOP
@@ -508,3 +511,40 @@ class MediaScan(object):
    @staticmethod
    def onError(e):
        raise e

class MediaOptimize(object):

    @staticmethod
    def build(startKey=None, endKey=None, startKeyInclusive=True, endKeyInclusive=True, maxReturned=200):
        if not startKey:
            startKey = ''
        if not endKey:
            endKey = '\xFF' * common.MAX_KEY_SIZE

        if len(startKey) > common.MAX_KEY_SIZE: raise common.KineticClientException("Start key exceeds maximum size of {0} bytes.".format(common.MAX_KEY_SIZE))
        if len(endKey) > common.MAX_KEY_SIZE: raise common.KineticClientException("End key exceeds maximum size of {0} bytes.".format(common.MAX_KEY_SIZE))

        m = messages.Command()

        m.header.messageType = messages.Command.BACKOP

        op = m.body.backgroundOperation
        op.backOpType = messages.Command.BackgroundOperation.MEDIAOPTIMIZE

        kr = op.range
        kr.startKey = startKey
        kr.endKey = endKey
        kr.startKeyInclusive = startKeyInclusive
        kr.endKeyInclusive = endKeyInclusive
        kr.maxReturned = maxReturned

        return (m, None)

    @staticmethod
    def parse(m, value):
        r = m.body.backgroundOperation.range
        return ([k for k in r.keys], r.endKey)

    @staticmethod
    def onError(e):
        raise e