Mercurial > code > home > repos > light9
view bin/vidref @ 942:dd896321faee
subserver can get a snapshot from vidref and display it on the sub
Ignore-this: 9ea0a172869922d22d8c5cf6ee4bf3da
author | drewp@bigasterisk.com |
---|---|
date | Thu, 13 Jun 2013 01:31:16 +0000 |
parents | 1d9547f90737 |
children | b281ee32c785 |
line wrap: on
line source
#!bin/python from run_local import log from twisted.internet import gtk2reactor gtk2reactor.install() from twisted.internet import reactor, defer import gobject gobject.threads_init() import gtk import sys, logging, optparse, json sys.path.append(".") from light9 import networking from light9.vidref.main import Gui from light9.vidref.replay import snapshotDir import cyclone.web, cyclone.httpclient, cyclone.websocket # find replay dirs correctly. show multiple # replays. trash. reorder/pin. dump takes that are too short; they're # just from seeking parser = optparse.OptionParser() parser.add_option("-v", "--verbose", action="store_true", help="logging.DEBUG") (options, args) = parser.parse_args() log.setLevel(logging.DEBUG) # limit the stdout one, but leave debug messages for the gtk logger log.handlers[0].setLevel(logging.DEBUG if options.verbose else logging.WARN) logging.getLogger("restkit.client").setLevel(logging.WARN) class Snapshot(cyclone.web.RequestHandler): @defer.inlineCallbacks def post(self): # save next pic # return /snapshot/path try: outputFilename = yield self.settings.gui.snapshot() assert outputFilename.startswith(snapshotDir()) out = networking.vidref.path( "snapshot/%s" % outputFilename[len(snapshotDir()):].lstrip('/')) self.write(json.dumps({'snapshot': out})) self.set_header("Location", out) self.set_status(303) except Exception as e: import traceback traceback.print_exc() raise class SnapshotPic(cyclone.web.StaticFileHandler): pass gui = Gui() port = networking.vidref.port reactor.listenTCP(port, cyclone.web.Application(handlers=[ (r'/snapshot', Snapshot), (r'/snapshot/(.*)', SnapshotPic, {"path": snapshotDir()}), ], debug=True, gui=gui)) log.info("serving on %s" % port) reactor.run()