Mercurial > code > home > repos > homeauto
changeset 1243:b63c35e13e18
environment graph service standardization
Ignore-this: 3aeb86c03902af984a871c9c2d2dd7cd
darcs-hash:d609c91b384e6d59a76babb6666c109653e31dd8
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Thu, 18 Apr 2019 09:12:26 -0700 |
parents | 24c004aac998 |
children | cda481e4b77b |
files | service/environment/Dockerfile service/environment/docs.n3 service/environment/environment.py service/environment/index.html service/environment/makefile service/environment/requirements.txt |
diffstat | 6 files changed, 134 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/environment/Dockerfile Thu Apr 18 09:12:26 2019 -0700 @@ -0,0 +1,17 @@ +FROM bang6:5000/base_x86 + +WORKDIR /opt + +COPY requirements.txt ./ +RUN pip install -r requirements.txt + +# upstream this +RUN apt-get install -y tzdata + +COPY twisted_sse_demo ./twisted_sse_demo +COPY *.py req* *.n3 *.html ./ + + +EXPOSE 9075 + +CMD [ "python", "environment.py" ]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/environment/docs.n3 Thu Apr 18 09:12:26 2019 -0700 @@ -0,0 +1,3 @@ +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. + +<http://projects.bigasterisk.com/device/calendar> rdfs:comment "facts related to the calendar" . \ No newline at end of file
--- a/service/environment/environment.py Mon Apr 15 00:17:04 2019 -0700 +++ b/service/environment/environment.py Thu Apr 18 09:12:26 2019 -0700 @@ -4,20 +4,28 @@ daytime/night, overall modes like 'maintenance mode', etc """ -import sys, datetime, cyclone.web -from twisted.internet import reactor, task +import sys, datetime, cyclone.web, logging +from docopt import docopt +from twisted.internet import reactor, task, defer from dateutil.tz import tzlocal from dateutil.relativedelta import relativedelta, FR from rdflib import Namespace, Literal -sys.path.append("/my/proj/homeauto/lib") +from greplin import scales +from greplin.scales.cyclonehandler import StatsHandler from patchablegraph import PatchableGraph, CycloneGraphEventsHandler, CycloneGraphHandler from twilight import isWithinTwilight +from logsetup import log, enableTwistedLog from rdfdoc import Doc ROOM = Namespace("http://projects.bigasterisk.com/room/") DEV = Namespace("http://projects.bigasterisk.com/device/") +STATS = scales.collection('/root', + scales.PmfStat('update'), +) + +@STATS.update.time() def update(masterGraph): stmt = lambda s, p, o: masterGraph.patchObject(ROOM.environment, s, p, o) @@ -47,8 +55,17 @@ def main(): - from twisted.python import log as twlog - twlog.startLogging(sys.stderr) + arg = docopt(""" + Usage: environment.py [options] + + -v Verbose + """) + log.setLevel(logging.INFO) + if arg['-v']: + enableTwistedLog() + log.setLevel(logging.DEBUG) + defer.setDebugging(True) + masterGraph = PatchableGraph() class Application(cyclone.web.Application): @@ -62,6 +79,7 @@ (r'/graph/events', CycloneGraphEventsHandler, {'masterGraph': masterGraph}), (r'/doc', Doc), # to be shared + (r'/stats/(.*)', StatsHandler, {'serverName': 'environment'}), ] cyclone.web.Application.__init__(self, handlers, masterGraph=masterGraph)
--- a/service/environment/index.html Mon Apr 15 00:17:04 2019 -0700 +++ b/service/environment/index.html Thu Apr 18 09:12:26 2019 -0700 @@ -1,22 +1,41 @@ -<!DOCTYPE html> -<html - xmlns:dcterms="http://purl.org/dc/terms/" - xmlns:dev="http://projects.bigasterisk.com/device/" - xmlns:xs="http://www.w3.org/2001/XMLSchema#" - xmlns="http://projects.bigasterisk.com/room/" - > +<!doctype html> +<html> <head> + <title>environment</title> + <meta charset="utf-8" /> <script src="/lib/polymer/1.0.9/webcomponentsjs/webcomponents.min.js"></script> + <script src="/lib/require/require-2.3.3.js"></script> + <script src="/rdf/common_paths_and_ns.js"></script> + + <link rel="import" href="/rdf/streamed-graph.html"> <link rel="import" href="/lib/polymer/1.0.9/polymer/polymer.html"> - <link rel="import" href="/rdf/streamed-graph.html"> - <link rel="import" href="/rdf/graph-view.html"> + <meta name="mobile-web-app-capable" content="yes"> + <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> - <h1>env</h1> - <template is="dom-bind"> + <template id="t" is="dom-bind"> <streamed-graph url="graph/events" graph="{{graph}}"></streamed-graph> - <graph-view graph="{{graph}}"></graph-view> + <div id="out"></div> + <script type="module" src="/rdf/streamed_graph_view.js"></script> </template> + <style> + .served-resources { + margin-top: 4em; + border-top: 1px solid gray; + padding-top: 1em; + } + .served-resources a { + padding-right: 2em; + } + </style> + + <div class="served-resources"> + <a href="stats/">/stats/</a> + <a href="graph">/graph</a> + <a href="graph/events">/graph/events</a> + <a href="doc">/doc</a> + </div> + </body> </html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/environment/makefile Thu Apr 18 09:12:26 2019 -0700 @@ -0,0 +1,44 @@ +JOB=environment +PORT=9075 + +TAG=bang6:5000/${JOB}_x86:latest + +build_image: + rm -rf tmp_ctx + mkdir -p tmp_ctx + cp -a Dockerfile ../../lib/*.py ../../lib/twisted_sse_demo *.n3 *.html *.py req* tmp_ctx + docker build --network=host -t ${TAG} tmp_ctx + docker push ${TAG} + rm -r tmp_ctx + +shell: + docker run --rm -it --cap-add SYS_PTRACE --net=host ${TAG} /bin/bash + +local_run: build_image + docker run --rm -it -p ${PORT}:${PORT} \ + -v `pwd`:/mnt \ + -v /my/proj/rdfdb/rdfdb:/usr/local/lib/python2.7/dist-packages/rdfdb \ + --net=host \ + ${TAG} \ + python environment.py -v + +local_run_strace: build_image + docker run --rm -it -p ${PORT}:${PORT} \ + -v `pwd`:/mnt \ + --net=host \ + --cap-add SYS_PTRACE \ + ${TAG} \ + strace -f -tts 200 python environment.py -v + +local_run_pyspy: build_image + docker run --rm -it -p ${PORT}:${PORT} \ + -v `pwd`:/mnt \ + --net=host \ + --cap-add SYS_PTRACE \ + ${TAG} \ + py-spy -- python environment.py + + +redeploy: build_image + supervisorctl restart $(JOB)_$(PORT) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/environment/requirements.txt Thu Apr 18 09:12:26 2019 -0700 @@ -0,0 +1,16 @@ +cyclone +docopt +ipdb +service_identity +twisted + +py-spy +#rdflib==4.2.2 +git+http://github.com/drewp/rdflib.git@5fa18be1231a5e4dfc86ec28f2f754158c6f6f0b#egg=rdflib + +#rdflib-jsonld==0.4.0 +#git+http://github.com/RDFLib/rdflib-jsonld@cc5f005b222105724cd59c6069df9982fbd28c98#egg=rdflib_jsonld +git+http://github.com/drewp/rdflib-jsonld.git@0a560c9f1aa7c7bbb80fea389e1f5fa51d1287f8#egg=rdflib_jsonld + +git+http://github.com/drewp/scales.git@448d59fb491b7631877528e7695a93553bfaaa93#egg=scales +https://projects.bigasterisk.com/rdfdb/rdfdb-0.8.0.tar.gz