From 52c7a37a785bea5db6a4526bb2548cac35b1888e Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 15 Aug 2017 17:18:50 +0200 Subject: [PATCH 1/2] [enh] add 'yunohost tools shell' --- data/actionsmap/yunohost.yml | 6 ++++++ src/yunohost/tools.py | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 24b099451..3effd8442 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1478,6 +1478,12 @@ tools: extra: pattern: *pattern_port + ### tools_shell() + shell: + configuration: + authenticate: all + action_help: Launch a development shell + ### tools_shutdown() shutdown: action_help: Shutdown the server diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 5b74883f1..294575ed8 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -814,6 +814,30 @@ def tools_migrations_state(): return read_json(MIGRATIONS_STATE_PATH) +def tools_shell(auth): + """ + Launch an (i)python shell in the YunoHost context. + + This is entirely aim for development. + """ + + logger.warn("The \033[1;34mauth\033[0m is available in this context") + try: + from IPython import embed + embed() + except ImportError: + logger.warn("You don't have IPython installed, consider installing it as it is way better than the standard shell.") + logger.warn("Falling back on the standard shell.") + + import readline # will allow Up/Down/History in the console + readline # to please pyflakes + import code + vars = globals().copy() + vars.update(locals()) + shell = code.InteractiveConsole(vars) + shell.interact() + + def _get_migrations_list(): migrations = [] From 4e1a8395575379632cdcde26a4d048003410b94a Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Tue, 15 Aug 2017 17:24:26 +0200 Subject: [PATCH 2/2] =?UTF-8?q?[enh]=20can=20do=20a=20'yunohost=20tools=20?= =?UTF-8?q?shell=20-c=20command'=20=C3=A0=20la=20python=20-c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/actionsmap/yunohost.yml | 4 ++++ src/yunohost/tools.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 3effd8442..46466de3d 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1483,6 +1483,10 @@ tools: configuration: authenticate: all action_help: Launch a development shell + arguments: + -c: + help: python command to execute + full: --command ### tools_shutdown() shutdown: diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 294575ed8..3fdee520c 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -814,13 +814,17 @@ def tools_migrations_state(): return read_json(MIGRATIONS_STATE_PATH) -def tools_shell(auth): +def tools_shell(auth, command=None): """ Launch an (i)python shell in the YunoHost context. This is entirely aim for development. """ + if command: + exec(command) + return + logger.warn("The \033[1;34mauth\033[0m is available in this context") try: from IPython import embed