comparison rdfdb/service.py @ 87:a96f4eb95ef0

more typing and formatting
author drewp@bigasterisk.com
date Mon, 04 Apr 2022 23:01:08 -0700
parents 5b6e90a708ce
children 1120c6489888
comparison
equal deleted inserted replaced
86:5b6e90a708ce 87:a96f4eb95ef0
2 import json 2 import json
3 import logging 3 import logging
4 import optparse 4 import optparse
5 import os 5 import os
6 import sys 6 import sys
7 import time 7 from typing import Dict, List, Optional, cast
8 from typing import Dict, List, Optional
9 8
10 import cyclone.web 9 import cyclone.web
11 import cyclone.websocket 10 import cyclone.websocket
12 import twisted.internet.error 11 import twisted.internet.error
13 from rdflib import ConjunctiveGraph, Graph, URIRef 12 from rdflib import ConjunctiveGraph, Graph, URIRef
14 from twisted.internet import reactor, task 13 import twisted.internet.reactor
15 from twisted.internet.inotify import IN_CREATE, INotify 14 from twisted.internet.inotify import IN_CREATE, INotify
16 from twisted.python.failure import Failure 15 from twisted.python.failure import Failure
17 from twisted.python.filepath import FilePath 16 from twisted.python.filepath import FilePath
17 from twisted.internet.interfaces import IReactorCore
18 18
19 from rdfdb.file_vs_uri import (DirUriMap, correctToTopdirPrefix, fileForUri, uriFromFile) 19 from rdfdb.file_vs_uri import (DirUriMap, correctToTopdirPrefix, fileForUri, uriFromFile)
20 from rdfdb.graphfile import GetSubgraph, GraphFile, PatchCb 20 from rdfdb.graphfile import GetSubgraph, GraphFile, PatchCb
21 from rdfdb.patch import ALLSTMTS, Patch 21 from rdfdb.patch import ALLSTMTS, Patch
22 from rdfdb.rdflibpatch import patchQuads 22 from rdfdb.rdflibpatch import patchQuads
23 reactor = cast(IReactorCore, twisted.internet.reactor)
23 24
24 # gatherProcessStats() 25 # gatherProcessStats()
25 # stats = scales.collection( 26 # stats = scales.collection(
26 # '/webServer', 27 # '/webServer',
27 # scales.IntStat('clients'), 28 # scales.IntStat('clients'),
356 from twisted.python import log as twlog 357 from twisted.python import log as twlog
357 twlog.startLogging(sys.stdout) 358 twlog.startLogging(sys.stdout)
358 359
359 reactor.listenTCP( 360 reactor.listenTCP(
360 port, 361 port,
361 cyclone.web.Application(handlers=[ 362 cyclone.web.Application(
362 (r'/graph', GraphResource), 363 handlers=[
363 (r'/syncedGraph', WebsocketClient), 364 (r'/graph', GraphResource),
364 (r'/prefixes', Prefixes), 365 (r'/syncedGraph', WebsocketClient),
365 # (r'/stats/(.*)', StatsHandler, { 366 (r'/prefixes', Prefixes),
366 # 'serverName': 'rdfdb' 367 # (r'/stats/(.*)', StatsHandler, {
367 # }), 368 # 'serverName': 'rdfdb'
368 (r'/(.*)', NoExts, { 369 # }),
369 "path": FilePath(__file__).sibling("web").path, 370 (r'/(.*)', NoExts, {
370 "default_filename": "index.html" 371 "path": FilePath(__file__).sibling("web").path,
371 }), 372 "default_filename": "index.html"
372 ], 373 }),
373 debug=True, 374 ],
374 db=db)) 375 debug=True,
376 db=db))
375 log.info("serving on %s" % port) 377 log.info("serving on %s" % port)
376 reactor.run() 378 reactor.run()
377 379
378 380
379 if __name__ == '__main__': 381 if __name__ == '__main__':