Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add order options to verdi process list #3004

Merged
merged 4 commits into from Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions aiida/backends/tests/cmdline/commands/test_process.py
Expand Up @@ -166,12 +166,37 @@ def setUp(self):

def test_list(self):
"""Test the list command."""
# pylint: disable=too-many-branches

# Default behavior should yield all active states (CREATED, RUNNING and WAITING) so six in total
result = self.cli_runner.invoke(cmd_process.process_list, ['-r'])
self.assertIsNone(result.exception, result.output)
self.assertEqual(len(get_result_lines(result)), 6)

# Ordering shouldn't change the number of results,
for flag in ['-O', '--order-by']:
for flag_value in ['id', 'ctime']:
result = self.cli_runner.invoke(cmd_process.process_list, ['-r', flag, flag_value])
self.assertIsNone(result.exception, result.output)
self.assertEqual(len(get_result_lines(result)), 6)

# but the orders should be inverse
for flag in ['-D', '--order-direction']:

flag_value = 'asc'
result = self.cli_runner.invoke(cmd_process.process_list, ['-r', '-O', 'id', flag, flag_value])
self.assertIsNone(result.exception, result.output)
result_num_asc = [l.split()[0] for l in get_result_lines(result)]
self.assertEqual(len(result_num_asc), 6)

flag_value = 'desc'
result = self.cli_runner.invoke(cmd_process.process_list, ['-r', '-O', 'id', flag, flag_value])
self.assertIsNone(result.exception, result.output)
result_num_desc = [l.split()[0] for l in get_result_lines(result)]
self.assertEqual(len(result_num_desc), 6)

self.assertEqual(result_num_asc, list(reversed(result_num_desc)))

# Adding the all option should return all entries regardless of process state
for flag in ['-a', '--all']:
result = self.cli_runner.invoke(cmd_process.process_list, ['-r', flag])
Expand Down
9 changes: 7 additions & 2 deletions aiida/cmdline/commands/cmd_process.py
Expand Up @@ -33,6 +33,8 @@ def verdi_process():
@verdi_process.command('list')
@options.PROJECT(
type=click.Choice(CalculationQueryBuilder.valid_projections), default=CalculationQueryBuilder.default_projections)
@options.ORDER_BY()
@options.ORDER_DIRECTION()
@options.GROUP(help='Only include entries that are a member of this group.')
@options.ALL(help='Show all entries, regardless of their process state.')
@options.PROCESS_STATE()
Expand All @@ -42,8 +44,10 @@ def verdi_process():
@options.LIMIT()
@options.RAW()
@decorators.with_dbenv()
def process_list(all_entries, group, process_state, exit_status, failed, past_days, limit, project, raw):
def process_list(all_entries, group, process_state, exit_status, failed, past_days, limit, project, raw, order_by,
order_dir):
"""Show a list of processes that are still running."""
# pylint: disable=too-many-locals
from tabulate import tabulate
from aiida.cmdline.utils.common import print_last_process_state_change, check_worker_load

Expand All @@ -54,7 +58,8 @@ def process_list(all_entries, group, process_state, exit_status, failed, past_da

builder = CalculationQueryBuilder()
filters = builder.get_filters(all_entries, process_state, exit_status, failed)
query_set = builder.get_query_set(relationships=relationships, filters=filters, past_days=past_days, limit=limit)
query_set = builder.get_query_set(
relationships=relationships, filters=filters, order_by={order_by: order_dir}, past_days=past_days, limit=limit)
projected = builder.get_projected(query_set, projections=project)

headers = projected.pop(0)
Expand Down
5 changes: 5 additions & 0 deletions aiida/cmdline/params/options/__init__.py
Expand Up @@ -280,6 +280,11 @@ def active_process_states():
type=click.Choice(['id', 'ctime']), default='ctime', show_default=True,
help='Order the entries by this attribute.')

ORDER_DIRECTION = OverridableOption(
'-D', '--order-direction', 'order_dir',
type=click.Choice(['asc', 'desc']), default='asc', show_default=True,
help='List the entries in ascending or descending order')

PAST_DAYS = OverridableOption(
'-p', '--past-days', 'past_days',
type=click.INT, metavar='PAST_DAYS',
Expand Down