2
0

4 Commits 9cbad3a037 ... 859dde2cbd

Autor SHA1 Nachricht Datum
  micha 859dde2cbd clean pylint ... vor 1 Monat
  micha f0bb8a4b6c cleanup pylint unused_var, fix:cursesDummy vor 1 Monat
  micha 7545b957f8 fix import with isort vor 1 Monat
  micha 4924e29d78 add cProfile vor 1 Monat
3 geänderte Dateien mit 55 neuen und 48 gelöschten Zeilen
  1. 53 48
      ArtNetProcessor.py
  2. 1 0
      start.sh
  3. 1 0
      start_ASP.sh

+ 53 - 48
ArtNetProcessor.py

@@ -4,6 +4,8 @@
 #from builtins import str, open, range, dict
 #from builtins import *
 
+# pylint: disable=redefined-outer-name,invalid-name,trailing-whitespace,missing-function-docstring
+
 """
 This file is part of librelight.
 
@@ -23,6 +25,7 @@ along with librelight.  If not, see <http://www.gnu.org/licenses/>.
 """
 
 import sys
+
 if sys.version_info.major <= 2:
     print("exit Python3 is needet")
     sys.exit()
@@ -38,13 +41,12 @@ if "__file__" in dir():
 else:
     sys.stdout.write("\x1b]2;"+str("__file__")+"\x07") # terminal title
 
+import json
+import os
 import string
 import time
-import os
-
-import json
-
 from optparse import OptionParser
+
 parser = OptionParser()
 parser.add_option("-r", "--recive", dest="recive",
                   help="set recive ip like --recive 10.")
@@ -71,6 +73,7 @@ if cython:
 
 from collections import OrderedDict
 from datetime import datetime
+
 #print(dir())
 #input()
 # ============================================================   
@@ -93,7 +96,7 @@ def memcachd_index_clear():
 
 memcachd_index_clear()
 
-def update_memcachd_index(key,val="",active=-1):
+def update_memcachd_index(key,active=-1): # val=""
     try:
         _index =  mc.get("index")
         #print("A",_index)
@@ -114,7 +117,8 @@ def update_memcachd_index(key,val="",active=-1):
 if mc:
     INDEX="index-artpoll"
     mc.set(INDEX ,{})
-def update_mc_artpoll_index(key,val=""):
+
+def update_mc_artpoll_index(key): #,val=""):
     try:
         INDEX="index-artpoll"
         _index =  mc.get(INDEX)
@@ -135,16 +139,19 @@ def update_mc_artpoll_index(key,val=""):
 
 def count_active_dmx_ch(dmx):
     active = 0
-    for i,v in enumerate(dmx):
+    for _,v in enumerate(dmx):
         if type(v) is int and v>=1:
-            if active < 0:
-                active = 0
+            #if active < 0:
+            #    active = 0
+            active = max(active,0)
             active += 1
     return active
 # ============================================================   
 # Text Grafik Curses =========================================   
 # ============================================================   
 import curses
+
+
 class CursesDummy():
     def __init__(self):
         self.sel_host=Pager()
@@ -153,7 +160,6 @@ class CursesDummy():
         self.sel_univ.wrap=1
         self.sel_mode=Pager()
         self.sel_mode.wrap=1
-        pass
     def dir(self):
         pass
     def test(self):
@@ -166,6 +172,7 @@ class CursesDummy():
         pass
     def inp(self):
         return ""
+    def loop(self,**args):
         pass
     def read(self):
         pass
@@ -243,8 +250,6 @@ class Window():
         self.clear()
         curses.beep()
 
-        frame = 10
-        i = 0
     def addstr(self,x,y,txt):
         self.myscreen.addstr(x, y, txt ) #zeile,spalte,text
     
@@ -290,14 +295,14 @@ class Window():
             self.myscreen.addstr(0, 1, str(self._inp) ) #zeile,spalte,text
             self.myscreen.refresh()
             return self._inp
-        except:
+        except Exception as _:
             pass#self._inp=""
 
     def clear(self):
         self.myscreen.clear()
         self.myscreen.border(0)
-        curses.nocbreak();
-        self.myscreen.keypad(0);
+        curses.nocbreak()
+        self.myscreen.keypad(0)
         #self.read()
         curses.echo()
         curses.resetty()
@@ -377,7 +382,7 @@ class Window():
                 try:
                     x=int(cmd2[1]) 
                     self.sel_host.set(x)
-                except:
+                except Exception as _:
                     pass
         else:
             self.cmd.append(inp2)
@@ -407,13 +412,13 @@ class Window():
             lines = [ ]
             #print("cmd:",cmd)
             lines.append(" host:"+ hostname +":"+netns+" CMD:" + "".join(self.cmd) )
-            if self.mode=="help" or  self.mode=="?":
+            if self.mode in ["help","?"]:
                 lines.append("HILFE[h]: " )
                 lines.append("MODE [m]: inp, in2 in1 " )
                 lines.append("UNIV [u]: 0-16  " )
                 lines.append(" " )
                 lines.append("HILFE " )
-            elif self.mode=="dmx" or self.mode == "DMX":
+            elif self.mode in ["dmx","DMX"]:
                 self.ttime = time.time()
                 dmx=self.ohost.get(host,univ=univ2)#univ=head_uni)
                 info=self.ohost.info()
@@ -462,7 +467,7 @@ class Window():
                         lines.append(str(self.ttime))
 
                 #screen.draw_lines(lines)
-            elif self.mode=="ltp" or self.mode=="LTP":
+            elif self.mode in ["ltp","LTP"]:
                 self.ttime = time.time()
                 dmx=self.ohost.get(univ=univ2)#head_uni)
                 #univ2=""
@@ -490,7 +495,7 @@ class Window():
                 host=""
                 univ2=""
                 info=self.ohost.info()
-                jinfo = ""
+
                 for i in info:
                     xl = json.dumps(i) + "=======X " # live
                     lines.append( xl )
@@ -521,7 +526,7 @@ class Window():
             lines.insert(0,tmp)
 
             tmp = ""
-            sel_univ_data = self.sel_univ.data
+            #sel_univ_data = self.sel_univ.data
             #sel_univ_data.sort()
             tmp += " univ:"+ (str(self.sel_univ.data))#.ljust(20," "))
             tmp += " list:"+ (str(self.sel_host.data))#.ljust(20," "))
@@ -542,7 +547,7 @@ class UniversBuffer():
         self.__universes_flag = {}
         self.__universes_x_frames = {}
         self.__universes_x_time = {}
-        self.__universes_count = {}
+        #self.__universes_count = {}
         self.__universes_timer = {} 
         self.__universes_matrix = ["."]*512 
         self.__universes_info = {}
@@ -640,7 +645,7 @@ class UniversBuffer():
                 v = self.__universes_dmx[host][i]
                 dmx[i] = v
         return dmx
-    def get_mtx(self,host=""):
+    def get_mtx(self):#,host=""):
         return self.__universes_matrix
     def info(self):
         return self.__universes_info
@@ -655,7 +660,7 @@ class HostBuffer():
     def __init__(self):
         """buffer hosts and route data into universes
         """
-        self.__hosts = [] # LTP order
+        #self.__hosts = [] # LTP order
         self.__universes = OrderedDict() # {} # 192.168.0.1 = [0]*512
         #self.update(host="localhost",univ=0,dmxframe=[6]*512)
         dmxframe = [0]*512
@@ -667,8 +672,7 @@ class HostBuffer():
     def get(self,host="", univ=""):
         if str(univ) in self.__universes:
              return self.__universes[str(univ)].get(host)
-        else:
-             return [-8]*512
+        return [-8]*512
     def hosts(self):
         hosts = []
         for univ in  self.__universes:
@@ -704,20 +708,24 @@ class HostBuffer():
 # ============================================================   
 # Network ====================================================   
 # ============================================================   
-import socket, struct
+
+import socket
+import struct
+
 hostname = socket.gethostname()
 netns = "none"
 x = os.popen("ip netns identify $$")
 xx = x.read()
 if xx:
     netns = xx.strip()
-import fcntl  #socket control
-import errno
+import fcntl  # socket control
+
+
 def toPrintable(nonprintable):
     out = ""
     
     for i in str(nonprintable):
-        printable = string.ascii_letters + string.digits +"/()=?{[]}\;:,.-_ "
+        printable = string.ascii_letters + string.digits +r"/()=?{[]}\;:,.-_ "
         if str(i) in printable :
             out += str(i)
     return out
@@ -741,7 +749,7 @@ def ArtPollCheck(data,addr):
          try:
                k = "{}:{}".format(addr[0],opcode[0])
                mc.set(k, data)
-               update_mc_artpoll_index(k,val="")
+               update_mc_artpoll_index(k) #,val="")
          except Exception as e:
                print("ArtPollCheck err:",e)
 
@@ -839,7 +847,7 @@ class IN_Socket():
                 self.univ = -1
                 try:
                     self.head = struct.unpack("!8sHBBBBHBB" , head )
-                except Exception as e:
+                except Exception as _:
                     pass#print( "======E09823" , e)
 
 
@@ -852,14 +860,14 @@ class IN_Socket():
                 if self.host.startswith("127."): #allways recive localhost on port 
                     self.__poll = 1
                     return 1
-                elif not options.recive:
+                if not options.recive:
                     self.__poll = 1
                     return 1
-                elif self.host.startswith(options.recive): 
+                if self.host.startswith(options.recive): 
                     self.__poll = 1
                     return 1
-                else:
-                    self.__poll = 0
+                
+                self.__poll = 0
                 
                 addr = str(addr)
                 univ = str(univ)
@@ -879,7 +887,7 @@ class IN_Socket():
                     print('recv timed out, retry later')
                 else:
                     print(e)
-            except socket.error as e:
+            except Exception as _:  # socket.error as e:
                 pass
     
     def recive(self):
@@ -898,10 +906,6 @@ class IN_Socket():
 # ============================================================   
 
 
-import time
-import socket
-import struct
-import random
 
 class ArtNetNode():
     """simple Object to generate raw ArtNet like Network packages 
@@ -916,7 +920,7 @@ class ArtNetNode():
         print("\n"+self.__doc__+"\n")
         try: 
             univ = int(univ)
-        except:
+        except Exception as _:
             print("errror univ",univ ,"is not int ... set to 7")
             univ = 7
         self.univ=univ
@@ -1013,7 +1017,8 @@ class ArtNetNode():
         if self.stamp + (1/60) <= time.time():
             self.send()
 
-def artnet_test():
+def artnet_test(): 
+    # pylint: disable=protected-access
     artnet = ArtNetNode()
     artnet._tes_frame()
 
@@ -1023,7 +1028,7 @@ def artnet_get_opcode(head):
     name ="unkown"
     try:
         opcode=hex(struct.unpack('<h', head[8:10])[0])
-    except:
+    except Exception as _:
         print("opcode error",[head])
 
     if opcode == '0x5000':
@@ -1117,6 +1122,7 @@ class Main():
         ohost = HostBuffer()
         
         screen=Window()
+        #screen=CursesDummy()
         screen.exit()
         screen.ohost = ohost
                 
@@ -1127,12 +1133,12 @@ class Main():
         #artnet_out._test_frame()
         if options.testuniv:
             artnet = ArtNetNode(univ=options.testuniv)
+            # pylint: disable=protected-access
             artnet._test_frame()
 
         #ysocket = Socket(bind='127.0.0.1' ,port=6555)
         in_socket = IN_Socket()
 
-        xt = time.time()
         ohost_buf = {}
         ohost_timer = Timer(1/30.,start=0) # 0.03333
         send_timer = Timer(1/30.) # 0.03333
@@ -1141,11 +1147,11 @@ class Main():
             while 1:
                 poll_flag = 0
                 if options.testuniv:
+                    # pylint: disable=protected-access
                     artnet._test_frame()
                 #artnet_out._test_frame()
                 #if in_socket.poll():
                 while in_socket.poll():
-                    xt = time.time()
                     poll_flag = 1
                     x = in_socket.recive()
                     if x["host"] == options.recive:
@@ -1195,13 +1201,11 @@ class Main():
 
                     #x=ohost.get(univ=univ2)
                     info=ohost.info()
-                    jinfo = ""
 
                     for i in info:
                         univ = i
                         if str(univ) == "54":
                             break
-                        xl = json.dumps(univ) + "======= " #XX
                         ltp=ohost.get(univ=i)
                         
                         try:
@@ -1217,6 +1221,7 @@ class Main():
 
                 if not poll_flag: 
                     time.sleep(.001)
+
                 screen.loop()
         finally:
             pass

+ 1 - 0
start.sh

@@ -1,2 +1,3 @@
 netns=$(ip netns identify $$)
 python3 /opt/LibreLight/ASP/ArtNetProcessor.py netns=$netns
+#python3  -m cProfile  /opt/LibreLight/ASP/ArtNetProcessor.py netns=$netns

+ 1 - 0
start_ASP.sh

@@ -28,3 +28,4 @@ if [ -f $CONFIG ] ; then
 fi
 
 python3 $path/ASP/ArtNetProcessor.py --recive $ARTNET_INPUT_NET --sendto $ARTNET_NODE_NET netns=$netns
+#python3 -m cProfile $path/ASP/ArtNetProcessor.py --recive $ARTNET_INPUT_NET --sendto $ARTNET_NODE_NET netns=$netns