annotate bin/captureDevice @ 1585:17da56a3c8df

group device captures into sessions, limit solver to specific ones Ignore-this: b91d858ebb435973b9742bed00567ffd
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 30 May 2017 08:37:25 +0000
parents 2239d5648932
children 9fe3052f8ced
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
1 #!bin/python
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
2 from __future__ import division
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
3 from rdflib import URIRef
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
4 from twisted.internet import reactor
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
5 from twisted.internet.defer import inlineCallbacks, Deferred
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
6
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
7 import logging
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
8 import optparse
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
9 import os
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
10 import time
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
11 import treq
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
12 import cyclone.web, cyclone.websocket, cyclone.httpclient
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
13 from greplin import scales
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
14
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
15 from run_local import log
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
16 from lib.cycloneerr import PrettyErrorHandler
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
17
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
18 from light9.namespaces import L9, RDF
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
19 from light9 import networking, showconfig
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
20 from light9.rdfdb.syncedgraph import SyncedGraph
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
21 from light9.paint.capture import writeCaptureDescription
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
22 from light9.greplin_cyclone import StatsForCyclone
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
23 from light9.effect.settings import DeviceSettings
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
24 from light9.effect.sequencer import sendToCollector
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
25 from light9.rdfdb.patch import Patch
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
26
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
27 stats = scales.collection('/webServer', scales.PmfStat('setAttr'))
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
28
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
29 class Camera(object):
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
30 def __init__(self, imageUrl):
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
31 self.imageUrl = imageUrl
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
32
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
33 def takePic(self, uri, writePath):
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
34 log.info('takePic %s', uri)
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
35 return treq.get(self.imageUrl).addCallbacks(
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
36 lambda r: self._done(writePath, r), log.error)
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
37
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
38 @inlineCallbacks
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
39 def _done(self, writePath, response):
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
40 jpg = yield response.content()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
41 try:
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
42 os.makedirs(os.path.dirname(writePath))
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
43 except OSError:
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
44 pass
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
45 with open(writePath, 'w') as out:
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
46 out.write(jpg)
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
47 log.info('wrote %s', writePath)
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
48
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
49 def deferSleep(sec):
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
50 d = Deferred()
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
51 reactor.callLater(sec, d.callback, None)
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
52 return d
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
53
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
54 class Capture(object):
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
55 firstMoveTime = 3
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
56 settleTime = .5
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
57 def __init__(self, graph, dev):
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
58 self.graph = graph
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
59 self.dev = dev
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
60
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
61 def steps(a, b, n):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
62 return [round(a + (b - a) * i / n, 5) for i in range(n)]
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
63
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
64 startTime = time.time()
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
65 self.captureId = 'cap%s' % (int(startTime) - 1495170000)
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
66 self.toGather = []
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
67
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
68 row = 0
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
69 for ry in steps(0.82, .92, 6):
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
70 xSteps = steps(.23, .42, 12)
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
71 if row % 2:
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
72 xSteps.reverse()
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
73 row += 1
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
74 for rx in xSteps:
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
75 self.toGather.append(DeviceSettings(graph, [
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
76 (dev, L9['rx'], rx),
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
77 (dev, L9['ry'], ry),
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
78 (dev, L9['color'], '#ffffff'),
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
79 ]))
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
80
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
81 self.devTail = dev.rsplit('/')[-1]
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
82 self.session = URIRef('/'.join([showconfig.showUri(),
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
83 'capture', self.devTail, self.captureId]))
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
84 self.ctx = URIRef(self.session + '/index')
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
85
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
86 self.graph.patch(Patch(addQuads=[
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
87 (self.session, RDF.type, L9['CaptureSession'], self.ctx),
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
88 ]))
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
89
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
90 self.numPics = 0
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
91 self.settingsCache = set()
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
92 self.step().addErrback(log.error)
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
93
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
94 def off(self):
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
95 return sendToCollector(client='captureDevice', session='main',
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
96 settings=DeviceSettings(self.graph, []))
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
97
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
98 @inlineCallbacks
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
99 def step(self):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
100 if not self.toGather:
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
101 yield self.off()
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
102 yield deferSleep(1)
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
103 reactor.stop()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
104 return
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
105 settings = self.toGather.pop()
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
106
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
107 log.info('[%s left] move to %r', len(self.toGather), settings)
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
108 yield sendToCollector(client='captureDevice', session='main',
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
109 settings=settings)
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
110
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
111 yield deferSleep(self.firstMoveTime if self.numPics == 0 else
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
112 self.settleTime)
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
113
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
114 picId = 'pic%s' % self.numPics
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
115 path = '/'.join([
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
116 'capture', self.devTail, self.captureId, picId]) + '.jpg'
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
117 uri = URIRef(self.session + '/' + picId)
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
118
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
119 yield camera.takePic(uri, os.path.join(showconfig.root(), path))
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
120 self.numPics += 1
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
121
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
122 writeCaptureDescription(self.graph, self.ctx, self.session, uri,
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
123 self.dev,
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
124 path, self.settingsCache, settings)
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
125
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
126 reactor.callLater(0, self.step)
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
127
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
128
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
129
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
130 camera = Camera('http://dash:8200/picamserve/pic?res=480&resize=480&rotation=180&iso=800&redgain=1.6&bluegain=2&shutter=60000')
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
131
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
132 class Attrs(PrettyErrorHandler, cyclone.web.RequestHandler):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
133 def put(self):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
134 with stats.setAttr.time():
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
135 client, clientSession, settings, sendTime = parseJsonMessage(self.request.body)
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
136 self.set_status(202)
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
137
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
138 def launch(graph):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
139
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
140 cap = Capture(graph, dev=L9['device/moving1'])
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
141 reactor.listenTCP(networking.captureDevice.port,
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
142 cyclone.web.Application(handlers=[
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
143 (r'/()', cyclone.web.StaticFileHandler,
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
144 {"path" : "light9/web", "default_filename" : "captureDevice.html"}),
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
145 (r'/stats', StatsForCyclone),
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
146 ]),
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
147 interface='::')
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
148 log.info('serving http on %s', networking.captureDevice.port)
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
149
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
150 def main():
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
151 parser = optparse.OptionParser()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
152 parser.add_option("-v", "--verbose", action="store_true",
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
153 help="logging.DEBUG")
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
154 (options, args) = parser.parse_args()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
155 log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
156
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
157 graph = SyncedGraph(networking.rdfdb.url, "captureDevice")
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
158
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
159 graph.initiallySynced.addCallback(lambda _: launch(graph)).addErrback(log.error)
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
160 reactor.run()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
161
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
162 if __name__ == '__main__':
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
163 main()