Mercurial > code > home > repos > light9
annotate bin/vidref @ 1089:2ee97997ee56
vidref now reads from picamserve
Ignore-this: 17bc49636b291f6640f2f2a4a8f93e40
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Thu, 05 Jun 2014 07:22:29 +0000 |
parents | b281ee32c785 |
children | 087f6cbe4b22 |
rev | line source |
---|---|
729
b5efddd80dad
update more shbang lines
Drew Perttula <drewp@bigasterisk.com>
parents:
647
diff
changeset
|
1 #!bin/python |
882 | 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 |
b281ee32c785
use Pillow. make vidref start up
Drew Perttula <drewp@bigasterisk.com>
parents:
941
diff
changeset
|
4 sys.path.append('/usr/lib/python2.7/dist-packages') # For gtk |
935 | 5 from twisted.internet import gtk2reactor |
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 | 8 import gobject |
9 gobject.threads_init() | |
522 | 10 import gtk |
941
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
11 import sys, logging, optparse, json |
523
9f36a105adb3
fix vidref to allow playback from webcam
drewp@bigasterisk.com
parents:
522
diff
changeset
|
12 sys.path.append(".") |
941
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
13 from light9 import networking |
937 | 14 from light9.vidref.main import Gui |
941
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
15 from light9.vidref.replay import snapshotDir |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
16 import cyclone.web, cyclone.httpclient, cyclone.websocket |
522 | 17 |
542
cfd5d5be1b50
vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents:
541
diff
changeset
|
18 # find replay dirs correctly. show multiple |
cfd5d5be1b50
vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents:
541
diff
changeset
|
19 # replays. trash. reorder/pin. dump takes that are too short; they're |
cfd5d5be1b50
vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents:
541
diff
changeset
|
20 # just from seeking |
cfd5d5be1b50
vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents:
541
diff
changeset
|
21 |
cfd5d5be1b50
vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents:
541
diff
changeset
|
22 parser = optparse.OptionParser() |
cfd5d5be1b50
vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents:
541
diff
changeset
|
23 parser.add_option("-v", "--verbose", action="store_true", |
cfd5d5be1b50
vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents:
541
diff
changeset
|
24 help="logging.DEBUG") |
cfd5d5be1b50
vidref complete panels on each replay. replays load and delete pretty well
drewp@bigasterisk.com
parents:
541
diff
changeset
|
25 (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
|
26 |
522 | 27 |
1089
2ee97997ee56
vidref now reads from picamserve
Drew Perttula <drewp@bigasterisk.com>
parents:
1070
diff
changeset
|
28 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
|
29 |
941
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
30 class Snapshot(cyclone.web.RequestHandler): |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
31 @defer.inlineCallbacks |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
32 def post(self): |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
33 # save next pic |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
34 # return /snapshot/path |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
35 try: |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
36 outputFilename = yield self.settings.gui.snapshot() |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
37 |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
38 assert outputFilename.startswith(snapshotDir()) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
39 out = networking.vidref.path( |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
40 "snapshot/%s" % outputFilename[len(snapshotDir()):].lstrip('/')) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
41 |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
42 self.write(json.dumps({'snapshot': out})) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
43 self.set_header("Location", out) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
44 self.set_status(303) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
45 except Exception as e: |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
46 import traceback |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
47 traceback.print_exc() |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
48 raise |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
49 |
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 |
937 | 53 |
941
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
54 gui = Gui() |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
55 |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
56 port = networking.vidref.port |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
57 reactor.listenTCP(port, cyclone.web.Application(handlers=[ |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
58 (r'/snapshot', Snapshot), |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
59 (r'/snapshot/(.*)', SnapshotPic, {"path": snapshotDir()}), |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
60 ], debug=True, gui=gui)) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
61 log.info("serving on %s" % port) |
937 | 62 |
935 | 63 reactor.run() |
522 | 64 |