[DEV] Standalone python scripts
I have been experimenting lately with some python scripts using the concept of http://code.google.com/p/android-scripting/
however i found the interface limiting in lots of places.
- you can't run applications on console directly.
- you have environmental limitations.
- you can't pass command-line arguments.
so while searching for solution i have came across python standalone however this script itself had some shortcommings including path errors.
so i have worked on this and found an optimal solution so here is the customized script.
Code:
PW=`pwd`
export EXTERNAL_STORAGE=/mnt/sdcard
export LANG=en
PYTHONPATH=/mnt/sdcard/com.googlecode.pythonforandroid/extras/python
PYTHONPATH=${PYTHONPATH}:/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6/lib-dynload
export PYTHONPATH
export TEMP=/mnt/storage/com.googlecode.pythonforandroid/extras/python/tmp
export PYTHON_EGG_CACHE=$TEMP
export PYTHONHOME=/data/data/com.googlecode.pythonforandroid/files/python
export LD_LIBRARY_PATH=/data/data/com.googlecode.pythonforandroid/files/python/lib
cd $PW
/data/data/com.googlecode.pythonforandroid/files/python/bin/python "$@"
These changes allow for following things.
- allow us to use this shell script to call python.
- allows for command line argument passing.
- relative path references are now working
what i have setup at my system is as follows
- script is named as py and placed at /system/bin/
- chmod 755 /system/bin/py
- so now i can naviagate to any folder and just type py followed by script name to execute it.
This should help in quick porting and testing of scripts in android handset, and small name should help in making it easy to work on virtual terminal.
However we cann't undermine the SL4A project coz the project is there to provide interfacing between android and python.
successfully
I will try to keep updating all the python scripts that i have been able to run hope others can also contribute to it.
|