Files @ f8ab10f4c80b
Branch filter:

Location: light9/bin/vidref

Drew Perttula
better prefix for shorter n3 files in this theater
Ignore-this: 122de90725785217f975cdc76b966cab
#!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 sys, logging, optparse, json
import cyclone.web, cyclone.httpclient, cyclone.websocket
from light9 import networking
from light9.vidref.main import Gui
from light9.vidref.replay import snapshotDir
from 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:
            import traceback
            traceback.print_exc()
            raise


class SnapshotPic(cyclone.web.StaticFileHandler):
    pass


class Time(cyclone.web.RequestHandler):

    def put(self):
        body = json.loads(self.request.body)
        t = body['t']
        source = body['source']
        self.settings.gui.incomingTime(t, source)
        self.set_status(202)


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'/snapshot', Snapshot),
        (r'/snapshot/(.*)', SnapshotPic, {
            "path": snapshotDir()
        }),
        (r'/time', Time),
    ],
                            debug=True,
                            gui=gui))
log.info("serving on %s" % port)

reactor.run()