changeset 2227:fe3543310d34

move uriTail to a better layer of code
author drewp@bigasterisk.com
date Tue, 23 May 2023 23:56:20 -0700
parents 1065c634e4a8
children f45814654fdb
files light9/collector/collector.py light9/collector/output.py light9/effect/sequencer/eval_faders.py light9/newtypes.py
diffstat 4 files changed, 24 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/light9/collector/collector.py	Tue May 23 23:55:06 2023 -0700
+++ b/light9/collector/collector.py	Tue May 23 23:56:20 2023 -0700
@@ -12,18 +12,11 @@
 from light9.effect.settings import DeviceSettings
 from light9.namespaces import L9, RDF
 from light9.newtypes import (ClientSessionType, ClientType, DeviceAttr, DeviceClass, DeviceSetting, DeviceUri, DmxIndex, DmxMessageIndex, OutputAttr,
-                             OutputRange, OutputUri, OutputValue, UnixTime, VTUnion)
+                             OutputRange, OutputUri, OutputValue, UnixTime, VTUnion, uriTail)
 
 log = logging.getLogger('collector')
 
 
-def uriTail(u: URIRef) -> str:
-    tail = u.rstrip('/').rsplit('/', 1)[1]
-    if not tail:
-        tail = str(u)
-    return tail
-
-
 def makeDmxMessageIndex(base: DmxIndex, offset: DmxIndex) -> DmxMessageIndex:
     return DmxMessageIndex(base + offset - 1)
 
--- a/light9/collector/output.py	Tue May 23 23:55:06 2023 -0700
+++ b/light9/collector/output.py	Tue May 23 23:56:20 2023 -0700
@@ -1,13 +1,16 @@
 import asyncio
-from typing import cast
-from rdflib import URIRef
+import logging
 import socket
 import struct
 import time
+from typing import cast
+from light9.newtypes import uriTail
+
 import usb.core
-import logging
-from twisted.internet import threads, reactor, task
-from twisted.internet.interfaces import IReactorCore, IReactorTime
+from rdflib import URIRef
+from twisted.internet import reactor, task
+from twisted.internet.interfaces import IReactorCore
+
 from light9.metrics import metrics
 
 log = logging.getLogger('output')
@@ -39,7 +42,7 @@
 
     def shortId(self) -> str:
         """short string to distinguish outputs"""
-        return self.uri.rstrip('/').rsplit('/')[-1]
+        return uriTail(self.uri)
 
     def update(self, buf: bytes) -> None:
         """caller asks for the output to be this buffer"""
--- a/light9/effect/sequencer/eval_faders.py	Tue May 23 23:55:06 2023 -0700
+++ b/light9/effect/sequencer/eval_faders.py	Tue May 23 23:56:20 2023 -0700
@@ -1,22 +1,18 @@
-import asyncio
-from dataclasses import dataclass
 import logging
 import time
-from typing import Callable, Coroutine, List, Optional, cast
-from light9.collector.collector import uriTail
-from light9.typedgraph import typedValue
+from dataclasses import dataclass
+from typing import List, Optional, cast
 
 from rdfdb import SyncedGraph
 from rdflib import URIRef
+from rdflib.term import Node
 
 from light9.effect import effecteval
-from light9.effect.sequencer import Note
 from light9.effect.settings import DeviceSettings, EffectSettings
-from light9.effect.simple_outputs import SimpleOutputs
 from light9.metrics import metrics
 from light9.namespaces import L9, RDF
-from light9.newtypes import EffectAttr, EffectUri, NoteUri, UnixTime
-from rdflib.term import Node
+from light9.newtypes import EffectAttr, EffectUri, UnixTime
+from light9.typedgraph import typedValue
 
 log = logging.getLogger('seq.fader')
 
@@ -68,7 +64,7 @@
             effect = typedValue(EffectUri, self.graph, fader, L9['effect'])
             setting = typedValue(Node, self.graph, fader, L9['setting'])
             setAttr = typedValue(EffectAttr,  self.graph, setting, L9['effectAttr'])
-            self.faders.append(Fader(self.graph, cast(URIRef, fader), effect, setAttr))           
+            self.faders.append(Fader(self.graph, cast(URIRef, fader), effect, setAttr))
 
         # this could go in a second, smaller addHandler call to avoid rebuilding Fader objs constantly
         for f in self.faders:
--- a/light9/newtypes.py	Tue May 23 23:55:06 2023 -0700
+++ b/light9/newtypes.py	Tue May 23 23:56:20 2023 -0700
@@ -12,7 +12,7 @@
 DmxMessageIndex = NewType('DmxMessageIndex', int)  # 0..511
 DeviceAttr = NewType('DeviceAttr', URIRef)  # e.g. :rx
 EffectClass = NewType('EffectClass', URIRef)  # e.g. effect:chase
-EffectUri = NewType('EffectUri', URIRef) # unclear when to use this vs EffectClass
+EffectUri = NewType('EffectUri', URIRef)  # unclear when to use this vs EffectClass
 EffectAttr = NewType('EffectAttr', URIRef)  # e.g. :chaseSpeed
 NoteUri = NewType('NoteUri', URIRef)
 OutputAttr = NewType('OutputAttr', URIRef)  # e.g. :xFine
@@ -30,3 +30,10 @@
 # Alternate output range for a device. Instead of outputting 0.0 to
 # 1.0, you can map that range into, say, 0.2 to 0.7
 OutputRange = NewType('OutputRange', Tuple[float, float])
+
+
+def uriTail(u: URIRef) -> str:
+    tail = u.rstrip('/').rsplit('/', 1)[1]
+    if not tail:
+        tail = str(u)
+    return tail