コード例 #1
0
ファイル: introspect.py プロジェクト: olekenneth/chains
def _parseMethodDoc(text):
    funcDoc = []
    argsDoc = {}
    argsOrder = []
    if text:
        pat = re.compile(' +')
        text = text.strip()
        for line in text.split('\n'):
            line = line.strip()
            tmp = pat.split(line)
            pre = tmp.pop(0)
            if pre and pre[0] == '@':
                pre = pre[1:]
                if pre == 'param':
                    key = tmp.pop(0)
                    argsOrder.append(key)
                    if not argsDoc.has_key(key):
                        argsDoc[key] = {}
                    argsDoc[key]['key'] = key
                    argsDoc[key]['type'] = tmp.pop(0)
                    argsDoc[key]['info'] = ' '.join(tmp)
                    argsDoc[key]['required'] = True
                elif pre == 'valid':
                    key = tmp.pop(0)
                    if not argsDoc.has_key(key):
                        argsDoc[key] = {}
                    argsDoc[key]['valid'] = json.decode(' '.join(tmp))
                elif pre == 'optional':
                    key = tmp.pop(0)
                    if not argsDoc.has_key(key):
                        argsDoc[key] = {}
                    argsDoc[key]['required'] = False
            else:
                funcDoc.append(line)
    return ('\n'.join(funcDoc), argsDoc, argsOrder)
コード例 #2
0
ファイル: amqp.py プロジェクト: olekenneth/chains
    def call(self, key, data=None, timeout=5, block=None):
        log.debug('RPC-CALL: execute %s = %s' % (key, data))
        if block is None:
            block = True

        # @todo: remove consume again afterwards!
        if not timeout:
            # tuba - no_ack=True is also an option
            self.consumerTag = self.ch.basic_consume(self.queue, callback=self._callback)

        self.response = None
        self.correlationId = getUuid()  # str(uuid.uuid4())
        msg = amqp.Message(
            json.encode(data),
            content_type='text/json',
            correlation_id=self.correlationId,
            # reply_to = self.queue
        )
        self.ch.basic_publish(
            msg,
            self.exchange,
            key,
            # reply_to = self.queue,
            # correlation_id = self.correlationId
        )

        if not block:
            return
        log.notice('RPC-CALL: wait response')

        startTime = time.time()
        while self.response is None:
            if timeout:
                msg = self.ch.basic_get(self.queue)
                if msg:
                    if self._callback(msg):
                        break
                else:
                    time.sleep(0.01)
                    if (time.time() - startTime) >= timeout:
                        raise TimeoutException('Waited %s sec for rpc call %s' % (timeout, key))
            else:
                self.ch.wait()

        log.notice('RPC-CALL: finished waiting')
        try:
            body = json.decode(self.response.body)
        except Exception as e:
            raise Exception("json decoding error: %s - for raw response: %s" % (e, self.response.body))
        tmp = self.response.routing_key.split('.')
        if tmp[0][1] == 'x': # todo: use constants
            if tmp[0][0] == 'o': d = 'orchestrator' # here too
            elif tmp[0][0] == 's': d = 'service'
            elif tmp[0][0] == 'r': d = 'reactor'
            elif tmp[0][0] == 'm': d = 'manager'
            e = RemoteException('Error in %s %s when calling %s' % (d,tmp[1],tmp[2]))
            e.setResponse(body)
            raise e
        log.debug('RPC-CALL: respone %s = %s' % (self.response.routing_key, body))
        return body
コード例 #3
0
ファイル: introspect.py プロジェクト: auduny/chains
def _parseMethodDoc(text):
    funcDoc = []
    argsDoc = {}
    argsOrder = []
    if text:
        pat = re.compile(' +')
        text = text.strip()
        for line in text.split('\n'):
            line = line.strip()
            tmp = pat.split(line)
            pre = tmp.pop(0)
            if pre and pre[0] == '@':
                pre = pre[1:]
                if pre == 'param':
                    key = tmp.pop(0)
                    argsOrder.append(key)
                    if not argsDoc.has_key(key):
                        argsDoc[key] = {}
                    argsDoc[key]['key'] = key
                    argsDoc[key]['type'] = tmp.pop(0)
                    argsDoc[key]['info'] = ' '.join(tmp)
                    argsDoc[key]['required'] = True
                elif pre == 'valid':
                    key = tmp.pop(0)
                    if not argsDoc.has_key(key):
                        argsDoc[key] = {}
                    argsDoc[key]['valid'] = json.decode(' '.join(tmp))
                elif pre == 'optional':
                    key = tmp.pop(0)
                    if not argsDoc.has_key(key):
                        argsDoc[key] = {}
                    argsDoc[key]['required'] = False
            else:
                funcDoc.append(line)
    return ('\n'.join(funcDoc), argsDoc, argsOrder)
コード例 #4
0
ファイル: __init__.py プロジェクト: auduny/chains
def parse(_req):
    parser = OptionParser()
    parser.add_option("-r", "--raw", action="store_true", dest="raw", help="Output raw data (do not format it)")
    parser.add_option("-j", "--json", action="store_true", dest="json", help="Output data as json")
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Be verbose (show error traces")
    parser.add_option(
        "-d",
        "--debug",
        action="store_true",
        dest="debug",
        help="Be very verbose (print log message for level debug and above)",
    )
    (options, req) = parser.parse_args(_req)
    try:
        section = req[0]
    except IndexError:
        raise InvalidParameterException("Missing section")
    try:
        command = req[1]
    except IndexError:
        raise InvalidParameterException("Missing command")
    id = None
    args = []
    if len(req) > 2:
        id = req[2]
        args = [id]
        if len(req) > 3:
            for a in req[3:]:
                if a[0] in ["{", "["]:
                    a = json.decode(a)
                args.append(a)
    options.section = section
    options.command = command
    options.args = args
    return options
コード例 #5
0
ファイル: amqp.py プロジェクト: auduny/chains
 def get(self):
     if self.deliveryTag is not None:
         raise Exception('You must call ack() before getting a new item')
     while not self.messages:
         self.ch.wait()
     msg = self.messages.pop(0)
     try:
         data = json.decode(msg.body)
     except Exception, e:
         raise Exception("Failed decoding JSON: %s\nOrig exception: %s" % (msg.body, e))
コード例 #6
0
ファイル: __init__.py プロジェクト: olekenneth/chains
def parse(_req):
    parser = OptionParser()
    parser.add_option('-r',
                      '--raw',
                      action='store_true',
                      dest='raw',
                      help='Output raw data (do not format it)')
    parser.add_option('-j',
                      '--json',
                      action='store_true',
                      dest='json',
                      help='Output data as json')
    parser.add_option('-v',
                      '--verbose',
                      action='store_true',
                      dest='verbose',
                      help='Be verbose (show error traces')
    parser.add_option(
        '-d',
        '--debug',
        action='store_true',
        dest='debug',
        help='Be very verbose (print log message for level debug and above)')
    (options, req) = parser.parse_args(_req)
    try:
        section = req[0]
    except IndexError:
        raise InvalidParameterException('Missing section')
    try:
        command = req[1]
    except IndexError:
        raise InvalidParameterException('Missing command')
    id = None
    args = []
    if len(req) > 2:
        id = req[2]
        args = [id]
        if len(req) > 3:
            for a in req[3:]:
                if a[0] in ['{', '[']:
                    a = json.decode(a)
                args.append(a)
    if section == 'help':
        options.section = command
        options.command = args[0]
        options.args = []
        options.help = True
    else:
        options.section = section
        options.command = command
        options.args = args
        options.help = False
    return options
コード例 #7
0
ファイル: amqp.py プロジェクト: auduny/chains
    def call(self, key, data=None, timeout=5, block=None):
        log.debug('RPC-CALL: execute %s = %s' % (key, data))
        if block == None:
            block = True

        # @todo: remove consume again afterwards!
        if not timeout:
            # tuba - no_ack=True is also an option
            self.consumerTag = self.ch.basic_consume(self.queue, callback=self._callback)

        self.response = None
        self.correlationId = getUuid() #str(uuid.uuid4())
        msg = amqp.Message(
            json.encode(data),
            content_type='text/json',
            correlation_id = self.correlationId,
            #reply_to = self.queue
        )
        self.ch.basic_publish(
            msg,
            self.exchange,
            key,
            #reply_to = self.queue,
            #correlation_id = self.correlationId
        )

        if not block:
            return
        log.notice('RPC-CALL: wait response')

        startTime = time.time()
        while self.response is None:
            if timeout:
                msg = self.ch.basic_get(self.queue)
                if msg:
                    if self._callback(msg):
                        break
                else:
                    time.sleep(0.01)
                    if (time.time()-startTime) >= timeout:
                        raise TimeoutException('Waited %s sec for rpc call %s' % (timeout, key))
            else:
                self.ch.wait()

        log.notice('RPC-CALL: finished waiting')
        try:
            body = json.decode(self.response.body)
        except Exception, e:
            raise Exception("json decoding error: %s - for raw response: %s" % (e, self.response.body))
コード例 #8
0
ファイル: amqp.py プロジェクト: olekenneth/chains
 def get(self):
     if self.deliveryTag is not None:
         raise Exception('You must call ack() before getting a new item')
     while not self.messages:
         self.ch.wait()
     msg = self.messages.pop(0)
     try:
         data = json.decode(msg.body)
     except Exception as e:
         raise Exception("Failed decoding JSON: %s\nOrig exception: %s" % (msg.body, repr(e)))
     self.deliveryTag = msg.delivery_tag
     correlationId = None
     if 'correlation_id' in msg.properties:
         correlationId = msg.properties['correlation_id']
     return (msg.routing_key, data, correlationId)
コード例 #9
0
ファイル: amqp.py プロジェクト: olekenneth/chains
 def get(self):
     if self.deliveryTag is not None:
         raise Exception('You must call ack() before getting a new item')
     while not self.messages:
         self.ch.wait()
     msg = self.messages.pop(0)
     try:
         data = json.decode(msg.body)
     except Exception as e:
         raise Exception("Failed decoding JSON: %s\nOrig exception: %s" %
                         (msg.body, repr(e)))
     self.deliveryTag = msg.delivery_tag
     correlationId = None
     if 'correlation_id' in msg.properties:
         correlationId = msg.properties['correlation_id']
     return (msg.routing_key, data, correlationId)
コード例 #10
0
ファイル: __init__.py プロジェクト: olekenneth/chains
def parse(_req):
    parser = OptionParser()
    parser.add_option('-r', '--raw', action='store_true', dest='raw', help='Output raw data (do not format it)')
    parser.add_option('-j', '--json', action='store_true', dest='json', help='Output data as json')
    parser.add_option('-v', '--verbose', action='store_true', dest='verbose', help='Be verbose (show error traces')
    parser.add_option('-d', '--debug', action='store_true', dest='debug', help='Be very verbose (print log message for level debug and above)')
    (options, req) = parser.parse_args(_req)
    try:
        section = req[0]
    except IndexError:
        raise InvalidParameterException('Missing section')
    try:
        command = req[1]
    except IndexError:
        raise InvalidParameterException('Missing command')
    id = None
    args = []
    if len(req) > 2:
        id = req[2]
        args = [id]
        if len(req) > 3:
            for a in req[3:]:
                if a[0] in ['{', '[']:
                    a = json.decode(a)
                args.append(a)
    if section == 'help':
        options.section = command
        options.command = args[0]
        options.args = []
        options.help = True
    else:
        options.section = section
        options.command = command
        options.args = args
        options.help = False
    return options
コード例 #11
0
ファイル: amqp.py プロジェクト: olekenneth/chains
    def call(self, key, data=None, timeout=5, block=None):
        log.debug('RPC-CALL: execute %s = %s' % (key, data))
        if block is None:
            block = True

        # @todo: remove consume again afterwards!
        if not timeout:
            # tuba - no_ack=True is also an option
            self.consumerTag = self.ch.basic_consume(self.queue,
                                                     callback=self._callback)

        self.response = None
        self.correlationId = getUuid()  # str(uuid.uuid4())
        msg = amqp.Message(
            json.encode(data),
            content_type='text/json',
            correlation_id=self.correlationId,
            # reply_to = self.queue
        )
        self.ch.basic_publish(
            msg,
            self.exchange,
            key,
            # reply_to = self.queue,
            # correlation_id = self.correlationId
        )

        if not block:
            return
        log.notice('RPC-CALL: wait response')

        startTime = time.time()
        while self.response is None:
            if timeout:
                msg = self.ch.basic_get(self.queue)
                if msg:
                    if self._callback(msg):
                        break
                else:
                    time.sleep(0.01)
                    if (time.time() - startTime) >= timeout:
                        raise TimeoutException(
                            'Waited %s sec for rpc call %s' % (timeout, key))
            else:
                self.ch.wait()

        log.notice('RPC-CALL: finished waiting')
        try:
            body = json.decode(self.response.body)
        except Exception as e:
            raise Exception("json decoding error: %s - for raw response: %s" %
                            (e, self.response.body))
        tmp = self.response.routing_key.split('.')
        if tmp[0][1] == 'x':  # todo: use constants
            if tmp[0][0] == 'o': d = 'orchestrator'  # here too
            elif tmp[0][0] == 's': d = 'service'
            elif tmp[0][0] == 'r': d = 'reactor'
            elif tmp[0][0] == 'm': d = 'manager'
            e = RemoteException('Error in %s %s when calling %s' %
                                (d, tmp[1], tmp[2]))
            e.setResponse(body)
            raise e
        log.debug('RPC-CALL: respone %s = %s' %
                  (self.response.routing_key, body))
        return body