annotate bin/vidref @ 1898:d3091e6dd1a0

more initial data for 2019 show Ignore-this: 1bf5c652531d8653ae74528414b772ef
author Drew Perttula <drewp@bigasterisk.com>
date Thu, 30 May 2019 17:14:11 +0000
parents 3c523c71da29
children 6f49dc917aa3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
729
b5efddd80dad update more shbang lines
Drew Perttula <drewp@bigasterisk.com>
parents: 647
diff changeset
1 #!bin/python
882
d96c09669b40 vidref change logger
drewp@bigasterisk.com
parents: 729
diff changeset
2 from run_local import log
1070
b281ee32c785 use Pillow. make vidref start up
Drew Perttula <drewp@bigasterisk.com>
parents: 941
diff changeset
3 import sys
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
4 sys.path.append('/usr/lib/python2.7/dist-packages') # For gtk
935
89adbbb06bcd vidref run in twisted mainloop
drewp@bigasterisk.com
parents: 882
diff changeset
5 from twisted.internet import gtk2reactor
89adbbb06bcd vidref run in twisted mainloop
drewp@bigasterisk.com
parents: 882
diff changeset
6 gtk2reactor.install()
941
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
7 from twisted.internet import reactor, defer
525
d3f8333bc142 more vidref replay code
drewp@bigasterisk.com
parents: 523
diff changeset
8 import gobject
d3f8333bc142 more vidref replay code
drewp@bigasterisk.com
parents: 523
diff changeset
9 gobject.threads_init()
941
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
10 import sys, logging, optparse, json
1096
087f6cbe4b22 vidrefsetup tool now prepares a url that vidref will use for rpi camera requests
Drew Perttula <drewp@bigasterisk.com>
parents: 1089
diff changeset
11 import cyclone.web, cyclone.httpclient, cyclone.websocket
1866
3c523c71da29 pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents: 1858
diff changeset
12 from light9 import networking
937
b0337e6f68f1 refactor to videorecorder.py
drewp@bigasterisk.com
parents: 935
diff changeset
13 from light9.vidref.main import Gui
941
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
14 from light9.vidref.replay import snapshotDir
1692
6fa4288da8a6 rdfdb is its own package now
drewp@bigasterisk.com
parents: 1369
diff changeset
15 from rdfdb.syncedgraph import SyncedGraph
522
e20419d637d5 initial vidref tests
drewp@bigasterisk.com
parents:
diff changeset
16
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
17 # find replay dirs correctly. show multiple
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
18 # replays. trash. reorder/pin. dump takes that are too short; they're
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
19 # just from seeking
542
cfd5d5be1b50 vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents: 541
diff changeset
20
cfd5d5be1b50 vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents: 541
diff changeset
21 parser = optparse.OptionParser()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
22 parser.add_option("-v", "--verbose", action="store_true", help="logging.DEBUG")
542
cfd5d5be1b50 vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents: 541
diff changeset
23 (options, args) = parser.parse_args()
cfd5d5be1b50 vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents: 541
diff changeset
24
1089
2ee97997ee56 vidref now reads from picamserve
Drew Perttula <drewp@bigasterisk.com>
parents: 1070
diff changeset
25 log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
534
6f1eb6437c96 vidref refactor, start to add more widgets
drewp@bigasterisk.com
parents: 525
diff changeset
26
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
27
941
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
28 class Snapshot(cyclone.web.RequestHandler):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
29
941
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
30 @defer.inlineCallbacks
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
31 def post(self):
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
32 # save next pic
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
33 # return /snapshot/path
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
34 try:
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
35 outputFilename = yield self.settings.gui.snapshot()
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
36
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
37 assert outputFilename.startswith(snapshotDir())
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
38 out = networking.vidref.path(
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
39 "snapshot/%s" % outputFilename[len(snapshotDir()):].lstrip('/'))
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
40
941
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
41 self.write(json.dumps({'snapshot': out}))
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
42 self.set_header("Location", out)
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
43 self.set_status(303)
1866
3c523c71da29 pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents: 1858
diff changeset
44 except Exception:
941
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
45 import traceback
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
46 traceback.print_exc()
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
47 raise
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
48
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
49
941
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
50 class SnapshotPic(cyclone.web.StaticFileHandler):
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
51 pass
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
52
1369
6b5e079b3dbe timeline hover goes to vidref
Drew Perttula <drewp@bigasterisk.com>
parents: 1212
diff changeset
53
6b5e079b3dbe timeline hover goes to vidref
Drew Perttula <drewp@bigasterisk.com>
parents: 1212
diff changeset
54 class Time(cyclone.web.RequestHandler):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
55
1369
6b5e079b3dbe timeline hover goes to vidref
Drew Perttula <drewp@bigasterisk.com>
parents: 1212
diff changeset
56 def put(self):
6b5e079b3dbe timeline hover goes to vidref
Drew Perttula <drewp@bigasterisk.com>
parents: 1212
diff changeset
57 body = json.loads(self.request.body)
6b5e079b3dbe timeline hover goes to vidref
Drew Perttula <drewp@bigasterisk.com>
parents: 1212
diff changeset
58 t = body['t']
6b5e079b3dbe timeline hover goes to vidref
Drew Perttula <drewp@bigasterisk.com>
parents: 1212
diff changeset
59 source = body['source']
6b5e079b3dbe timeline hover goes to vidref
Drew Perttula <drewp@bigasterisk.com>
parents: 1212
diff changeset
60 self.settings.gui.incomingTime(t, source)
6b5e079b3dbe timeline hover goes to vidref
Drew Perttula <drewp@bigasterisk.com>
parents: 1212
diff changeset
61 self.set_status(202)
6b5e079b3dbe timeline hover goes to vidref
Drew Perttula <drewp@bigasterisk.com>
parents: 1212
diff changeset
62
6b5e079b3dbe timeline hover goes to vidref
Drew Perttula <drewp@bigasterisk.com>
parents: 1212
diff changeset
63
1114
a38955ba6f40 rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents: 1096
diff changeset
64 graph = SyncedGraph(networking.rdfdb.url, "vidref")
1096
087f6cbe4b22 vidrefsetup tool now prepares a url that vidref will use for rpi camera requests
Drew Perttula <drewp@bigasterisk.com>
parents: 1089
diff changeset
65
087f6cbe4b22 vidrefsetup tool now prepares a url that vidref will use for rpi camera requests
Drew Perttula <drewp@bigasterisk.com>
parents: 1089
diff changeset
66 gui = Gui(graph)
941
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
67
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
68 port = networking.vidref.port
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
69 reactor.listenTCP(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
70 port,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
71 cyclone.web.Application(handlers=[
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
72 (r'/()', cyclone.web.StaticFileHandler, {
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
73 'path': 'light9/vidref',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
74 'default_filename': 'vidref.html'
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
75 }),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
76 (r'/snapshot', Snapshot),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
77 (r'/snapshot/(.*)', SnapshotPic, {
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
78 "path": snapshotDir()
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
79 }),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
80 (r'/time', Time),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
81 ],
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
82 debug=True,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1692
diff changeset
83 gui=gui))
941
1d9547f90737 vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents: 937
diff changeset
84 log.info("serving on %s" % port)
937
b0337e6f68f1 refactor to videorecorder.py
drewp@bigasterisk.com
parents: 935
diff changeset
85
935
89adbbb06bcd vidref run in twisted mainloop
drewp@bigasterisk.com
parents: 882
diff changeset
86 reactor.run()