How to translate an ADB command line control ---> to MonkeyRunner Python script - android-activity

When I run this on the command line it brings up the screen on my device to change the language.
$ adb shell am start -a android.settings.LOCALE_SETTINGS
works great.
I am trying the same functionality into a Python script that monkeyrunner calls.
How do you translate the above into something that will work with monkeyrunner / python?
e.g. I tried:
device = Monkeyrunner.waitForConnection()
package = 'android.settings'
activity = 'LOCALE_SETTINGS'
runComponent = package + '/' activity
device.startActivity(component=runComponent
This does nothing. No error message. But nothing.
Any suggestions?

android.settings.LOCALE_SETTINGS is not a component but an action. You can do either
device.startActivity(action='android.settings.LOCALE_SETTINGS')
or
device.startActivity(component='com.android.settings/com.android.settings.Settings$LocalePickerActivity')

Related

How to source environment file in python?

I am trying to automate an application restarts with Python which is currently implemented with shell scripts. Before running the restart commands, we need to source a .sh environment file which is done in the shell script with
. ./opt///**.sh. I am using paramiko and exec_command to run the restart command which throws the error that libraries are missing. So I have tried several ways to source this environment file in the python program but have not been successful.
Things I have tried:
stdin1,stdout1,stderr1 = ssh_client1.exec_command(". ./opt///**.sh")
stdin1,stdout1,stderr1 = ssh_client1.exec_command("source /opt///**.sh")
subprocess.call("/opt///**.sh", shell=True)
os.system(". /opt///**.sh")
I picked the below from stack overflow if I remember correctly
enter code herecommand = shlex.split("bash -c 'source /opt///**.sh'")
enter code hereproc = subprocess.Popen(command, stdout = subprocess.PIPE)
enter code herefor line in proc.stdout:
enter code here(key, _, value) = line.partition("=")
enter code hereos.environ[key] = value
enter code hereproc.communicate()
I still get the same error missing libraries which I am supposed to get when I do not source the environment file when I run the application restart commands using exec_command("/opt///start")
Any help is really appreciated.
Thanks.
#Martin Prikryl: Execute multiple commands in Paramiko so that commands are affected by their predecessors
I love you man!! I am writing a py script to remote ssh with paramiko that sources a local environment file before running application restart commands. I was breaking my head over this for over 2 weeks, until I read this post. It works like a charm. Thank you!!
Solution:
Each exec_command multiple times is executed in its own "shell". So the previous commands have no effect on an environment of the following commands.
Use && to combine the commands. In this way, the previous command, which in my case is the environment file, has an effect on the following command.
stdin3,stdout3,stderr3 = ssh_client1.exec_command(". /opt///env.sh && STOP")

how to set command line for electron

I need a the electron start with transparent window in linux, the documents say I need put --enable-transparent-visuals --disable-gpu in the command line. Is there a way to pass the command line args in the program not in the terminal command line.
like this:
electron . --enable-transparent-visuals --disable-gpu
I need when I run
electron .
the args have set in the program.It means I just double click the bin file and the args are OK. Don't need to pass them manually.
You can put them in the main script of the application (main.js), before the 'ready' event of the app module is emitted, like so:
const electron = require('electron')
// Module to control application life.
const app = electron.app
app.commandLine.appendSwitch('enable-transparent-visuals');
app.commandLine.appendSwitch('disable-gpu');
app.on('ready', () => {
// Your code here
});
For a list of other command line switches, you can go here

Standard for feeding test data to a Nagios plugin?

I'm developing a Nagios plugin in Perl (no Nagios::Plugin, just plain Perl). The error condition I'm checking for normally comes from a command output, called inside the plugin. However, it would be very inconvenient to create the error condition, so I'm looking for a way to feed test output to the plugin to see if it works correctly.
The easiest way I found at the moment would be with a command line option to optionally read input from a file instead of calling the command.
if($opt_f) {
open(FILE, $opt_f);
#output = <FILE>;
close FILE;
}
else {
#output = `my_command`;
}
Are there other, better ways to do this?
Build a command line switch into your plugin, and if you set -t on the command line, you use your test command at /path/to/test/command, else you run the 'production' command at /path/to/production/command
The default action is production, only test it the switch indicating test mode is present.
Or you could have a test version of the command that returns various status for you to test (via a command line argument perhaps).
You put the test version of mycommnd in some test directory (/my/nagois/tests/bin).
Then you manipulate the PATH environment variable on the command line that runs the test.
$ env PATH=/my/nagois/tests/bin:$PATH nagios_pugin.pl
The change to $PATH will only last for as long as that one command executes. The change is localized to the subshell that is spawned to run the plugin.
The backticks used to execute the command will cause the shell to use the PATH to locate the command, and that will the the test version of the command, which lives in the directory that is now the first one on the search path.
let me know if I wasn't clear.
New answer for new method.

Command line installer issues

Am attempting to run installer using command line using -c option.
Command line execution appears like this:
E:\dev>MyApp_32.exe -c
E:\dev>This will install App on your computer.
OK [o, Enter], Cancel [c]
E:\dev> (showing the Windows command line is confusing to user)
Welcome .. (text of 2nd screen)
Typing "c" or "Cancel" doesn't work. It always takes enter key as input and proceeds to next screen.
Pressing enter transfers control back to windows's command shell, then back to installer. This looks confusing to user. It doesn't give a unified experience to user.
Is it possible to provide input via a silent file ? i.e. a text file with pre-selected inputs?
Am using 32 bit installer on Win 7 Professional x64 with Java 1.6 installed.
The problem is that the installer is a GUI application, it cannot take control of a WIndows terminal in this way. If you start it via
start /wait MyApp_32.exe -c
the command line prompts will not be displayed.
You can run set a response file with the -varfile argument, see the help for more information.

Making bat file in Window Mobile 6

I have Windows mobile 6. I have installed Cre-ME+, and command line. In the command line we need to type the following command and execute it, to load Oracle Mobile Application:
\Windows\CrEme\bin\CrEme.exe -Of -classpath \Windows\CrEme\lib\AWTclasses.zip;\XONTMWA\lib\j4205328.zip oracle.apps.mwa.awt.client.StartGUI
However, Windows Mobile does not support the bat/cmd file execution, so what would be a equivalent way of starting the Oracle Mobile Application, without having to type the command every time?
Create a shortcut with the command line, either via API or with your favorite text editor.
The contents would look like this (if my character count is right anyway):
139#\Windows\CrEme\bin\CrEme.exe -Of -classpath \Windows\CrEme\lib\AWTclasses.zip;\XONTMWA\lib\j4205328.zip oracle.apps.mwa.awt.client.StartGUI