From 198fbbb4658b26c92c116b447914b235db4ad93b Mon Sep 17 00:00:00 2001 From: Leopold Talirz Date: Thu, 28 Nov 2019 15:20:54 +0100 Subject: [PATCH] print path to config file in verdi status From time to time, the need arises to have a look inside the currently active AiiDA configuration file. While the path to the file repository is printed in the output of `verdi status` and `verdi profile show`, one needs to edit this path to get to the config file (and, in principle, the repository can even be located comepletely elsewhere). Printing the location of the config file is helpful for daily use, also as a reminder which configuration file is currently active. --- aiida/cmdline/commands/cmd_profile.py | 3 ++- aiida/cmdline/commands/cmd_status.py | 6 +++++- aiida/manage/configuration/__init__.py | 13 ++++++++++--- tests/cmdline/commands/test_status.py | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/aiida/cmdline/commands/cmd_profile.py b/aiida/cmdline/commands/cmd_profile.py index 8d5563139e..6ac1671237 100644 --- a/aiida/cmdline/commands/cmd_profile.py +++ b/aiida/cmdline/commands/cmd_profile.py @@ -52,10 +52,11 @@ def profile_list(): @arguments.PROFILE(default=defaults.get_default_profile) def profile_show(profile): """Show details for a profile.""" + if profile is None: echo.echo_critical('no profile to show') - echo.echo_info('Configuration for: {}'.format(profile.name)) + echo.echo_info('Profile: {}'.format(profile.name)) data = sorted([(k.lower(), v) for k, v in profile.dictionary.items()]) echo.echo(tabulate.tabulate(data)) diff --git a/aiida/cmdline/commands/cmd_status.py b/aiida/cmdline/commands/cmd_status.py index 312e8d2b9b..74a597f45e 100644 --- a/aiida/cmdline/commands/cmd_status.py +++ b/aiida/cmdline/commands/cmd_status.py @@ -49,12 +49,16 @@ def verdi_status(): from aiida.common.utils import Capturing from aiida.manage.external.rmq import get_rmq_url from aiida.manage.manager import get_manager + from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER exit_code = ExitCode.SUCCESS + + # path to configuration file + print_status(ServiceStatus.UP, 'config dir', AIIDA_CONFIG_FOLDER) + manager = get_manager() profile = manager.get_profile() - # getting the profile try: profile = manager.get_profile() print_status(ServiceStatus.UP, 'profile', 'On profile {}'.format(profile.name)) diff --git a/aiida/manage/configuration/__init__.py b/aiida/manage/configuration/__init__.py index 695666bf6b..2b5618f394 100644 --- a/aiida/manage/configuration/__init__.py +++ b/aiida/manage/configuration/__init__.py @@ -22,7 +22,7 @@ __all__ = ( config.__all__ + options.__all__ + profile.__all__ + - ('get_config', 'get_config_option', 'load_profile', 'reset_config') + ('get_config', 'get_config_option', 'get_config_path', 'load_profile', 'reset_config') ) @@ -66,6 +66,14 @@ def load_profile(profile=None): return PROFILE +def get_config_path(): + """Returns path to .aiida configuration directory.""" + import os + from .settings import AIIDA_CONFIG_FOLDER, DEFAULT_CONFIG_FILE_NAME + + return os.path.join(AIIDA_CONFIG_FOLDER, DEFAULT_CONFIG_FILE_NAME) + + def load_config(create=False): """Instantiate Config object representing an AiiDA configuration file. @@ -82,9 +90,8 @@ def load_config(create=False): import os from aiida.common import exceptions from .config import Config - from .settings import AIIDA_CONFIG_FOLDER, DEFAULT_CONFIG_FILE_NAME - filepath = os.path.join(AIIDA_CONFIG_FOLDER, DEFAULT_CONFIG_FILE_NAME) + filepath = get_config_path() if not os.path.isfile(filepath) and not create: raise exceptions.MissingConfigurationError('configuration file {} does not exist'.format(filepath)) diff --git a/tests/cmdline/commands/test_status.py b/tests/cmdline/commands/test_status.py index 145d6b5095..f76ba44e2b 100644 --- a/tests/cmdline/commands/test_status.py +++ b/tests/cmdline/commands/test_status.py @@ -33,6 +33,7 @@ def test_status_1(self): options = [] result = self.cli_runner.invoke(cmd_status.verdi_status, options) self.assertIsInstance(result.exception, SystemExit) + self.assertIn('config', result.output) self.assertIn('profile', result.output) self.assertIn('postgres', result.output) self.assertIn('rabbitmq', result.output)