BTW.... can you email me the instructions as a setup-androind.txt and I 
will include them in scripts/?

On Thursday, 19 January 2012 10:56:18 UTC-6, fpp wrote:
>
>
> In response to a question in another thread, here is a summary of how 
> I got web2py running on my Android device (a Samsung Note), using 
> hints found here and there. 
>
> Maybe it can save some time for those wanting to do the same thing. 
>
> Note : I am just getting started with Android, so there are probably 
> better and/or easier ways to do it than what I describe here. 
>
> Please add to this thread if you see anything missing or incorrect. 
>
> --------------------------------- 
>
> First we need to get python running on the device, obviously. 
>
> This is done by installing SL4A (scripting layer for Android). 
> Get the the apk from http://code.google.com/p/android-scripting/ and 
> install it 
> (requires checking "unknown sources" in settings/applications) 
> SL4A was initially called ASE (Android scripting engine), so many 
> older Howtos use that instead. 
>
> Run the app, use menu/view/interpreters : by default there is only 
> "shell". 
> Use menu again, "add", choose Python. 
> This downloads the installer. Run "python for android" from your apps 
> list, install... 
>
> Whew, now we have Python on our device, but it only runs through the 
> SL4A interface. 
>
>
> Now we need to get it running from the command line. 
>
> I used the traditional "adb" method to connect from the PC to the 
> Android console, with the USB cable. 
> adb can be found in the Android SDK, and is also included in several 
> rooting kits, which are smaller (adb is just one executable and two 
> DLLs under Windows). 
> It also needs the USB drivers for the device, which means installing 
> vendor software (like Kies for Samsung). 
>
> (Users who already have an SSH daemon running on their device can use 
> ssh and scp and Wifi instead) 
>
> So, if all goes well, "adb shell" will connect you to a very basic 
> Linux console on your device. 
>
> On mine, the SL4A scripts folder is at : /sdcard/sl4a/scripts 
> I chose to do everything in there to be available also from inside the 
> app. 
>
> You can now verify that python does not run from the command line, 
> because no environment is set. 
>
> I found this ready-made script that does all the grunt work : 
> http://blog.anantshri.info/android-standalone-python/ 
>
> Only it seems that paths move around a lot between Android versions 
> and/or devices, so I had to correct them for mine : 
>
> #! /bin/sh 
> 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 
> "$@" 
>
> Let's save this to "py.sh" and copy that to the device : 
> adb push py.sh /sdcard/sl4a/scripts 
>
> Then connect back with 'adb shell' and try 'sh py.sh' : if the paths 
> are OK you should now be in the Python interpreter. 
> Whew again :-) 
>
>
> Now comes the web2py part. It's not as easy as it should be, due to 
> some shortcomings in the Android Python distribution. 
>
> First, you need version 1.97.1 at least (i used 1.99.4, latest as of 
> this writing). 
> Next, even then some things don't work, such as creating an app 
> directly on the device, because of cache problems : 
>
> https://groups.google.com/group/web2py/browse_thread/thread/461ca3eec3fde4e4/9ab612d9c21604ee?hl=fr&lnk=gst&q=android#9ab612d9c21604ee
>  
>
> I worked around this by preparing the web2py environment on the PC 
> first, then copying it over. 
>
> These are the main steps : 
>
> * get latest web2py_src.zip 
> * unzip to temp dir on PC 
> * run once so that all initialization steps are done, check the admin 
> app 
> * stop 
> * copy your existing app(s) to the web2py applications folders 
> * (optional) reduce size by deleting example apps, test scripts, 
> errors etc. 
> * re-zip to web2py_a.zip 
> * push to device with adb push web2py_a.zip /sdcard/sl4a/scripts 
> * connect to shell again and unzip 
>
> Note: on my device 'unzip' would fail to extract the archive because 
> it could not set the permissions. 
> I had to use 'su' first for it to work (the device was already rooted) 
>
> So now we only need a way to start web2py as a daemon. 
> I created a new 'web2py.sh' shell script, which is the same as py.sh 
> except for the last two lines : 
>
> #! /bin/sh 
>
> 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 
> cd web2py 
> /data/data/com.googlecode.pythonforandroid/files/python/bin/python 
> web2py.py -l '' -a foobar -n 2 -i 127.0.0.1 & 
>
> This starts web2py with the following settings : 
>
> -l'' : disable logging 
> -zz foobar: sets the admin app password 
> -n 2 : two processes only (single user app) 
> -i 127.0.0.1 : listen on localhost address (no networks needed for on- 
> device usage) 
>
> This prints the web2py startup message and returns. 
> Disconnecting from adb does not stop the server. 
> This should work also from SL4A. 
>
> Hope this helps, 
> fp 
>

-- 



Reply via email to