1979
|
1 #!bin/python
|
|
2
|
|
3 from run_local import log
|
|
4
|
|
5 from rdflib import URIRef
|
|
6 from twisted.internet import reactor
|
|
7 from twisted.internet.defer import inlineCallbacks, Deferred
|
|
8
|
|
9 import logging
|
|
10 import optparse
|
|
11 import os
|
|
12 import time
|
|
13 import treq
|
|
14 import cyclone.web, cyclone.websocket, cyclone.httpclient
|
|
15 from greplin import scales
|
|
16
|
|
17 from cycloneerr import PrettyErrorHandler
|
|
18
|
|
19 from light9.namespaces import L9, RDF
|
|
20 from light9 import networking, showconfig
|
|
21 from rdfdb.syncedgraph import SyncedGraph
|
|
22
|
|
23 from greplin.scales.cyclonehandler import StatsHandler
|
|
24 from light9.effect.settings import DeviceSettings
|
|
25 from rdfdb.patch import Patch
|
|
26
|
|
27 stats = scales.collection('/webServer', scales.PmfStat('setAttr',
|
|
28 recalcPeriod=1))
|
|
29
|
1998
|
30
|
1979
|
31 def launch(graph):
|
|
32 if 0:
|
1998
|
33 reactor.listenTCP(
|
|
34 networking.captureDevice.port,
|
|
35 cyclone.web.Application(handlers=[
|
|
36 (r'/()', cyclone.web.StaticFileHandler, {
|
|
37 "path": "light9/web",
|
|
38 "default_filename": "patchServer.html"
|
|
39 }),
|
|
40 (r'/stats/(.*)', StatsHandler, {
|
|
41 'serverName': 'patchServer'
|
|
42 }),
|
|
43 ]),
|
|
44 interface='::',
|
|
45 )
|
1979
|
46 log.info('serving http on %s', networking.captureDevice.port)
|
|
47
|
|
48 def prn():
|
|
49 width = {}
|
|
50 for dc in graph.subjects(RDF.type, L9['DeviceClass']):
|
|
51 for attr in graph.objects(dc, L9['attr']):
|
1998
|
52 width[dc] = max(
|
|
53 width.get(dc, 0),
|
|
54 graph.value(attr, L9['dmxOffset']).toPython() + 1)
|
|
55
|
|
56 user = {} # chan: [dev]
|
1979
|
57 for dev in set(graph.subjects(L9['dmxBase'], None)):
|
|
58 dc = graph.value(dev, RDF.type)
|
|
59 base = graph.value(dev, L9['dmxBase']).toPython()
|
|
60 for offset in range(0, width[dc]):
|
|
61 chan = base + offset
|
|
62 user.setdefault(chan, []).append(dev)
|
|
63
|
|
64 for chan in range(1, max(user) + 1):
|
|
65 dev = user.get(chan, None)
|
|
66 print(f'chan {chan} used by {dev}')
|
1998
|
67
|
1979
|
68 graph.addHandler(prn)
|
1998
|
69
|
|
70
|
1979
|
71 def main():
|
|
72 parser = optparse.OptionParser()
|
|
73 parser.add_option("-v",
|
|
74 "--verbose",
|
|
75 action="store_true",
|
|
76 help="logging.DEBUG")
|
|
77 (options, args) = parser.parse_args()
|
|
78 log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
|
|
79
|
|
80 graph = SyncedGraph(networking.rdfdb.url, "captureDevice")
|
|
81
|
|
82 graph.initiallySynced.addCallback(lambda _: launch(graph)).addErrback(
|
|
83 log.error)
|
|
84 reactor.run()
|
|
85
|
|
86
|
|
87 if __name__ == '__main__':
|
|
88 main()
|