Mercurial > code > home > repos > light9
comparison bin/patchserver @ 1979:19eef99e059e
start patchserver- shows final dmx usage
Ignore-this: 7ac19499001abffaa838f7b7dd5b919d
author | drewp@bigasterisk.com |
---|---|
date | Sat, 08 Jun 2019 09:16:08 +0000 |
parents | |
children | 3d28b1a54a29 |
comparison
equal
deleted
inserted
replaced
1978:7da21faf75b3 | 1979:19eef99e059e |
---|---|
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 | |
30 def launch(graph): | |
31 if 0: | |
32 reactor.listenTCP(networking.captureDevice.port, | |
33 cyclone.web.Application(handlers=[ | |
34 (r'/()', cyclone.web.StaticFileHandler, { | |
35 "path": "light9/web", | |
36 "default_filename": "patchServer.html" | |
37 }), | |
38 (r'/stats/(.*)', StatsHandler, { | |
39 'serverName': 'patchServer' | |
40 }), | |
41 ]), | |
42 interface='::', | |
43 ) | |
44 log.info('serving http on %s', networking.captureDevice.port) | |
45 | |
46 def prn(): | |
47 width = {} | |
48 for dc in graph.subjects(RDF.type, L9['DeviceClass']): | |
49 for attr in graph.objects(dc, L9['attr']): | |
50 width[dc] = max(width.get(dc, 0), graph.value(attr, L9['dmxOffset']).toPython() + 1) | |
51 | |
52 user = {} # chan: [dev] | |
53 for dev in set(graph.subjects(L9['dmxBase'], None)): | |
54 dc = graph.value(dev, RDF.type) | |
55 base = graph.value(dev, L9['dmxBase']).toPython() | |
56 for offset in range(0, width[dc]): | |
57 chan = base + offset | |
58 user.setdefault(chan, []).append(dev) | |
59 | |
60 for chan in range(1, max(user) + 1): | |
61 dev = user.get(chan, None) | |
62 print(f'chan {chan} used by {dev}') | |
63 graph.addHandler(prn) | |
64 | |
65 def main(): | |
66 parser = optparse.OptionParser() | |
67 parser.add_option("-v", | |
68 "--verbose", | |
69 action="store_true", | |
70 help="logging.DEBUG") | |
71 (options, args) = parser.parse_args() | |
72 log.setLevel(logging.DEBUG if options.verbose else logging.INFO) | |
73 | |
74 graph = SyncedGraph(networking.rdfdb.url, "captureDevice") | |
75 | |
76 graph.initiallySynced.addCallback(lambda _: launch(graph)).addErrback( | |
77 log.error) | |
78 reactor.run() | |
79 | |
80 | |
81 if __name__ == '__main__': | |
82 main() |