コード例 #1
0
ファイル: monitor.py プロジェクト: seanupton/zc.async
def poll(at=None, before=None, uuid=None):
    """Get information about a single poll, defaulting to most recent.

    Usage:

        poll
        (returns most recent poll)

        poll at:<poll key or interval>
        (returns poll at or before the poll key or interval)

        poll before:<poll key or interval>
        (returns poll before the poll key or interval)

    Intervals are of the format ``[nD][nH][nM][nS]``, where "n" should
    be replaced with a positive integer, and "D," "H," "M," and "S" are
    literals standing for "days," "hours," "minutes," and "seconds."
    For instance, you might use ``5M`` for five minutes, ``20S`` for
    twenty seconds, or ``1H30M`` for an hour and a half.

    Example:

        async poll at:5M
        (get the poll information at five minutes ago or before)"""
    # TODO: parse at and before to datetimes
    if uuid is not None:
        uuid = uuid_UUID(uuid)
    info = zc. async .dispatcher.get(uuid).getPollInfo(_dt(at), _dt(before))
    return {
        'key': info.key,
        'time': info.utc_timestamp.isoformat() + "Z",
        'results': info
    }
コード例 #2
0
ファイル: monitor.py プロジェクト: seanupton/zc.async
def status(uuid=None):
    """Get a mapping of general zc.async dispatcher information.

    'status' is one of 'STUCK', 'STARTING', 'RUNNING', or 'STOPPED', where
    'STUCK' means the poll is past due."""
    if uuid is not None:
        uuid = uuid_UUID(uuid)
    return zc. async .dispatcher.get(uuid).getStatusInfo()
コード例 #3
0
ファイル: test_response_json.py プロジェクト: XmingTec/zato
    def test_response_all_elem_types(self):
        class MyService(Service):
            class SimpleIO:
                output = 'aaa', AsIs('bbb'), Bool('ccc'), 'ddd', Date('eee'), DateTime('fff'), Decimal('ggg'), \
                    Float('jjj'), Int('mmm'), Opaque('ooo'), Text('ppp'), UUID('qqq')

        CySimpleIO.attach_sio(self.get_server_config(), MyService)

        aaa = 'aaa-111'
        bbb = 'bbb-222-bbb'
        ccc = True
        ddd = ''
        eee = dt_parse('1999-12-31')
        fff = dt_parse('1988-01-29T11:22:33.0000Z')
        ggg = '123.456'

        jjj = '111.222'
        mmm = '9090'

        ooo = 'ZZZ-ZZZ-ZZZ'
        ppp = 'mytext'
        qqq = uuid_UUID('d011d054-db4b-4320-9e24-7f4c217af673')

        # Note that 'ddd' is optional and we are free to skip it
        data = {
            'aaa': aaa,
            'bbb': bbb,
            'ccc': ccc,
            'ddd': ddd,
            'eee': eee,
            'fff': fff,
            'ggg': ggg,
            'jjj': jjj,
            'mmm': mmm,
            'ooo': ooo,
            'ppp': ppp,
            'qqq': qqq
        }

        result = MyService._sio.get_output(data, DATA_FORMAT.JSON)
        json_data = json_loads(result)

        self.assertEquals(json_data['aaa'], aaa)
        self.assertEquals(json_data['bbb'], bbb)
        self.assertEquals(json_data['ccc'], ccc)
        self.assertEquals(json_data['eee'], '1999-12-31')
        self.assertEquals(json_data['fff'], '1988-01-29T11:22:33+00:00')
        self.assertEquals(json_data['ggg'], ggg)
        self.assertEquals(json_data['jjj'], float(jjj))
        self.assertEquals(json_data['mmm'], int(mmm))
        self.assertEquals(json_data['ooo'], ooo)
        self.assertEquals(json_data['ppp'], ppp)
        self.assertEquals(json_data['qqq'], qqq.hex)
コード例 #4
0
    def test_parse_nested_dict_all_sio_elems(self):

        locality = Dict('locality', Int('type'), Text('name'), AsIs('coords'), Decimal('geo_skip'), Float('geo_diff'))
        address = Dict('address', locality, UUID('street_id'), CSV('prefs'), DateTime('since'), List('types'), Opaque('opaque1'))
        email = Dict('email', Text('value'), Bool('is_business'), Date('join_date'), DictList('preferred_order', 'name', 'pos'))
        customer = Dict('customer', 'name', email, address)

        class MyService(Service):
            class SimpleIO:
                input = customer

        CySimpleIO.attach_sio(self.get_server_config(), MyService)

        data = Bunch()
        data.customer = Bunch()
        data.customer.name = 'my-name'
        data.customer.email = Bunch()
        data.customer.email.value = 'my-email'
        data.customer.email.is_business = True
        data.customer.email.join_date = '1999-12-31'
        data.customer.email.preferred_order = [{'name':'address2', 'pos':'2'}, {'name':'address1', 'pos':'1'}]
        data.customer.address = Bunch()
        data.customer.address.locality = Bunch()
        data.customer.address.locality.type = '111'
        data.customer.address.locality.name = 'my-locality'
        data.customer.address.locality.coords = object()
        data.customer.address.locality.geo_skip = '123.456'
        data.customer.address.locality.geo_diff = '999.777'
        data.customer.address.street_id = uuid4().hex
        data.customer.address.prefs = '1,2,3,4'
        data.customer.address.since = '27-11-1988T11:22:33'
        data.customer.address.types = ['a', 'b', 'c', 'd']
        data.customer.address.opaque1 = object()

        input = MyService._sio.parse_input(data, DATA_FORMAT.JSON)
        self.assertIsInstance(input, Bunch)

        self.assertEquals(input.customer.name, data.customer.name)
        self.assertEquals(input.customer.email.value, data.customer.email.value)
        self.assertEquals(input.customer.email.is_business, data.customer.email.is_business)
        self.assertEquals(input.customer.email.join_date, dt_parse(data.customer.email.join_date))
        self.assertListEqual(input.customer.email.preferred_order, data.customer.email.preferred_order)
        self.assertEquals(input.customer.address.locality.type, int(data.customer.address.locality.type))
        self.assertEquals(input.customer.address.locality.name, data.customer.address.locality.name)
        self.assertIs(input.customer.address.locality.coords, data.customer.address.locality.coords)
        self.assertEquals(input.customer.address.locality.geo_skip, decimal_Decimal(data.customer.address.locality.geo_skip))
        self.assertEquals(input.customer.address.locality.geo_diff, float(data.customer.address.locality.geo_diff))
        self.assertEquals(input.customer.address.street_id, uuid_UUID(data.customer.address.street_id))
        self.assertEquals(input.customer.address.prefs, data.customer.address.prefs.split(','))
        self.assertEquals(input.customer.address.since, dt_parse(data.customer.address.since))
        self.assertEquals(input.customer.address.types, data.customer.address.types)
        self.assertIs(input.customer.address.opaque1, data.customer.address.opaque1)
コード例 #5
0
ファイル: test_parsing_input_csv.py プロジェクト: danlg/zato
    def test_parse_all_elem_types(self):
        class MyService(Service):
            class SimpleIO:
                input = 'aaa', AsIs('bbb'), Bool('ccc'), 'ddd', Date('eee'), DateTime('fff'), Decimal('ggg'), \
                    Float('jjj'), Int('mmm'), Opaque('ooo'), Text('ppp'), UUID('qqq')

        CySimpleIO.attach_sio(self.get_server_config(), MyService)

        aaa = 'aaa-111'
        bbb = 'bbb-222-bbb'
        ccc = 'True'
        ddd = ''
        eee = '1999-12-31'
        fff = '1988-01-29T11:22:33.0000Z'
        ggg = '123.456'

        jjj = '111.222'
        mmm = '9090'

        ooo = 'ZZZ-ZZZ-ZZZ'
        ppp = 'mytext'
        qqq = 'd011d054-db4b-4320-9e24-7f4c217af673'

        # Note that 'ddd' is optional and we are free to skip it
        data = ','.join(
            [aaa, bbb, ccc, ddd, eee, fff, ggg, jjj, mmm, ooo, ppp, qqq])

        input = MyService._sio.parse_input(data, DATA_FORMAT.CSV)
        self.assertIsInstance(input, list)
        input = input[0]

        self.assertEquals(input.aaa, aaa)
        self.assertEquals(input.bbb, bbb)
        self.assertTrue(input.ccc)
        self.assertEquals(input.ddd, '')

        self.assertIsInstance(input.eee, datetime)
        self.assertEquals(input.eee.year, 1999)
        self.assertEquals(input.eee.month, 12)
        self.assertEquals(input.eee.day, 31)

        self.assertIsInstance(input.fff, datetime)
        self.assertEquals(input.fff.year, 1988)
        self.assertEquals(input.fff.month, 1)
        self.assertEquals(input.fff.day, 29)

        self.assertEquals(input.ggg, decimal_Decimal(ggg))
        self.assertEquals(input.jjj, float(jjj))
        self.assertEquals(input.mmm, int(mmm))
        self.assertEquals(input.ooo, ooo)
        self.assertEquals(input.ppp, ppp)
        self.assertEquals(input.qqq, uuid_UUID(qqq))
コード例 #6
0
ファイル: monitor.py プロジェクト: seanupton/zc.async
def jobstats(at=None,
             before=None,
             since=None,
             queue=None,
             agent=None,
             uuid=None):
    """Statistics on historical jobs as of last poll.

    Usage:

        jobstats
        (returns statistics on historical jobs as of last poll)

        jobstats queue:<queue name>
        (statistics are filtered to those coming from the named queue)

        jobstats agent:<agent name>
        (statistics are filtered to those coming from agents with given name)

        jobstats at:<poll key or interval>
        (statistics are collected at or before the poll key or interval)

        jobstats before:<pollkey or interval>
        (statistics are collected before the poll key or interval)

        jobstats since:<pollkey or interval>
        (statistics are collected since poll key or interval, inclusive)

    The modifiers "queue:", "agent:", "since:", and one of "at:" or "before:"
    may be combined.

    Intervals are of the format ``[nD][nH][nM][nS]``, where "n" should
    be replaced with a positive integer, and "D," "H," "M," and "S" are
    literals standing for "days," "hours," "minutes," and "seconds."
    For instance, you might use ``5M`` for five minutes, ``20S`` for
    twenty seconds, or ``1H30M`` for an hour and a half.

    Poll keys are the values shown as "key" from the ``poll`` or ``polls``
    command.

    Example:

        async jobstats queue: agent:main since:1H
        (results filtered to queue named '' and agent named 'main' from
         one hour ago till now)"""
    if uuid is not None:
        uuid = uuid_UUID(uuid)
    return zc. async .dispatcher.get(uuid).getStatistics(
        _dt(at), _dt(before), _dt(since), queue, agent)
コード例 #7
0
ファイル: test_response_xml.py プロジェクト: myhighland/zato
    def test_response_all_elem_types(self):

        class MyService(Service):
            class SimpleIO:
                xml_pretty_print = False
                xml_declaration = False
                output = 'aaa', AsIs('bbb'), Bool('ccc'), 'ddd', Date('eee'), DateTime('fff'), Decimal('ggg'), \
                    Float('jjj'), Int('mmm'), Opaque('ooo'), Text('ppp'), UUID('qqq')

        CySimpleIO.attach_sio(self.get_server_config(), MyService)

        aaa = 'aaa-111'
        bbb = 'bbb-222-bbb'
        ccc = True
        ddd = ''
        eee = dt_parse('1999-12-31')
        fff = dt_parse('1988-01-29T11:22:33.0000Z')
        ggg = '123.456'

        jjj = '111.222'
        mmm = '9090'

        ooo = 'ZZZ-ZZZ-ZZZ'
        ppp = 'mytext'
        qqq = uuid_UUID('d011d054-db4b-4320-9e24-7f4c217af673')

        # Note that 'ddd' is optional and we are free to skip it
        data = {
            'aaa': aaa,
            'bbb': bbb,
            'ccc': ccc,
            'ddd': ddd,
            'eee': eee,
            'fff': fff,
            'ggg': ggg,
            'jjj': jjj,
            'mmm': mmm,
            'ooo': ooo,
            'ppp': ppp,
            'qqq': qqq
        }

        result = MyService._sio.get_output(data, DATA_FORMAT.XML)
        self.assertEquals(result, '<response><aaa>aaa-111</aaa><bbb>bbb-222-bbb</bbb><ccc>True</ccc>' \
            '<ddd></ddd><eee>1999-12-31</eee><fff>1988-01-29T11:22:33+00:00</fff>' \
            '<ggg>123.456</ggg><jjj>111.222</jjj><mmm>9090</mmm><ooo>ZZZ-ZZZ-ZZZ</ooo>' \
            '<ppp>mytext</ppp><qqq>d011d054db4b43209e247f4c217af673</qqq></response>')
コード例 #8
0
ファイル: monitor.py プロジェクト: seanupton/zc.async
def polls(at=None, before=None, since=None, count=None, uuid=None):
    """Get information about recent polls, defaulting to most recent.

    Usage:

        polls
        (returns most recent 3 poll)

        polls at:<poll key or interval>
        (returns up to 3 polls at or before the poll key or interval)

        polls before:<poll key or interval>
        (returns up to 3 polls before the poll key or interval)

        polls since:<poll key or interval>
        (returns polls since the poll key or interval, inclusive)

        polls count <positive integer>
        (returns the given number of the most recent files)

    The modifiers "since:", "count:", and one of "at:" or "before:" may
    be combined.

    Intervals are of the format ``[nD][nH][nM][nS]``, where "n" should
    be replaced with a positive integer, and "D," "H," "M," and "S" are
    literals standing for "days," "hours," "minutes," and "seconds."
    For instance, you might use ``5M`` for five minutes, ``20S`` for
    twenty seconds, or ``1H30M`` for an hour and a half.

    Example:

        async polls since:10M before:5M
        (get the poll information from 10 to 5 minutes ago)"""
    if uuid is not None:
        uuid = uuid_UUID(uuid)
    if count is None:
        if since is None:
            count = 3
    else:
        count = int(count)
    return [{
        'key': p.key,
        'time': p.utc_timestamp.isoformat() + "Z",
        'results': p
    } for p in zc. async .dispatcher.get(uuid).iterPolls(
        _dt(at), _dt(before), _dt(since), count)]
コード例 #9
0
    def uniq_id(self):
        device_id = ''
        mac_addr = xbmc.getInfoLabel('Network.MacAddress')

        # hack response busy
        i = 0
        while not py2_encode(':') in mac_addr and i < 3:
            i += 1
            time_sleep(1)
            mac_addr = xbmc.getInfoLabel('Network.MacAddress')
        if py2_encode(':') in mac_addr:
            device_id = str(
                uuid_UUID(hashlib_md5(mac_addr.encode('utf-8')).hexdigest()))
        else:
            self.log('[{0}] error: failed to get device id ({1})'.format(
                self.addon_id, str(mac_addr)))
            self.dialog_ok('Geräte-Id konnte nicht ermittelt werden.')
        return device_id
コード例 #10
0
ファイル: monitor.py プロジェクト: seanupton/zc.async
def job(OID, database=None, uuid=None):
    """Local information about a job as of last poll, if known.

    Does not consult ZODB, but in-memory information.

    Usage:

        job <job id>
        (returns information about the job)

        job <job id> database:<database name>
        (returns job information, with job id disambiguated by database name)

    The job id in this case is an integer such as those returned by the
    ``async jobs`` command or in the ``longest ...`` and ``shortest ...``
    values of the ``async jobstats`` command.  It is the integer version of the
    oid of the job, and can be converted to an oid with ``ZODB.utils.p64``, and
    converted back to an integer with ``ZODB.utils.u64``.
    """
    if uuid is not None:
        uuid = uuid_UUID(uuid)
    return zc. async .dispatcher.get(uuid).getJobInfo(long(OID), database)
コード例 #11
0
ファイル: monitor.py プロジェクト: seanupton/zc.async
def jobs(queue=None, agent=None, uuid=None):
    """Show active jobs in worker threads as of the instant.

    Usage:

        jobs
        (returns active jobs as of last poll, newest to oldest)

        jobs queue:<queue name>
        (jobs are filtered to those coming from the named queue)

        jobs agent:<agent name>
        (jobs are filtered to those coming from agents with given name)

    "queue:" and "agent:" modifiers may be combined.

    Example:

        async jobs queue: agent:main
        (results filtered to queue named '' and agent named 'main')"""
    if uuid is not None:
        uuid = uuid_UUID(uuid)
    return zc. async .dispatcher.get(uuid).getActiveJobIds(queue, agent)
コード例 #12
0
ファイル: test_intUtils.py プロジェクト: kats/idx
 def testConversion(self):
     u = uuid_UUID(bytes_le = sample_UUID)
     ints = unpack_from('=QQ', sample_UUID)
     ints2 = uuid2searchInts(u) 
     self.assertEqual(ints, ints2)
コード例 #13
0
ファイル: test_parsing_input_xml.py プロジェクト: danlg/zato
    def test_parse_all_elem_types_non_list(self):
        class MyService(Service):
            class SimpleIO:
                input = 'aaa', AsIs('bbb'), Bool('ccc'), CSV('ddd'), Date('eee'), DateTime('fff'), Decimal('ggg'), \
                    Float('jjj'), Int('mmm'), Opaque('ooo'), Text('ppp'), UUID('qqq')

        CySimpleIO.attach_sio(self.get_server_config(), MyService)

        aaa = 'aaa-111'
        bbb = 'bbb-222-bbb'
        ccc = True
        ddd = '1,2,3,4'
        eee = '1999-12-31'
        fff = '1988-01-29T11:22:33.0000Z'
        ggg = '123.456'

        jjj = '111.222'
        mmm = '9090'

        ooo = 'ZZZ-ZZZ-ZZZ'
        ppp = 'mytext'
        qqq = 'd011d054-db4b-4320-9e24-7f4c217af673'

        # Note that 'ddd' is optional and we are free to skip it
        data = lxml_fromstring("""<?xml version="1.0"?><root>
            <aaa>{}</aaa>
            <bbb>{}</bbb>
            <ccc>{}</ccc>
            <ddd>{}</ddd>
            <eee>{}</eee>
            <fff>{}</fff>
            <ggg>{}</ggg>
            <jjj>{}</jjj>
            <mmm>{}</mmm>
            <ooo>{}</ooo>
            <ppp>{}</ppp>
            <qqq>{}</qqq>
        </root>
        """.format(aaa, bbb, ccc, ddd, eee, fff, ggg, jjj, mmm, ooo, ppp, qqq))

        input = MyService._sio.parse_input(data, DATA_FORMAT.XML)
        self.assertIsInstance(input, Bunch)

        self.assertEquals(input.aaa, aaa)
        self.assertEquals(input.bbb, bbb)
        self.assertTrue(input.ccc)
        self.assertListEqual(input.ddd, ['1', '2', '3', '4'])

        self.assertIsInstance(input.eee, datetime)
        self.assertEquals(input.eee.year, 1999)
        self.assertEquals(input.eee.month, 12)
        self.assertEquals(input.eee.day, 31)

        self.assertIsInstance(input.fff, datetime)
        self.assertEquals(input.fff.year, 1988)
        self.assertEquals(input.fff.month, 1)
        self.assertEquals(input.fff.day, 29)

        self.assertEquals(input.ggg, decimal_Decimal(ggg))
        self.assertEquals(input.jjj, float(jjj))
        self.assertEquals(input.mmm, int(mmm))
        self.assertEquals(input.ooo, ooo)
        self.assertEquals(input.ppp, ppp)
        self.assertEquals(input.qqq, uuid_UUID(qqq))