Files @ 7eb423e60011
Branch filter:

Location: light9/bin/vidref

drewp@bigasterisk.com
checkpoint show data
Ignore-this: 20364078759d11074f633b52cc6c48f5
#!bin/python
from run_local import log
import sys
sys.path.append('/usr/lib/python2.7/dist-packages') # For gtk
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
import cyclone.web, cyclone.httpclient, cyclone.websocket
from light9 import networking, showconfig
from light9.vidref.main import Gui
from light9.vidref.replay import snapshotDir
from light9.rdfdb.syncedgraph import SyncedGraph

 # 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 if options.verbose else logging.INFO)

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

graph = SyncedGraph(networking.rdfdb.url, "vidref")

gui = Gui(graph)

port = networking.vidref.port
reactor.listenTCP(port, cyclone.web.Application(handlers=[
    (r'/()', cyclone.web.StaticFileHandler,
     {'path': 'light9/vidref', 'default_filename': 'vidref.html'}),
    (r'/static/(.*)', cyclone.web.StaticFileHandler, {'path': 'static/'}),
    (r'/snapshot', Snapshot),
    (r'/snapshot/(.*)', SnapshotPic, {"path": snapshotDir()}),
    ], debug=True, gui=gui))
log.info("serving on %s" % port)

reactor.run()