123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- #!/usr/bin/python3
- import json
- import memcache
- import time
- mc = None
- def _connect():
- try:
- mc = memcache.Client(['127.0.0.1:11211'], debug=0)
- except:
- mc = None
- return mc
- mc = _connect()
- def mc_set_fix(index="fix",data=[]):
- #index = mc.get("index")
- mc.set("fix", data)
- def mc_set_patch_loop(FIXTURES):
- _FIXTURES = FIXTURES
- time.sleep(10)
- print("start loop MC_PATCH ...")
- while 1:
- try:
- mc_set_patch(FIXTURES)
- except Exception as e:
- print(e)
- time.sleep(5)
- def mc_set_patch(FIXTURES):
- _FIXTURES = FIXTURES
- #print("mc_set_patch")
- index_patch = []
- for fix,val in _FIXTURES.fixtures.items():
- #print("FIX",fix,val)
- val = json.dumps(val).encode()
- mc.set("PATCH-"+str(fix),val)
- index_patch.append(fix)
- val = json.dumps(index_patch).encode()
- mc.set("PATCH-INDEX",val)
- def get_programmer():
- if mc is None:
- return
- DATA=mc.get("fix")#cmd)
- out=[]
- for k,v in DATA.items():
- ok=0
- for kk,vv in v["ATTRIBUT"].items():
- if kk.startswith("_"):
- continue
- if vv["ACTIVE"]:
- tmp={"ID":k,"NAME":v["NAME"],"ATTR":kk,"NR":vv["NR"]} #,"FX3":vv["FX2"]}
- out.append(tmp)
- ok=1
- #if ok:
- # print()
- return out
- def get_patch():
- if mc is None:
- return
- index=mc.get("PATCH-INDEX") #index")#cmd)
- index=json.loads(index)
- out = []
- for v in index:
- patch=mc.get("PATCH-"+str(v)) #index")#cmd)
- patch=json.loads(patch)
- u = patch["UNIVERS"] #* 512
- d = patch["DMX"]
- attr = {}
- for a in patch["ATTRIBUT"]:
- nr =patch["ATTRIBUT"][a]["NR"]
- if nr <= 0:
- continue
- if a == "END":
- continue
- if a.startswith("_"):
- continue
- nr = nr + d + u*512
- attr[a] = nr-1
- tmp = {"FIX":v,"UNI":u,"DMX":d,"NR":nr,"ATTR":attr}
- out.append(tmp )
-
- return out
- def patch_order_by_fix(patch):
- out={}
- for p in patch:
- ID = p["FIX"]
- out[ID] = p
- #print("patch_order",[ID,p])
- return out
- def get_exec_meta(nr):
- data = {}
- try:
- data = mc.get("EXEC-META-"+str(nr))
- data = json.loads(data)
- except Exception as e:
- print(" ER1R mc...",e)
- return data
- modes = {}
- def modes_refresh():
- global modes
- try:
- data = mc.get("MODES")
- data = json.loads(data)
- modes = data
- except Exception as e:
- print(" ER7R mc...",e)
- print(mc)
- print(dir(mc))
- #time.sleep(3)
- return modes
- def modes_refresh_loop():
- time.sleep(3)
- while 1:
- modes_refresh()
- time.sleep(0.1)
|