Mercurial > code > home > repos > homeauto
changeset 688:7ac46dc29517
get some iot2 tests going
Ignore-this: cdfdf88f445f043aa5aa55f737f6b776
author | drewp@bigasterisk.com |
---|---|
date | Tue, 21 Jan 2020 23:59:45 -0800 |
parents | 1fe2a8e15ebf |
children | e3eceee54937 |
files | service/iot2/devices.py service/iot2/iot2_linux.nim service/iot2/requirements.txt service/iot2/tasks.py |
diffstat | 4 files changed, 86 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/iot2/devices.py Tue Jan 21 23:59:45 2020 -0800 @@ -0,0 +1,7 @@ +from standardservice.logsetup import log +import w1thermsensor + +def hello(): + log.info('hi devices') + + log.info(w1thermsensor.W1ThermSensor.get_available_sensors())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/iot2/iot2_linux.nim Tue Jan 21 23:59:45 2020 -0800 @@ -0,0 +1,16 @@ +import nimpy + +proc setup_python(): PyObject = + let sys = pyImport("sys") + discard sys.path.extend([ + ".", # for devices.py itself + "env/lib/python3.7/site-packages" # for deeper imports + ]) + + pyImport("devices") + + +echo "iot2_linux starting" + +let devices = setup_python() +discard devices.hello()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/iot2/requirements.txt Tue Jan 21 23:59:45 2020 -0800 @@ -0,0 +1,7 @@ +#RPi.GPIO==0.6.5 +#git+git://github.com/adafruit/Adafruit_Nokia_LCD +#http://abyz.me.uk/rpi/pigpio/pigpio.zip +#rpi_ws281x==3.1.0 +w1thermsensor + +standardservice==0.6.0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/iot2/tasks.py Tue Jan 21 23:59:45 2020 -0800 @@ -0,0 +1,56 @@ +from invoke import task +from pathlib import Path + +@task +def nim_install(ctx): + if Path('nim-1.0.4/bin/nim').exists(): + return + ctx.run(f'curl https://nim-lang.org/download/nim-1.0.4-linux_x64.tar.xz | xz -dc | tar x') + +@task +def py_install(ctx): + if Path('env/bin/python').exists(): + return + ctx.run(f'mkdir -p env') + ctx.run(f'virtualenv -p /usr/bin/python3.7 env') + +@task(pre=[py_install]) +def py_deps(ctx): + pip_install_ran = Path('env/lib/python3.7/site-packages/wheel').stat().st_mtime + requirements = Path('requirements.txt').stat().st_mtime + if pip_install_ran > requirements: + return + ctx.run(f'env/bin/pip install --quiet --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements.txt') + +@task(pre=[nim_install]) +def nim_deps(ctx): + pkgs = ['nimpy-0.1.0'] + if all(Path(f'~/.nimble/pkgs/{pkg}').expanduser().exists() for pkg in pkgs): + return + plain_names = ' '.join(p.split('-')[0] for p in pkgs) + ctx.run(f'nim-1.0.4/bin/nimble install {plain_names}', pty=True) + + +@task(pre=[nim_install]) +def nim_build_x86(ctx): + ctx.run(f'nim-1.0.4/bin/nim c --out:iot2_linux_x86 iot2_linux.nim', pty=True) + +@task +def arm_cross_compiler_install(ctx): + ctx.run(f'sudo apt install -y crossbuild-essential-armhf', pty=True) + +@task(pre=[nim_install]) +def nim_build_arm(ctx): + ctx.run(f'nim-1.0.4/bin/nim c --cpu:arm --out:iot2_linux_arm iot2_linux.nim', pty=True) + +@task(pre=[py_deps, nim_build_x86]) +def local_run(ctx): + ctx.run(f'./iot2_linux_x86') + + +# pack this into docker for pushing to Pi + +# apt install -y sshfs +# sshfs drewp@10.2.0.110:/my/proj/homeauto/service/iot2 /mnt +# cd /mnt +# ./iot2_linux_arm