Quantcast
Channel: xda-developers - Android Software and Hacking General [Developers Only]
Viewing all articles
Browse latest Browse all 3614

[Scripting][ARM][Installer] Python (static) 2.7.8 and 3.4.2

$
0
0
(Check out https://www.python.org for information on what Python is.)


Yes you read that correctly, static python for Android! It took a while to figure out how to get this compiled, but I finally did it. I present you with an installer and a little bit of testing. I'll probably eventually post some information on how it was compiled if anyone's interested.


INSTALLATION
Recovery flash installers are attached that will install python 2.7.8 and/or 3.4.2 to /system/pythonX.X.X. You can install both if you want. Installation size is about 38MB for python 2.7.8 , and 62MB for python 3.4.2.

After installation, the python director(ies) in /system will contain the static python binary, the python library.a, and some modules. Separate scripted executables will be installed to /system/bin/python or /system/bin/python3 depending on which one is installed. These basically just set the PYTHONHOME environment variable and execute the python binary.


TESTING
When you boot up to Android after installation, you should be able to just open up a terminal and fire off some python commands.

Test using python 2.7.8:
Code:

python -c 'print "Hello World!"'

Test using python 3.4.2:
Code:

python3 -c 'print("Hello World!")'

You can also write scripts shelled with python:

Code:

#!/system/bin/python

print "Hello World!"

Make sure to set them as executable with "chmod +x".


Adjust your screen brightness via /sys (root required, tested on Galaxy Nexus):
Code:

python -c 'f=open("/sys/devices/omapdss/display0/backlight/s6e8aa0/brightness","w"); f.write("40"); f.close()'
A cool script I made to tweak file system I/O like rq_affinity, rotational, etc for I/O blocks:
Code:

#!/system/bin/python
import os,re,sys
list=[]
# find all directories containing rq_affinity
for roots, dirs, files in os.walk('/sys'):
  for file in files:
    match=re.search(r'\S+/rq_affinity',os.path.join(roots,file))
    if match:
      list.append(match.group().replace('rq_affinity',''))

# write specific values to files in each directory found before
for dir in list:
  for name in 'rq_affinity', 'rotational', 'read_ahead_kb', 'nr_requests', 'iostats', 'nomerges', 'add_random':
    try:
      f=open(dir+name,'w')
      if name is 'rq_affinity': f.write('1')
      elif name is 'read_ahead_kb': f.write('512')
      elif name is 'nr_requests': f.write('512')
      else: f.write('0')
      f.close()
    except IOError:
      sys.stderr.write('Problem writing to ' + dir+name + '\n')

Or execute "python" or "python3" without any parameters to open up the interpreter and go from there. When you start for example "python" (python 2.7.8), you should see:

Code:

Python 2.7.8 (default, Dec  1 2014, 05:15:18)
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>


***I haven't fully tested this yet, so let me know how it goes. I know basic commands work, but there are still some complexities in the compilation that may need to be figured out.***

ISSUES
-help doesn't seem to be working, will check this out

Attached Files
File Type: zip python2.7.8.zip - [Click for QR Code] (10.50 MB)
File Type: zip python3.4.2.zip - [Click for QR Code] (19.38 MB)

Viewing all articles
Browse latest Browse all 3614

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>