Files
@ 0617b6006ec4
Branch filter:
Location: light9/bin/subserver - annotation
0617b6006ec4
3.3 KiB
text/plain
ts cleanup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | 33a5a98e9bf1 33a5a98e9bf1 33a5a98e9bf1 a5a44077c54c 33a5a98e9bf1 33a5a98e9bf1 3c523c71da29 dd896321faee dd896321faee 33a5a98e9bf1 3c523c71da29 dd896321faee 6fa4288da8a6 6fa4288da8a6 dd896321faee dd896321faee bb4d1e9b30c1 40cc863d2b63 7772cc48e016 7772cc48e016 33a5a98e9bf1 7772cc48e016 33a5a98e9bf1 448fe9f81501 891f2d75c686 891f2d75c686 7772cc48e016 a4632a7b2e17 891f2d75c686 891f2d75c686 7772cc48e016 891f2d75c686 33a5a98e9bf1 33a5a98e9bf1 33a5a98e9bf1 33a5a98e9bf1 33a5a98e9bf1 bb4d1e9b30c1 33a5a98e9bf1 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 dd896321faee dd896321faee 7772cc48e016 dd896321faee dd896321faee dd896321faee 7772cc48e016 7772cc48e016 dd896321faee dd896321faee dd896321faee dd896321faee dd896321faee dd896321faee dd896321faee 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 dd896321faee 7772cc48e016 dd896321faee dd896321faee 7772cc48e016 dd896321faee dd896321faee dd896321faee dd896321faee dd896321faee dd896321faee dd896321faee 7772cc48e016 7772cc48e016 33a5a98e9bf1 33a5a98e9bf1 7772cc48e016 7772cc48e016 7772cc48e016 33a5a98e9bf1 33a5a98e9bf1 33a5a98e9bf1 33a5a98e9bf1 33a5a98e9bf1 e703b3434dbd 33a5a98e9bf1 e703b3434dbd 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 7772cc48e016 33a5a98e9bf1 33a5a98e9bf1 | #!bin/python
"""
live web display of all existing subs with pictures, mainly for
dragging them into CC or Timeline
"""
from run_local import log
import optparse, logging, json, subprocess, datetime
from dateutil.tz import tzlocal
from twisted.internet import reactor, defer
import cyclone.web, cyclone.httpclient, cyclone.websocket
from rdflib import URIRef, Literal
import pyjade.utils
from rdfdb.syncedgraph import SyncedGraph
from rdfdb.patch import Patch
from light9.namespaces import L9, DCTERMS
from light9 import networking, showconfig
from cycloneerr import PrettyErrorHandler
class Static(PrettyErrorHandler, cyclone.web.StaticFileHandler):
def get(self, path, *args, **kw):
if path in ['', 'effects']:
return self.respondStaticJade("light9/subserver/%s.jade" %
(path or 'index'))
if path.endswith(".js"):
return self.responseStaticCoffee(
'light9/subserver/%s' %
path.replace(".js", ".coffee")) # potential security hole
cyclone.web.StaticFileHandler.get(self, path, *args, **kw)
def respondStaticJade(self, src):
html = pyjade.utils.process(open(src).read())
self.write(html)
def responseStaticCoffee(self, src):
self.write(
subprocess.check_output(
['/usr/bin/coffee', '--compile', '--print', src]))
class Snapshot(PrettyErrorHandler, cyclone.web.RequestHandler):
@defer.inlineCallbacks
def post(self):
about = URIRef(self.get_argument("about"))
response = yield cyclone.httpclient.fetch(
networking.vidref.path("snapshot"), method="POST", timeout=1)
snapUri = URIRef(json.loads(response.body)['snapshot'])
# vidref could write about when it was taken, etc. would it be
# better for us to tell vidref where to attach the result in
# the graph, and then it doesn't even have to return anything?
ctx = showconfig.showUri() + "/snapshots"
self.settings.graph.patch(
Patch(addQuads=[
(about, L9['image'], snapUri, ctx),
(snapUri, DCTERMS['created'],
Literal(datetime.datetime.now(tzlocal())), ctx),
]))
self.write(json.dumps({'snapshot': snapUri}))
def newestImage(subject):
newest = (None, None)
for img in graph.objects(subject, L9['image']):
created = graph.value(img, DCTERMS['created'])
if created > newest[0]:
newest = (created, img)
return newest[1]
if __name__ == "__main__":
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)
graph = SyncedGraph(networking.rdfdb.url, "subServer")
port = networking.subServer.port
reactor.listenTCP(
port,
cyclone.web.Application(handlers=[
(r'/snapshot', Snapshot),
(r'/(.*)', Static, {
"path": "light9/subserver",
"default_filename": "index.jade"
}),
],
debug=True,
graph=graph))
log.info("serving on %s" % port)
reactor.run()
|