annotate bin/captureDevice @ 1830:8e0e5b3db301

redo collector client to use HTTP Ignore-this: b1ae4f45bfe31d8ba58d13c68e9f6a87
author drewp@bigasterisk.com
date Sat, 09 Jun 2018 17:56:43 +0000
parents 6fa4288da8a6
children 7772cc48e016
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
1692
6fa4288da8a6 rdfdb is its own package now
drewp@bigasterisk.com
parents: 1625
diff changeset
20 from rdfdb.syncedgraph import SyncedGraph
1544
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
1830
8e0e5b3db301 redo collector client to use HTTP
drewp@bigasterisk.com
parents: 1692
diff changeset
24 from light9.collector.collector_client import sendToCollector
1692
6fa4288da8a6 rdfdb is its own package now
drewp@bigasterisk.com
parents: 1625
diff changeset
25 from 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
1625
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
68 #quantum
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
69 rxSteps = steps(.06, .952, 10)
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
70 rySteps = steps(0.1, .77, 5)
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
71 zoomSteps = steps(.12, .85, 3)
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
72 # aura
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
73 rxSteps = steps(0.15, .95, 10)
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
74 rySteps = steps(0, .9, 5)
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
75 zoomSteps = steps(.6, .9, 3)
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
76
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
77 row = 0
1625
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
78 for ry in rySteps:
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
79 xSteps = rxSteps[:]
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
80 if row % 2:
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
81 xSteps.reverse()
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
82 row += 1
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
83 for rx in xSteps:
1625
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
84 for zoom in zoomSteps:
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
85 self.toGather.append(DeviceSettings(graph, [
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
86 (dev, L9['rx'], rx),
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
87 (dev, L9['ry'], ry),
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
88 (dev, L9['color'], '#ffffff'),
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
89 (dev, L9['zoom'], zoom),
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
90 #(dev, L9['focus'], 0.13),
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
91 ]))
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
92
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
93 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
94 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
95 '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
96 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
97
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
98 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
99 (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
100 ]))
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
101
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
102 self.numPics = 0
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
103 self.settingsCache = set()
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
104 self.step().addErrback(log.error)
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
105
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
106 def off(self):
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
107 return sendToCollector(client='captureDevice', session='main',
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
108 settings=DeviceSettings(self.graph, []))
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
109
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
110 @inlineCallbacks
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
111 def step(self):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
112 if not self.toGather:
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
113 yield self.off()
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
114 yield deferSleep(1)
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
115 reactor.stop()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
116 return
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
117 settings = self.toGather.pop()
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 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
120 yield sendToCollector(client='captureDevice', session='main',
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
121 settings=settings)
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
122
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
123 yield deferSleep(self.firstMoveTime if self.numPics == 0 else
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
124 self.settleTime)
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 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
127 path = '/'.join([
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
128 '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
129 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
130
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
131 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
132 self.numPics += 1
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
133
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
134 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
135 self.dev,
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
136 path, self.settingsCache, settings)
1552
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 reactor.callLater(0, self.step)
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
139
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
140
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
141
1625
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
142 camera = Camera('http://plus:8200/picamserve/pic?res=1080&resize=800&iso=800&redgain=1.6&bluegain=1.6&shutter=60000&x=0&w=1&y=0&h=.952')
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
143
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
144 class Attrs(PrettyErrorHandler, cyclone.web.RequestHandler):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
145 def put(self):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
146 with stats.setAttr.time():
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
147 client, clientSession, settings, sendTime = parseJsonMessage(self.request.body)
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
148 self.set_status(202)
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
149
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
150 def launch(graph):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
151
1625
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
152 cap = Capture(graph, dev=L9['device/aura5'])
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
153 reactor.listenTCP(networking.captureDevice.port,
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
154 cyclone.web.Application(handlers=[
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
155 (r'/()', cyclone.web.StaticFileHandler,
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
156 {"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
157 (r'/stats', StatsForCyclone),
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 interface='::')
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
160 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
161
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
162 def main():
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
163 parser = optparse.OptionParser()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
164 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
165 help="logging.DEBUG")
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
166 (options, args) = parser.parse_args()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
167 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
168
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
169 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
170
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
171 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
172 reactor.run()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
173
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
174 if __name__ == '__main__':
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
175 main()