Pass command line arguments to Bokeh server application - bokeh

I have a Bokeh server application. I would like to pass it custom options on the command line:
bokeh serve /path/to/script.py --my-option foo
Is this possible? Will Bokeh pass these options through somehow?

Yes, use the --args command line option described in the User's Guide. Everything you put after the --args option will just appear in sys.argv for the app code, just as you would expect with any normal python script.
Running this app:
import sys
print(sys.argv)
With this invocation:
bokeh serve foo.py --args -x 1 bar --baz
Then opening a session will result in this being printed:
['foo.py', '-x', '1', 'bar', '--baz']

Related

AttributeError: module 'salt.modules' has no attribute 'cp'

The CP command from the terminal is working as expected via
salt "*" cp_push .... works as expected from the master terminal. However using the command in an execution module fails with:
AttributeError: module 'salt.modules' has no attribute 'cp'
Salt is imported in the execution module via:
import salt
The function is being called as:
salt.modules.cp.push(path=str(latest_report))
Not an answer but a work around.
used:
salt.modules.cmdmod.run("salt-call cp.push *desired path*, shell="powershell")
Using powershell solved a plethora of other errors in default Command Prompt

What does `python3 ()` do?

While trying to execute a timeit command on the command line using the python command line interface I accidentally put .function() on the outside of the command like so:
$ python3 -m timeit '<code>'.function()
Rather than the timeit command being executed, I was prompted as such:
function>
Thinking I had entered the python repl I tried to quit with q. Yes, I'm aware quit() is the correct way to do this. Having returned to the command line, I noticed the error and corrected it like so:
$ python3 -m timeit `<code>.function()`
I expected this code to execute correctly, but instead I received the following error:
python3:7: command not found: q
After discussing it with some colleagues, it was suggested that I check which python was being used:
$ which python3
python3 () {
q
}
This was not what I was expecting! Normally the result would be /usr/local/bin/python3. Through some trial and error I was able to determine that the minimal case to reproduce this is:
$ python3 ()
function> q
$
Now that the context is out of the way, I have two questions about the behaviour I witnessed:
1. What exactly does python3 () do?
2. How do I return execution to its original state in the same terminal window? I'm aware I can open a new terminal window and the original state exists in that window.
The syntax foo () is used in POSIX-compliant shells (such as bash, dash, and zsh) to define a function. Your entire snippet defines a function called python3 and executes the command q when it's ran. You can bypass shell functions and aliases using the command command: command -p python3 myfile.py
To remove the function from the current shell process, you can use unset -f python3. If it keeps coming back after starting new shells, then it's likely defined in one of you shell initialization files.

Symfony Console Output

I am writing my first symfony console apps and I would like to ask a question regarding the console outputs.
When I run a new CLI app in the console like: ./testapp then I get the following output:
Usage:
command [options] [arguments]
Options:
--help (-h) Display this help message
--quiet (-q) Do not output any message
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
--no-interaction (-n) Do not ask any interactive question
Available commands:
help Displays help for a command
list Lists commands
Is there a way to remove the display of this content? I want only the "Available Commands" to be visible. And is it possible to create my own groups in this display?
As of Symfony 2.5, you can change the default command (the command that's executed when no command name was specified). See for more information: http://symfony.com/doc/current/components/console/changing_default_command.html
The Console component will always run the ListCommand when no command name is passed. In order to change the default command you just need to pass the command name to the setDefaultCommand method.
(Symfony Console 4.1)
It's possible to remove the default options:
$options = $app->getDefinition()->getOptions();
unset($options['ansi']);
unset($options['no-interaction']);
unset($options['verbose']);
unset($options['help']);
unset($options['quiet']);
unset($options['version']);
unset($options['no-ansi']);
$app->getDefinition()->setOptions($options);
or just:
$app->getDefinition()->setOptions();
Options group will not show in the list command.
Although I don't know if this has any undesirable side effect.

Pydev Eclipse console does not support curses.setupterm

I cannot run a script in Eclipse that works perfectly in a terminal.
It seems that Eclipse console cannot support some functions. I am looking for a workaround to be able to debug the script using Pydev.
Is it possible to set PyDev to use for example /usr/bin/gnome-terminal instead of the Eclipse native console ?
Otherwise it there a way to define a wrapper as a python interpreter for PyDev that will launch an terminal external to Eclipse (I've tried but failed on that).
Thank you
Nga
Right now, curses-based apps really don't run well inside Eclipse/PyDev, so, you must really launch it externally. To debug you can use the remote debugger: http://pydev.org/manual_adv_remote_debugger.html
If you use Aptana Studio, there's a terminal view which should emulate a terminal better... try running python (i.e.: running your program) from inside that view. If it does work properly there, maybe I could check a way to better integrate there and launch directly in that view.
Thank you for your reply. I have finally defined kind of a wrapper as a bash script calling python in a xterm. Pydev is checking some configuration by calling eclipse/plugins/org.python.pydev_2.4.0.2012020116/PySrc/interpreterInfo.py so the script first echo the format expected by PyDev. here is the script "
#!/bin/bash
# dummy return for Eclipse Pydev - respect interpreter info format
echo "EXECUTABLE:/home/user/python_custom/python_xterm|
|/home/user/eclipse/plugins/org.python.pydev_2.4.0.2012020116/PySrc
|/usr/lib/python2.5
|/usr/lib/python2.5/plat-linux2
|/usr/lib/python2.5/lib-tk
|/usr/lib/python2.5/lib-dynload
|/usr/local/lib/python2.5/site-packages
|/usr/lib/python2.5/site-packages
|/usr/lib/python2.5/site-packages/Numeric
|/usr/lib/python2.5/site-packages/PIL
|/usr/lib/python2.5/site-packages/gst-0.10
|/var/lib/python-support/python2.5
|/usr/lib/python2.5/site-packages/gtk-2.0
|/var/lib/python-support/python2.5/gtk-2.0
|/var/lib/python-support/python2.5/HTMLgen
|/var/lib/python-support/python2.5/pyinotify
|/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode
|/usr/lib/site-python
#
$
|__builtin__
|__main__
|_ast
|_codecs
|_sre
|_symtable
|_types
|errno
|exceptions
|gc
|imp
|marshal
|posix
|pwd
|signal
|sys
|thread
|xxsubtype
|zipimport
"
# activate scrollbar -sb with 6000 lines
# allow logging -l with filename log_$NOW
xterm -g 150x100+0+0 -sb -sl 6000 -si -hold -e "python $*"
that does the job, and I can use Pydev and its debugger

Respond to shell prompts from Ant SSH task (SSHEXEC)

I'm using the SSHEXEC ant task to run an SSH script against a remote linux box.
This has worked fine until I try and call a ksh script which prompts the user for input. The script changes the current user (like su). It prompts the user for a change_request_id, and a change_request_reason. So using this command normally in a shell would look like this:
change_user deploy_user
Please enter the changes request number for doing this: 1234
Please enter the changes request reason: Because I can
<deploy_user>
But when I run these commands from SSHEXEC, it gets to the first prompt "Please enter the changes request number for doing this:" and stops. Even though I'm piping a response to this prompt via SSHEXEC, it still gets stuck here.
Unfortunately we do not have access to change or copy the change_user shell script.
I was wondering if there was some way I could use SSHEXEC which would send down prompt answers with the command.
Any help would be appreciated.
Are you able to put another script on the same server as the change user script that accepts command line parameters and then calls the change request script itself? E.g. in ksh:
#!/usr/bin/ksh
#
# $1 is change request number
# $2 is change request reason
#
/path/to/change_request_cmd <<PARAMS
$1
$2
PARAMS
It may be easier to have SSHEXEC call this script instead.

Resources