Run Python for Android (Qpython) in Android Terminal - android

Python for Android (Py4A 2.6) is wonderful!!! But QPython (2.7) is a lot more powerful and continuously developed. Now I try to integrate Qpython's Python into Android (5.1 CM12) Terminal / ADB described in this Tutorial:http://wiki.qpython.org/en/diveinto/
My Script to import the environment variables qpython needs looks like:
TERM=screen
PATH=/data/data/com.hipipal.qpyplus/files/bin:/system/bin:/system/xbin
LD_LIBRARY_PATH=.:/data/data/com.hipipal.qpyplus/files/lib/:/data/data/com.hipipal.qpyplus/files/:/data/data/com.hipipal.qpyplus/lib/
PYTHONHOME=/data/data/com.hipipal.qpyplus/files
ANDROID_PRIVATE=/data/data/com.hipipal.qpyplus/files
PYTHONPATH=/storage/emulated/0/com.hipipal.qpyplus/lib/python2.7/site-packages/:/data/data/com.hipipal.qpyplus/files/lib/python2.7/site-packages/:/data/data/com.hipipal.qpyplus/files/lib/python2.7/:/data/data/com.hipipal.qpyplus/files/lib/python27.zip:/data/data/com.hipipal.qpyplus/files/lib/python2.7/lib-dynload/:/storage/emulated/0/com.hipipal.qpyplus/scripts
PYTHONSTARTUP=/storage/emulated/0/com.hipipal.qpyplus/lib/python2.7/site-packages/qpythoninit.py
PYTHONOPTIMIZE=2
TMPDIR=/storage/emulated/0/com.hipipal.qpyplus/cache
AP_HOST=127.0.0.1
AP_PORT=58418
AP_HANDSHAKE=01805a68-c04c-4e21-bd54-ac8732f3a8da
ANDROID_PUBLIC=/storage/emulated/0/com.hipipal.qpyplus
ANDROID_PRIVATE=/data/data/com.hipipal.qpyplus/files
ANDROID_ARGUMENT=/storage/emulated/0/com.hipipal.qpyplus/scripts
Shell session:
u0_a101#C1905:/ $ source /sdcard/qpyenvnew.sh
u0_a101#C1905:/ $ $python
u0_a101#C1905:/ $ hmm do nothing?!
I get no output.
I have found here on Stackoverflow the same Question but the posted solution ist a link how is down.
Other Tutorial on throws only errors
http://dinostest.com/node/28

Try this command in your terminal:
$sh data/data/com.hipipal.qpyplus/files/bin/qpython.sh
Terminal will prompt a Python console.

If your script for the environment variables was obtained by running the code from the tutorial link, it should be correct.
If what you have pasted is exactly what you entered, the problem would be that you tried to run pyhton by typing $python when it should have just been python
Pre-fixing with $ is used to reference the value of a variable, so entering $python referenced the value of the variable python but does nothing with it, hence no feedback.

EDIT2: Although it's not a direct answer to this question I suggest having a look at the App 'Termux'. You can install Python2/3 via apt, virtualenv/-wrapper etc... Much more powerfull!
EDIT: Since /data/data... is only accessible as root, the following must be done as root!
Take care that the python executables path is in your $PATH. That wasn't the case even after having run the script from the tutorial (your script). If it's not present simply type:export PATH=/data/data/com.hipipal.qpyplus/files/bin:$PATH
or follow theses steps. In short: create a file in /sdcard (here ".bashrc") with the above line. After that type: source .bashrcsource init.sh (init.sh is located in /data/data/com.hipipal.qpyplus/files/bin as well) Then fire up Python with python-android5 which is the PIE compatible executable for Phone with Lollipop and above. But be aware: For whatever reason I couldn't exit() or quit() the Python prompt but I was able to run Script from the Terminal! Have fun!

EDIT: I spotted this: PythonForAndroid. It is a fork of PythonForAndroid that is still alive, and this versions are able to run on Android L (Python3 on 5.1.1 in my case). Also check the SL4A linked there, it works great on Lollipop.
Thanks to the answers above I made a super easy solution. If you have root: Create a file "python" and type the following line in it:
sh data/data/com.hipipal.qpyplus/files/bin/qpython-android5.sh
Place this file in your /system/bin directory and you can access python from everywhere using the command 'python'.

Related

How to run malloDroid script?

I want to check SSL verification in my application. I downloaded on my santoku malloDroid.py and try use it (of course earlier I have read that script is an extansion of Androguard). I simply run mallo app: ./malloroid.py -f test.apk and i got import error that there is no androguard module. How to run malloDroid script to verify ssl?
In order to use MalloDroid, you need to have AndroGuard. Setting up Androguard is quite straight forward. Read more about installation here .
Once you have Androguard set up along with the proper environment variables, you can use Mallodroid as follows :
./mallodroid.py -f test.apk -x
This will most likely work!

How to run single testcase with Monkeyrunner

According to official documentation function MonkeyDevice.instrument(className, args) is perfectly suitable for this task.
As I understand this should be done like this:
device.instrument('my.package.name/android.test.InstrumentationTestRunner', {'class':'my.package.name.SingleTest'})
However it still launches all test-cases. Is it bug or my mistake?
It's a chimpchat bug.
I've just uploaded a path that fixes the problem.
Once applied, you will be able to run all the tests in a class by using the same syntax you are using.
If you want to give it a try before the patch is merged you can
download android source
cherry pick patch 37560
set the environment (build/envsetup.sh)
lunch
make chimpchat
make monkeyrunner
Try:
device.shell('am instrument -w -e class my.package.name.SingleTest my.package.name/android.test.InstrumentationTestRunner')
For some reason, device.instrument() way doesn't work for me even with latest sdk 20.0.1 and platform 14.

Shell script won't run on Android but will on Ubuntu

This script was written to make changes to the build.prop file on rooted devices. It will run on ubuntu but throws the following error when it is ran on a device. 6: Syntax error: expecting "in"
LINE_BREAK=""
while read line
do
case $line in
ro.ril.reject.cs.ss.enabled?=*)
line="ro.ril.reject.cs.ss.enabled=1";;
ro.ril.reject.mo.ussd.enabled?=*)
line="ro.ril.reject.mo.ussd.enabled=1";;
ro.phone.function?=*)
line="ro.phone.function=0";;
ro.bt.profiles?=*)
line="ro.bt.profiles=4270339";;
service.brcm.bt.ag_supported?=*)
line="service.brcm.bt.ag_supported=0";;
esac
NEW_FILE="$NEW_FILE$LINE_BREAK$line"
LINE_BREAK="\n"
done </system/build.prop
echo $NEW_FILE>/system/build.prop
Is there a nuance to writing scripts in android that I am missing? Thanks in advance!
You can try writing a script using SL4A which is the scripting layer for android.
Reference
http://android.amolgupta.in/2011/04/scripting-on-android.html
I do not have an Android but I would try putting quotes around $line:
case "$line" in
Just a hunch. Sorry about that. Maybe you tried already.

Where is the help.py for Android's monkeyrunner

I just can't find the help.py file in order to create the API reference for the monkeyrunner. The command described at the Android references
monkeyrunner <format> help.py <outfile> does not work when i call monkeyrunner html help.py /path/to/place/the/doc.html.
It's quite obvious that the help.py file is not found and the monkeyrunner also tells me "Can't open specified script file". But a locate on my system doesn't bring me a help.py file that has anything to do with monkeyrunner or Android.
So my question is: Where did they hide the help.py file for creating the API reference?
I cannot find it either. But one can assume that it is simply calling MonkeyRunner.help() with the passed in arguments. If you just want to get something quick use this script I created also named help.py:
#!/usr/bin/env python
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
text = MonkeyRunner.help("html");
f = open('help.html', 'w')
f.write(text);
f.close();
Run it just like any other monkeyrunner script:
$ monkeyrunner help.py
After I have all codes in my machine (i.e, repo sync), it is at mydroid/sdk/monkeyrunner/scripts along with other three:
help.py monkey_playback.py monkey_recorder.py mr_pydoc.py
This is brilliant answer https://stackoverflow.com/a/4470513/551383 but if you really want this file is in android source i.e. http://androidxref.com/4.2_r1/xref/sdk/monkeyrunner/scripts/help.py
http://androidxref.com/source/xref/sdk/monkeyrunner/scripts/help.py
I believe the documentation on the website starts from that script, but I'm pretty sure somebody edits it a bit afterwards as well.
There's an error in monkeyrunner's help documentation (monkeyrunner Built-in Help), you should use parameters in another order:
monkeyrunner help.py <format> <outfile>
And don't forget about specifying a full path to the script, if you're running it outside of the monkeyrunner.bat directory (android monkeyrunner scripts).
If you don't have Repo Sync, described by users above, you can find the sources (including help.py), for example, here: monkeyrunner scripts.
I opened an issue at Google Code (Issue 26259: monkeyrunner Built-in Help Description Error) and I hope that they'll fix it soon.

how to execute the test cases of PVplayer in android?

hi can you tell me how to execute the test cases defined in /external/opencore/engines/player/test/src in the donut code?
I have seen the PVplayer documentation , but that does not provide any information.
I am trying to run an SDP file in the PVplayer.
Try to follow the following steps to run the PV Player engine tests (I have done all this with donut code and product Sapphire):
1.You have to include the following line in /external/opencore/Android.mk while making build:
#include $(PV_TOP)/engines/player/test/Android.mk
Either uncomment this (if its commented) or remove any check which is avoiding this line to be included.
2.Build and install the images into phone.
3.Now open shell (use adb shell command). go to directory /system/bin.
There will be an excutable pvplayer_engine_test. Now run the following command:
pvplayer_engine_test -test x y -source xyz.mp4 -logfile -logall
where x is the start test case number and y is the end test
case number.
(For more command line options, please refer pvplayer_engine_unit_test_guide.pdf which is available at /external/opencore/doc location).
Hope this helps.

Categories

Resources