clicon / clixon

YANG-based toolchain including NETCONF and RESTCONF interfaces and an interactive CLI
http://www.clicon.org/
Other
206 stars 69 forks source link

Add run python3 #520

Closed khromenokroman closed 2 months ago

khromenokroman commented 2 months ago

This commit includes a new function cli_start_python3 which executes Python3 scripts from within the CLI. The function operates as a new command in the CLI interface, accepting a path to the script as an argument. This enhancement improves the versatility of the Clixon CLI interface by allowing direct execution of Python scripts.

krihal commented 2 months ago

What are the advantage over adding a shebang for Python3 in the script and then use something like this in the CLI specification?

shell("System command"), cli_start_shell("bash");{
  <source:rest>("Single shell command"), cli_start_shell("bash");
}

Any Python script can then be called as long as #!/bin/env python3 or similar are added to the top of the file and the file is executable and "shell" can of course be renamed.

debian@khn-dev /> shell /tmp/test.py
foo
olofhagsand commented 2 months ago

It would be nice to add a documentation section somewhere here: https://clixon-docs.readthedocs.io/en/latest/cli.html on how to use scripts (specifically python) as callbacks.

khromenokroman commented 2 months ago

What are the advantage over adding a shebang for Python3 in the script and then use something like this in the CLI specification?

shell("System command"), cli_start_shell("bash");{
  <source:rest>("Single shell command"), cli_start_shell("bash");
}

Any Python script can then be called as long as #!/bin/env python3 or similar are added to the top of the file and the file is executable and "shell" can of course be renamed.

debian@khn-dev /> shell /tmp/test.py
foo

That's right, you can do this. But then it will be like this Снимок экрана от 2024-05-22 13-16-10

And with my version it will be like this Снимок экрана от 2024-05-22 13-18-23

I think it's better this way. But I could be wrong :)

khromenokroman commented 2 months ago

It would be nice to add a documentation section somewhere here: https://clixon-docs.readthedocs.io/en/latest/cli.html on how to use scripts (specifically python) as callbacks.

I'll try to do it now

olofhagsand commented 2 months ago

It would be nice to add a documentation section somewhere here: https://clixon-docs.readthedocs.io/en/latest/cli.html on how to use scripts (specifically python) as callbacks.

I'll try to do it now

You need to checkout the old version of configure for tests to parse

olofhagsand commented 2 months ago

I think it's better this way. But I could be wrong :) Yes, but can you do it more generalized, so that it is not hardcoded to /usr/bin/python3? I can see it being useful for other scripts (or even if python is installed elsewhere.u This is the advantage of the existing cli_start_shell.

olofhagsand commented 2 months ago

I see you close this PR. I think it is important to improve the scripting interface, and also its documentation, and I think your comments made sense. Are you planning to make a new PR?

khromenokroman commented 2 months ago

I see you close this PR. I think it is important to improve the scripting interface, and also its documentation, and I think your comments made sense. Are you planning to make a new PR?

yes, I will correct the comments, they were correct, and make a new pool request