From f32b4d762d0e3fd7f5b3a6219e4e2bb1dacbbeb2 Mon Sep 17 00:00:00 2001 From: Baptiste Jonglez <baptiste.jonglez@inria.fr> Date: Fri, 6 May 2022 11:33:12 +0200 Subject: [PATCH] cli: allow to run even if config file is missing --- grid5000/cli.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/grid5000/cli.py b/grid5000/cli.py index 1f5a996..454983f 100644 --- a/grid5000/cli.py +++ b/grid5000/cli.py @@ -20,23 +20,29 @@ MOTD = r""" \____/_/ /_/\__,_/ /_____/\____/\____/\____/ -* Configuration loaded from %s -* A new client (variable gk) has been created for the user %s +""" + +MOTD_END = """\ * Start exploring the API through the gk variable # Example: Get all available sites $) gk.sites.list() """ - def main(): - path = pathlib.Path(CONF_PATH) - if not path.exists(): - print("Configuration file %s is missing" % CONF_PATH) - return - gk = Grid5000.from_yaml(CONF_PATH) - motd = MOTD % (CONF_PATH, gk.username) + motd = MOTD + if path.exists(): + gk = Grid5000.from_yaml(CONF_PATH) + motd += "* Configuration loaded from %s\n" % CONF_PATH + else: + gk = Grid5000() + motd += "* Warning: configuration file %s is missing, authentication might not work\n" % CONF_PATH + if gk.username: + motd += "* A new client (variable gk) has been created for the user %s\n" % gk.username + else: + motd += "* A new client (variable gk) has been created\n" + motd += MOTD_END IPython.embed(header=motd) -- GitLab