annotate bin/captureDevice @ 1866:3c523c71da29

pyflakes cleanups and some refactors Ignore-this: f7372e678699175feb4e628eee3d768c
author Drew Perttula <drewp@bigasterisk.com>
date Sat, 25 May 2019 12:10:51 +0000
parents 40cc863d2b63
children 1a7e5b07bf17
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
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
2
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
1861
40cc863d2b63 start py3 and other dep fixes
drewp@bigasterisk.com
parents: 1859
diff changeset
16 from cycloneerr import PrettyErrorHandler
1544
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
1866
3c523c71da29 pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents: 1861
diff changeset
26 from light9.zmqtransport import parseJsonMessage
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
27
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
28 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
29
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
30
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
31 class Camera(object):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
32
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
33 def __init__(self, imageUrl):
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
34 self.imageUrl = imageUrl
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
35
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
36 def takePic(self, uri, writePath):
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
37 log.info('takePic %s', uri)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
38 return treq.get(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
39 self.imageUrl).addCallbacks(lambda r: self._done(writePath, r),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
40 log.error)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
41
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
42 @inlineCallbacks
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
43 def _done(self, writePath, response):
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
44 jpg = yield response.content()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
45 try:
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
46 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
47 except OSError:
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
48 pass
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
49 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
50 out.write(jpg)
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
51 log.info('wrote %s', writePath)
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
52
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
53
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
54 def deferSleep(sec):
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
55 d = Deferred()
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
56 reactor.callLater(sec, d.callback, None)
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
57 return d
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
58
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
59
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
60 class Capture(object):
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
61 firstMoveTime = 3
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
62 settleTime = .5
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
63
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
64 def __init__(self, graph, dev):
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
65 self.graph = graph
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
66 self.dev = dev
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
67
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
68 def steps(a, b, n):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
69 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
70
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
71 startTime = time.time()
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
72 self.captureId = 'cap%s' % (int(startTime) - 1495170000)
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
73 self.toGather = []
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
74
1625
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
75 #quantum
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
76 rxSteps = steps(.06, .952, 10)
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
77 rySteps = steps(0.1, .77, 5)
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
78 zoomSteps = steps(.12, .85, 3)
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
79 # aura
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
80 rxSteps = steps(0.15, .95, 10)
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
81 rySteps = steps(0, .9, 5)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
82 zoomSteps = steps(.6, .9, 3)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
83
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
84 row = 0
1625
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
85 for ry in rySteps:
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
86 xSteps = rxSteps[:]
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
87 if row % 2:
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
88 xSteps.reverse()
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
89 row += 1
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
90 for rx in xSteps:
1625
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
91 for zoom in zoomSteps:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
92 self.toGather.append(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
93 DeviceSettings(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
94 graph,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
95 [
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
96 (dev, L9['rx'], rx),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
97 (dev, L9['ry'], ry),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
98 (dev, L9['color'], '#ffffff'),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
99 (dev, L9['zoom'], zoom),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
100 #(dev, L9['focus'], 0.13),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
101 ]))
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
102
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
103 self.devTail = dev.rsplit('/')[-1]
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
104 self.session = URIRef('/'.join(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
105 [showconfig.showUri(), 'capture', self.devTail, self.captureId]))
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
106 self.ctx = URIRef(self.session + '/index')
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
107
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
108 self.graph.patch(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
109 Patch(addQuads=[
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
110 (self.session, RDF.type, L9['CaptureSession'], self.ctx),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
111 ]))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
112
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
113 self.numPics = 0
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
114 self.settingsCache = set()
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
115 self.step().addErrback(log.error)
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
116
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
117 def off(self):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
118 return sendToCollector(client='captureDevice',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
119 session='main',
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
120 settings=DeviceSettings(self.graph, []))
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
121
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
122 @inlineCallbacks
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
123 def step(self):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
124 if not self.toGather:
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
125 yield self.off()
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
126 yield deferSleep(1)
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
127 reactor.stop()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
128 return
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
129 settings = self.toGather.pop()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
130
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
131 log.info('[%s left] move to %r', len(self.toGather), settings)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
132 yield sendToCollector(client='captureDevice',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
133 session='main',
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
134 settings=settings)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
135
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
136 yield deferSleep(self.firstMoveTime if self.numPics ==
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
137 0 else self.settleTime)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
138
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
139 picId = 'pic%s' % self.numPics
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
140 path = '/'.join(['capture', self.devTail, self.captureId, picId
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
141 ]) + '.jpg'
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
142 uri = URIRef(self.session + '/' + picId)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
143
1584
2239d5648932 captureDevice saves all pics
Drew Perttula <drewp@bigasterisk.com>
parents: 1553
diff changeset
144 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
145 self.numPics += 1
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
146
1585
17da56a3c8df group device captures into sessions, limit solver to specific ones
Drew Perttula <drewp@bigasterisk.com>
parents: 1584
diff changeset
147 writeCaptureDescription(self.graph, self.ctx, self.session, uri,
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
148 self.dev, path, self.settingsCache, settings)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
149
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
150 reactor.callLater(0, self.step)
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
151
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
152
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
153 camera = Camera(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
154 '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'
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
155 )
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
156
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
157
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
158 class Attrs(PrettyErrorHandler, cyclone.web.RequestHandler):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
159
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
160 def put(self):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
161 with stats.setAttr.time():
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
162 client, clientSession, settings, sendTime = parseJsonMessage(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
163 self.request.body)
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
164 self.set_status(202)
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
165
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
166
1552
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
167 def launch(graph):
0aad247a1168 refactor and fix captureDevice
Drew Perttula <drewp@bigasterisk.com>
parents: 1544
diff changeset
168
1625
9fe3052f8ced theater values for capture
drewp@bigasterisk.com
parents: 1585
diff changeset
169 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
170 reactor.listenTCP(networking.captureDevice.port,
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
171 cyclone.web.Application(handlers=[
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
172 (r'/()', cyclone.web.StaticFileHandler, {
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
173 "path": "light9/web",
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
174 "default_filename": "captureDevice.html"
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
175 }),
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
176 (r'/stats', StatsForCyclone),
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
177 ]),
1866
3c523c71da29 pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents: 1861
diff changeset
178 interface='::',
3c523c71da29 pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents: 1861
diff changeset
179 cap=cap)
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
180 log.info('serving http on %s', networking.captureDevice.port)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
181
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
182
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
183 def main():
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
184 parser = optparse.OptionParser()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
185 parser.add_option("-v",
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
186 "--verbose",
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
187 action="store_true",
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
188 help="logging.DEBUG")
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
189 (options, args) = parser.parse_args()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
190 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
191
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
192 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
193
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
194 graph.initiallySynced.addCallback(lambda _: launch(graph)).addErrback(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
195 log.error)
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
196 reactor.run()
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
197
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
198
1544
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
199 if __name__ == '__main__':
fc5675f5b756 captureDevice tool for sweeping through light settings and grabbing pics
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
200 main()