Skip to content

Instantly share code, notes, and snippets.

@ZoomQuiet
Last active January 4, 2016 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZoomQuiet/8645207 to your computer and use it in GitHub Desktop.
Save ZoomQuiet/8645207 to your computer and use it in GitHub Desktop.
Fabric for QPython auto upload/running script/collect log etc... from local through SSH
from fabric.api import local, env, run
#import os
env.shell = "/system/bin/sh -c"
# Local path configuration (can be absolute or relative to fabfile)
#
# Remote server configuration
PY = '/data/data/com.hipipal.qpyplus/files/bin/python'
PYQ = 'root@192.168.0.100'
env.hosts= [PYQ]
env.user = "root"
PYQ_ROOT = '/storage/sdcard0/com.hipipal.qpyplus/projects'
PROJ_NAME = 'chaos'
CRT_PROJ = "%(PYQ_ROOT)s/%(PROJ_NAME)s"% locals()
SCP_UP = "scp *.py %(PYQ)s:%(CRT_PROJ)s/ "% locals()
# Actions define.
#def pushproj(ports='22', name='chaos'):
def pushproj():
'''scp all .py into Android QPython projects dir
'''
print SCP_UP
local(SCP_UP)
def qpy_run_it(script="hello.py"):
'''fab qpy_run_it:script=MY.py
'''
run('pwd')
run('ls -la ./')
#run('export PYTHONHOME=/data/data/com.hipipal.qpyplus/files')
print '%s %s/%s'% (PY, CRT_PROJ, script)
#run('%s %s/%s'% (PY, CRT_PROJ, script))
run('source %s/qpy_profile && %s %s/%s'% (PYQ_ROOT
, PY
, CRT_PROJ
, script
))
#run('%s %s/%s'% (PY, CRT_PROJ, script))
'''main develop loop usage :
$ fab qpy:script=MY_developing.py
so fab will auto:
- scp all local .py up into mobile QPython projects fold
- and source right sys. env
- and call the 'MY_developing.py'
- so wiil see the script running in mobile desktop ;-)
'''
def qpy(script="hello.py"):
'''main develop tools, auto upload and running in Android
'''
pushproj()
qpy_run_it(script)
env()
def uname():
'''print Android sys. info.
'''
run('uname -a')
def env():
'''print Android sys. env
'''
print 'source %s/qpy_profile'% PYQ_ROOT
run('env')
#run('source %s/qpy_profile && env'% PYQ_ROOT)
def genenv(script="gen_env.py"):
'''gen qpy need env into: /storage/sdcard0/com.hipipal.qpyplus/projects/qpy_profile
'''
qpy_run_it(script)
run('ls -la %s'% CRT_PROJ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment