-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release v0.4.0: node account info, list of blocks, batch status by id…
…entifier commands (#55)
- Loading branch information
1 parent
a8a5079
commit 6eaa1fc
Showing
79 changed files
with
5,436 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
""" | ||
Provide implementation of the command line interface's batch commands. | ||
""" | ||
import sys | ||
|
||
import click | ||
from remme import Remme | ||
|
||
from cli.batch.forms import ( | ||
GetBatchesListForm, | ||
GetBatchForm, | ||
GetBatchStatusForm, | ||
) | ||
from cli.batch.help import ( | ||
BATCH_IDENTIFIER_ARGUMENT_HELP_MESSAGE, | ||
BATCH_STATUS_IDENTIFIER_ARGUMENT_HELP_MESSAGE, | ||
BATCHES_HEAD_ARGUMENT_HELP_MESSAGE, | ||
BATCHES_IDENTIFIERS_ARGUMENT_HELP_MESSAGE, | ||
BATCHES_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE, | ||
BATCHES_LIMIT_ARGUMENT_HELP_MESSAGE, | ||
BATCHES_REVERSE_ARGUMENT_HELP_MESSAGE, | ||
BATCHES_START_ARGUMENT_HELP_MESSAGE, | ||
) | ||
from cli.batch.service import Batch | ||
from cli.constants import ( | ||
FAILED_EXIT_FROM_COMMAND_CODE, | ||
NODE_URL_ARGUMENT_HELP_MESSAGE, | ||
) | ||
from cli.utils import ( | ||
default_node_url, | ||
print_errors, | ||
print_result, | ||
) | ||
|
||
|
||
@click.group('batch', chain=True) | ||
def batch_commands(): | ||
""" | ||
Provide commands for working with batch. | ||
""" | ||
pass | ||
|
||
|
||
@click.option('--id', required=True, type=str, help=BATCH_IDENTIFIER_ARGUMENT_HELP_MESSAGE) | ||
@click.option('--node-url', required=False, type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url()) | ||
@batch_commands.command('get') | ||
def get_batch(id, node_url): | ||
""" | ||
Get a batch by its identifier. | ||
""" | ||
arguments, errors = GetBatchForm().load({ | ||
'id': id, | ||
'node_url': node_url, | ||
}) | ||
|
||
if errors: | ||
print_errors(errors=errors) | ||
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE) | ||
|
||
batch_id = arguments.get('id') | ||
node_url = arguments.get('node_url') | ||
|
||
remme = Remme(network_config={ | ||
'node_address': str(node_url) + ':8080', | ||
}) | ||
|
||
batch, errors = Batch(service=remme).get(id=batch_id) | ||
|
||
if errors is not None: | ||
print_errors(errors=errors) | ||
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE) | ||
|
||
print_result(result=batch) | ||
|
||
|
||
@click.option('--id', required=True, type=str, help=BATCH_STATUS_IDENTIFIER_ARGUMENT_HELP_MESSAGE) | ||
@click.option('--node-url', required=False, type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url()) | ||
@batch_commands.command('get-status') | ||
def get_batch_status(id, node_url): | ||
""" | ||
Get a batch status by its identifier. | ||
""" | ||
arguments, errors = GetBatchStatusForm().load({ | ||
'id': id, | ||
'node_url': node_url, | ||
}) | ||
|
||
if errors: | ||
print_errors(errors=errors) | ||
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE) | ||
|
||
batch_id = arguments.get('id') | ||
node_url = arguments.get('node_url') | ||
|
||
remme = Remme(network_config={ | ||
'node_address': str(node_url) + ':8080', | ||
}) | ||
|
||
result, errors = Batch(service=remme).get_status(id=batch_id) | ||
|
||
if errors is not None: | ||
print_errors(errors=errors) | ||
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE) | ||
|
||
print_result(result=result) | ||
|
||
|
||
@click.option('--ids', required=False, type=str, help=BATCHES_IDENTIFIERS_ARGUMENT_HELP_MESSAGE) | ||
@click.option('--start', required=False, type=str, help=BATCHES_START_ARGUMENT_HELP_MESSAGE) | ||
@click.option('--limit', required=False, type=int, help=BATCHES_LIMIT_ARGUMENT_HELP_MESSAGE) | ||
@click.option('--head', required=False, type=str, help=BATCHES_HEAD_ARGUMENT_HELP_MESSAGE) | ||
@click.option('--reverse', required=False, is_flag=True, help=BATCHES_REVERSE_ARGUMENT_HELP_MESSAGE) | ||
@click.option('--ids-only', required=False, is_flag=True, help=BATCHES_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE) | ||
@click.option('--node-url', required=False, type=str, help=NODE_URL_ARGUMENT_HELP_MESSAGE, default=default_node_url()) | ||
@batch_commands.command('get-list') | ||
def get_batches(ids, start, limit, head, reverse, ids_only, node_url): | ||
""" | ||
Get a list of batches. | ||
""" | ||
arguments, errors = GetBatchesListForm().load({ | ||
'ids': ids, | ||
'start': start, | ||
'limit': limit, | ||
'head': head, | ||
'reverse': reverse, | ||
'ids_only': ids_only, | ||
'node_url': node_url, | ||
}) | ||
|
||
if errors: | ||
print_errors(errors=errors) | ||
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE) | ||
|
||
batch_ids = arguments.get('ids') | ||
start = arguments.get('start') | ||
limit = arguments.get('limit') | ||
head = arguments.get('head') | ||
reverse = arguments.get('reverse') | ||
ids_only = arguments.get('ids_only') | ||
node_url = arguments.get('node_url') | ||
|
||
remme = Remme(network_config={ | ||
'node_address': str(node_url) + ':8080', | ||
}) | ||
|
||
if ids_only: | ||
result, errors = Batch(service=remme).get_list_ids( | ||
ids=batch_ids, start=start, limit=limit, head=head, reverse=reverse, | ||
) | ||
else: | ||
result, errors = Batch(service=remme).get_list( | ||
ids=batch_ids, start=start, limit=limit, head=head, reverse=reverse, | ||
) | ||
|
||
if errors is not None: | ||
print_errors(errors=errors) | ||
sys.exit(FAILED_EXIT_FROM_COMMAND_CODE) | ||
|
||
print_result(result=result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
Provide forms for command line interface's batch commands. | ||
""" | ||
from marshmallow import ( | ||
Schema, | ||
fields, | ||
validate, | ||
) | ||
|
||
from cli.generic.forms.fields import ( | ||
BatchIdentifierField, | ||
BatchIdentifiersListField, | ||
NodeUrlField, | ||
) | ||
|
||
|
||
class GetBatchForm(Schema): | ||
""" | ||
Get a batch by its identifier form. | ||
""" | ||
|
||
id = BatchIdentifierField(required=True) | ||
node_url = NodeUrlField(required=True) | ||
|
||
|
||
class GetBatchStatusForm(Schema): | ||
""" | ||
Get a batch status by its identifier form. | ||
""" | ||
|
||
id = BatchIdentifierField(required=True) | ||
node_url = NodeUrlField(required=True) | ||
|
||
|
||
class GetBatchesListForm(Schema): | ||
""" | ||
Get a list of batches form. | ||
""" | ||
|
||
ids = BatchIdentifiersListField(allow_none=True, required=False) | ||
start = BatchIdentifierField(allow_none=True, required=False) | ||
head = BatchIdentifierField(allow_none=True, required=False) | ||
limit = fields.Integer( | ||
allow_none=True, | ||
strict=True, | ||
required=False, | ||
validate=[ | ||
validate.Range(min=1, error='Limit must be greater than 0.'), | ||
], | ||
) | ||
reverse = fields.Boolean(required=False) | ||
ids_only = fields.Boolean(required=False) | ||
node_url = NodeUrlField(required=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" | ||
Provide help messages for command line interface's batch commands. | ||
""" | ||
BATCH_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Identifier to get a batch by.' | ||
BATCH_STATUS_IDENTIFIER_ARGUMENT_HELP_MESSAGE = 'Identifier to get a batch status by.' | ||
BATCHES_IDENTIFIERS_ARGUMENT_HELP_MESSAGE = 'Identifiers to get a list of batches by.' | ||
BATCHES_START_ARGUMENT_HELP_MESSAGE = 'Batch identifier to get a list of batches starting from.' | ||
BATCHES_LIMIT_ARGUMENT_HELP_MESSAGE = 'Maximum amount of batches to return.' | ||
BATCHES_HEAD_ARGUMENT_HELP_MESSAGE = 'Block identifier to get a list of batches to.' | ||
BATCHES_REVERSE_ARGUMENT_HELP_MESSAGE = 'Parameter to reverse result.' | ||
BATCHES_IDENTIFIERS_ONLY_ARGUMENT_HELP_MESSAGE = 'The flag to get a list of batches\' identifiers.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
Provide implementation of the batch interfaces. | ||
""" | ||
|
||
|
||
class BatchInterface: | ||
""" | ||
Implements batch interface. | ||
""" | ||
|
||
def get(self, id): | ||
""" | ||
Get a batch by its identifier. | ||
Arguments: | ||
id (string, required): batch identifier. | ||
""" | ||
pass | ||
|
||
def get_status(self, id): | ||
""" | ||
Get a batch status by its identifier. | ||
Arguments: | ||
id (string, required): batch identifier. | ||
""" | ||
pass | ||
|
||
def get_list(self, ids, start, limit, head, reverse): | ||
""" | ||
Get a list of batches. | ||
A list of batches could be filtered by batch identifiers, start identifier, limit, head identifier, | ||
reverse. | ||
Arguments: | ||
ids (list, optional): identifiers to get a list of batches by. | ||
start (string, optional): batch identifier to get a list of batches starting from. | ||
limit (int, optional): maximum amount of batches to return. | ||
head (string, optional): block identifier to get a list of batches from. | ||
reverse (bool, optional): parameter to reverse result. | ||
""" | ||
pass | ||
|
||
def get_list_ids(self, ids, start, limit, head, reverse): | ||
""" | ||
Get a list of batches' identifiers. | ||
A list of batch identifiers could be filtered by batch identifiers, start identifier, limit, head identifier, | ||
reverse. | ||
Arguments: | ||
ids (list, optional): identifiers to get a list of batches by. | ||
start (string, optional): batch identifier to get a list of batches starting from. | ||
limit (int, optional): maximum amount of batches to return. | ||
head (string, optional): block identifier to get a list of batches from. | ||
reverse (bool, optional): parameter to reverse result. | ||
""" | ||
pass |
Oops, something went wrong.