Example #1
0
    def show(self, id, sort, current):

        deferred = Tasks.client.get_tasks(id)
        result = sync_wait(deferred)

        if not id:
            values = []

            if current:
                result = [
                    t for t in result if TaskStatus(t['status']).is_active()
                ]

            for task in result:
                values.append([
                    task['id'],
                    Tasks.__format_seconds(task['time_remaining']),
                    str(task['subtasks_count']), task['status'],
                    Tasks.__progress_str(task['progress'])
                ])

            return CommandResult.to_tabular(Tasks.task_table_headers,
                                            values,
                                            sort=sort)

        if isinstance(result, dict):
            result['time_remaining'] = \
                Tasks.__format_seconds(result['time_remaining'])
            result['progress'] = Tasks.__progress_str(result['progress'])

        return result
Example #2
0
def payments(sort):

    deferred = payments.client.get_payments_list()
    result = sync_wait(deferred) or []

    values = []

    for payment in result:

        payment_value = float(payment["value"])
        payment_fee = payment["fee"] or u""

        if payment_fee:
            payment_fee = u"{:.1f}%".format(float(payment_fee) * 100 /
                                            payment_value)

        entry = [
            payment["subtask"],
            payment["payee"].encode('hex'),
            __status(payment),
            __value(payment_value),
            payment_fee
        ]

        values.append(entry)

    return CommandResult.to_tabular(payments_table_headers, values, sort=sort)
Example #3
0
def payments(sort, status):

    deferred = payments.client.get_payments_list()
    result = sync_wait(deferred) or []

    values = []
    if status is not None:
        result = filter_by_status(result, status)

    for payment in result:

        payment_value = float(payment["value"])
        payment_fee = payment["fee"] or ""

        if payment_fee:
            payment_fee = __value(payment_fee, "ETH")

        entry = [
            to_unicode(payment["subtask"]),
            to_unicode(payment["payee"]),
            to_unicode(payment["status"]),
            __value(payment_value, "GNT"),
            to_unicode(payment_fee)
        ]

        values.append(entry)

    return CommandResult.to_tabular(payments_table_headers, values, sort=sort)
Example #4
0
    def test_command_formatter(self):
        formatter = CommandFormatter()

        for prettify in [True, False]:
            formatter.prettify = prettify

            self.assertIsNone(formatter.format(None))
            self.assertIsNone(formatter.format(''))
            self.assertEqual(formatter.format('Some text'), 'Some text')

            if not prettify:
                self.assertEqual(formatter.format(formatter),
                                 DictSerializer.dump(formatter, typed=False))

        table_headers = ['First', 'Second', 'Third']
        table_values = [
            ['value 1', 'value 2', 'value 3'],
            ['value 1', 'value 2', 'value 3'],
            ['value 1', 'value 2', 'value 3'],
        ]

        tabular_result = CommandResult.to_tabular(table_headers, table_values)
        tabular_repr = formatter.format(tabular_result)
        tabular_data_repr = formatter.format(tabular_result.from_tabular())

        self.assertIsNotNone(tabular_repr)
        self.assertIsNotNone(tabular_data_repr)
        self.assertNotEqual(tabular_data_repr, tabular_repr)
Example #5
0
    def test_tabular(self):

        headers = ['1', '2', '3']
        values = [
            ['d', 'b', 'f'],
            ['a', 'e', 'c'],
        ]

        tabular = CommandResult.to_tabular(headers, values)

        self.assertEqual(tabular.data, (headers, values))
        self.assertEqual(tabular.type, CommandResult.TABULAR)
        self.assertEqual(tabular.from_tabular(), (headers, values))

        tabular = CommandResult.to_tabular(headers, values, sort='4')

        self.assertEqual(tabular.from_tabular()[1], values)

        tabular = CommandResult.to_tabular(headers, values, sort='1')

        self.assertNotEqual(tabular.from_tabular()[1], values)
        self.assertEqual(tabular.from_tabular()[1], [
            ['a', 'e', 'c'],
            ['d', 'b', 'f'],
        ])

        tabular = CommandResult.to_tabular(headers, values, sort='2')

        self.assertEqual(tabular.from_tabular()[1], values)

        tabular = CommandResult.to_tabular(headers, values, sort='3')

        self.assertNotEqual(tabular.from_tabular()[1], values)
        self.assertEqual(tabular.from_tabular()[1], [
            ['a', 'e', 'c'],
            ['d', 'b', 'f'],
        ])

        CommandResult.type = CommandResult.NONE
        with self.assertRaises(TypeError):
            CommandResult.from_tabular()
        CommandResult.type = CommandResult.TABULAR
Example #6
0
    def __peers(peers, sort, full):
        values = []

        for peer in peers:
            values.append([
                str(peer['address']),
                str(peer['port']),
                Network.__key_id(peer['key_id'], full),
                unicode(peer['node_name'])
            ])

        return CommandResult.to_tabular(Network.node_table_headers,
                                        values,
                                        sort=sort)
Example #7
0
def incomes(sort):
    deferred = incomes.client.get_incomes_list()
    result = sync_wait(deferred) or []

    values = []

    for income in result:
        entry = [
            income["payer"].encode('hex'),
            __status(income),
            __value(float(income["value"])),
            str(income["block_number"])
        ]
        values.append(entry)

    return CommandResult.to_tabular(payments_table_headers, values, sort=sort)
Example #8
0
    def subtasks(self, id, sort):
        values = []

        deferred = Tasks.client.get_subtasks(id)
        result = sync_wait(deferred)

        if isinstance(result, list):
            for subtask in result:
                values.append([
                    subtask['node_name'], subtask['subtask_id'],
                    str(subtask['time_remaining']), subtask['status'],
                    Tasks.__progress_str(subtask['progress'])
                ])

        return CommandResult.to_tabular(Tasks.subtask_table_headers,
                                        values,
                                        sort=sort)
Example #9
0
def incomes(sort, status):
    deferred = incomes.client.get_incomes_list()
    result = sync_wait(deferred) or []

    values = []
    if status is not None:
        result = filter_by_status(result, status)

    for income in result:
        entry = [
            to_unicode(income["payer"]),
            to_unicode(income["status"]),
            __value(float(income["value"]), "GNT"),
        ]
        values.append(entry)

    return CommandResult.to_tabular(incomes_table_headers, values, sort=sort)
Example #10
0
    def test_command_formatter_table_format(self):
        formatter = CommandFormatter()

        table_headers = ['First', 'Second', 'Third']
        table_values = [
            ['value 1', 'value 2', 'value 3'],
            ['value 1', 'value 2', 'value 3'],
            ['value 1', 'value 2', 'value 3'],
        ]

        tabular_result = CommandResult.to_tabular(table_headers, table_values)
        tabular_repr = formatter.format(tabular_result)
        tabular_data_repr = formatter.format(tabular_result.from_tabular())

        self.assertIsNotNone(tabular_repr)
        self.assertIsNotNone(tabular_data_repr)
        self.assertNotEqual(tabular_data_repr, tabular_repr)
Example #11
0
    def __peers(peers, sort, full):
        values = []

        for p in peers:
            addr = Network.__one_of(p, 'address', 'pub_addr')
            port = Network.__one_of(p, 'port', 'p2p_pub_port', 'p2p_prv_port')
            key = Network.__one_of(p, 'key_id', 'key')

            values.append([
                str(addr),
                str(port),
                Network.__key_id(key, full),
                str(p['node_name']),
            ])

        return CommandResult.to_tabular(Network.node_table_headers,
                                        values,
                                        sort=sort)
Example #12
0
    def show(self, sort):

        deferred = Environments.client.get_environments()
        result = sync_wait(deferred) or []

        values = []

        for env in result:
            values.append([
                env['id'],
                str(env['supported']),
                str(env['accepted']),
                str(env['performance']),
                env['description']
            ])

        return CommandResult.to_tabular(Environments.table_headers, values,
                                        sort=sort)
Example #13
0
    def show(self, id, sort):

        deferred = Tasks.client.get_tasks(id)
        result = sync_wait(deferred)

        if not id:
            values = []

            for task in result or []:
                values.append([
                    task['id'],
                    str(task['time_remaining']),
                    str(task['subtasks']), task['status'],
                    Tasks.__progress_str(task['progress'])
                ])

            return CommandResult.to_tabular(Tasks.task_table_headers,
                                            values,
                                            sort=sort)

        if isinstance(result, dict):
            result['progress'] = Tasks.__progress_str(result['progress'])

        return result
Example #14
0
 def unsupport(self, last_days):
     deferred = Tasks.client.get_unsupport_reasons(int(last_days))
     result = sync_wait(deferred)
     values = [[r['reason'], r['ntasks'], r['avg']] for r in result]
     return CommandResult.to_tabular(Tasks.unsupport_reasons_table_headers,
                                     values)
Example #15
0
 def show(self):
     res = sync_wait(Resources.client.get_res_dirs_sizes(), timeout=None)
     return CommandResult.to_tabular(list(res.keys()), [list(res.values())])