Skip to content
Snippets Groups Projects
Commit 17fb11aa authored by matograine's avatar matograine Committed by Moul
Browse files

[enh] wot: Migrate from tabulate to texttable (#203)

parent 2e12cdae
No related branches found
No related tags found
1 merge request!199#203: Harmonize tables style using Texttable
...@@ -20,14 +20,13 @@ from typing import Dict, List, Tuple ...@@ -20,14 +20,13 @@ from typing import Dict, List, Tuple
import click import click
from duniterpy.api.bma import blockchain, wot from duniterpy.api.bma import blockchain, wot
from pendulum import from_timestamp, now from pendulum import from_timestamp, now
from tabulate import tabulate
from silkaj import wot_tools as wt from silkaj import wot_tools as wt
from silkaj.blockchain_tools import get_blockchain_parameters from silkaj.blockchain_tools import get_blockchain_parameters
from silkaj.constants import DATE from silkaj.constants import DATE
from silkaj.crypto_tools import is_pubkey_and_check from silkaj.crypto_tools import is_pubkey_and_check
from silkaj.network_tools import client_instance, exit_on_http_error from silkaj.network_tools import client_instance, exit_on_http_error
from silkaj.tui import gen_pubkey_checksum from silkaj.tui import Table, gen_pubkey_checksum
def get_sent_certifications( def get_sent_certifications(
...@@ -78,6 +77,8 @@ def received_sent_certifications(uid_pubkey: str) -> None: ...@@ -78,6 +77,8 @@ def received_sent_certifications(uid_pubkey: str) -> None:
certifications["received_expire"] = [] certifications["received_expire"] = []
certifications["received"] = [] certifications["received"] = []
certifications["sent"] = []
certifications["sent_expire"] = []
for cert in identity["others"]: for cert in identity["others"]:
certifications["received_expire"].append( certifications["received_expire"].append(
expiration_date_from_block_id( expiration_date_from_block_id(
...@@ -92,15 +93,16 @@ def received_sent_certifications(uid_pubkey: str) -> None: ...@@ -92,15 +93,16 @@ def received_sent_certifications(uid_pubkey: str) -> None:
certifications["sent_expire"], certifications["sent_expire"],
) = get_sent_certifications(signed, time_first_block, params) ) = get_sent_certifications(signed, time_first_block, params)
nbr_sent_certs = len(certifications["sent"]) if "sent" in certifications else 0 nbr_sent_certs = len(certifications["sent"]) if "sent" in certifications else 0
table = tabulate(
certifications, headers="keys", tablefmt="orgtbl", stralign="right" table = Table(style="columns").set_cols_align(["r", "r", "r", "r"])
) table.fill_from_dict(certifications)
print( print(
f'{identity["uid"]} ({gen_pubkey_checksum(pubkey, True)}) \ f'{identity["uid"]} ({gen_pubkey_checksum(pubkey, True)}) \
from block #{identity["meta"]["timestamp"][:15]}\n\ from block #{identity["meta"]["timestamp"][:15]}\n\
received {len(certifications["received"])} and \ received {len(certifications["received"])} and sent \
sent {nbr_sent_certs}/{params["sigStock"]} certifications:\n\ {nbr_sent_certs}/{params["sigStock"]} certifications:\n\
{table}\n\ {table.draw()}\n\
✔: Certification available to be written or already written into the blockchain\n' ✔: Certification available to be written or already written into the blockchain\n'
) )
membership_status(certifications, pubkey, req) membership_status(certifications, pubkey, req)
...@@ -203,9 +205,9 @@ def choose_identity(pubkey_uid: str) -> Tuple[Dict, str, List]: ...@@ -203,9 +205,9 @@ def choose_identity(pubkey_uid: str) -> Tuple[Dict, str, List]:
pubkey_index = 0 pubkey_index = 0
uid_index = 0 uid_index = 0
elif identities > 1: elif identities > 1:
table = tabulate(identities_choices, headers="keys", tablefmt="orgtbl") table = Table().set_cols_dtype(["t", "t", "t", "t"])
click.echo(table) table.fill_from_dict(identities_choices)
click.echo(table.draw())
# Loop till the passed value is in identities_choices # Loop till the passed value is in identities_choices
message = "Which identity would you like to select (id)?" message = "Which identity would you like to select (id)?"
selected_id = None selected_id = None
......
...@@ -19,9 +19,7 @@ from click.testing import CliRunner ...@@ -19,9 +19,7 @@ from click.testing import CliRunner
from silkaj.cli import cli from silkaj.cli import cli
from silkaj.constants import FAILURE_EXIT_STATUS from silkaj.constants import FAILURE_EXIT_STATUS
from silkaj.money import get_sources from silkaj.money import get_sources
from silkaj.tui import gen_pubkey_checksum
# had to import from wot to prevent loop dependencies
from silkaj.wot import gen_pubkey_checksum
def test_get_sources(monkeypatch): def test_get_sources(monkeypatch):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment