507
|
1 import sys, datetime, cyclone.web, json
|
|
2 from twisted.internet import reactor, task
|
|
3 from rdflib import Namespace, Literal, ConjunctiveGraph
|
|
4 import rdflib_jsonld.parser
|
|
5 from patchablegraph import PatchableGraph, CycloneGraphEventsHandler, CycloneGraphHandler
|
|
6
|
|
7 class CurrentGraph(cyclone.web.RequestHandler):
|
|
8 def put(self):
|
|
9 g = ConjunctiveGraph()
|
|
10 rdflib_jsonld.parser.to_rdf(json.loads(self.request.body), g)
|
|
11 self.settings.masterGraph.setToGraph(g)
|
|
12
|
|
13 def main():
|
|
14 from twisted.python import log as twlog
|
|
15 twlog.startLogging(sys.stderr)
|
|
16 masterGraph = PatchableGraph()
|
|
17
|
|
18 class Application(cyclone.web.Application):
|
|
19 def __init__(self):
|
|
20 handlers = [
|
|
21 (r"/()", cyclone.web.StaticFileHandler,
|
|
22 {"path": ".", "default_filename": "index.html"}),
|
|
23 (r'/graph', CycloneGraphHandler, {'masterGraph': masterGraph}),
|
|
24 (r'/graph/events', CycloneGraphEventsHandler, {'masterGraph': masterGraph}),
|
|
25 (r'/currentGraph', CurrentGraph),
|
|
26 ]
|
|
27 cyclone.web.Application.__init__(self, handlers,
|
|
28 masterGraph=masterGraph)
|
|
29
|
|
30 reactor.listenTCP(10012, Application())
|
|
31 reactor.run()
|
|
32
|
|
33 if __name__ == '__main__':
|
|
34 main()
|