Mercurial > code > home > repos > light9
annotate bin/vidref @ 1070:b281ee32c785
use Pillow. make vidref start up
Ignore-this: 52ba5ec2409bbf446c7592d3646220ad
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Mon, 02 Jun 2014 07:46:55 +0000 |
parents | 1d9547f90737 |
children | 2ee97997ee56 |
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 |
647
a30550d5827f
vidref shows more logs in the gui
Drew Perttula <drewp@bigasterisk.com>
parents:
542
diff
changeset
|
28 log.setLevel(logging.DEBUG) |
a30550d5827f
vidref shows more logs in the gui
Drew Perttula <drewp@bigasterisk.com>
parents:
542
diff
changeset
|
29 # limit the stdout one, but leave debug messages for the gtk logger |
a30550d5827f
vidref shows more logs in the gui
Drew Perttula <drewp@bigasterisk.com>
parents:
542
diff
changeset
|
30 log.handlers[0].setLevel(logging.DEBUG if options.verbose else logging.WARN) |
534
6f1eb6437c96
vidref refactor, start to add more widgets
drewp@bigasterisk.com
parents:
525
diff
changeset
|
31 logging.getLogger("restkit.client").setLevel(logging.WARN) |
6f1eb6437c96
vidref refactor, start to add more widgets
drewp@bigasterisk.com
parents:
525
diff
changeset
|
32 |
6f1eb6437c96
vidref refactor, start to add more widgets
drewp@bigasterisk.com
parents:
525
diff
changeset
|
33 |
941
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
34 class Snapshot(cyclone.web.RequestHandler): |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
35 @defer.inlineCallbacks |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
36 def post(self): |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
37 # save next pic |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
38 # return /snapshot/path |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
39 try: |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
40 outputFilename = yield self.settings.gui.snapshot() |
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 assert outputFilename.startswith(snapshotDir()) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
43 out = networking.vidref.path( |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
44 "snapshot/%s" % outputFilename[len(snapshotDir()):].lstrip('/')) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
45 |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
46 self.write(json.dumps({'snapshot': out})) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
47 self.set_header("Location", out) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
48 self.set_status(303) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
49 except Exception as e: |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
50 import traceback |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
51 traceback.print_exc() |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
52 raise |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
53 |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
54 class SnapshotPic(cyclone.web.StaticFileHandler): |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
55 pass |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
56 |
937 | 57 |
941
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
58 gui = Gui() |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
59 |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
60 port = networking.vidref.port |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
61 reactor.listenTCP(port, cyclone.web.Application(handlers=[ |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
62 (r'/snapshot', Snapshot), |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
63 (r'/snapshot/(.*)', SnapshotPic, {"path": snapshotDir()}), |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
64 ], debug=True, gui=gui)) |
1d9547f90737
vidref can take snapshots and serve them back
drewp@bigasterisk.com
parents:
937
diff
changeset
|
65 log.info("serving on %s" % port) |
937 | 66 |
935 | 67 reactor.run() |
522 | 68 |