blob: 43c4795587a1f94072001d0e4cfa386c433235ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import pdb
import hashlib
from logger import main_log
#TODO: make component registry a singleton
def initRegistry():
#TODO: don't overwrite existing registry
if not 'Registry' in globals():
globals()['Registry'] = {}
def clearRegistry():
initRegistry()
def removeComponent(cid):
globals()['Registry'].pop(cid)
def getComponent(cid):
return globals()['Registry'][cid]
#Registry of all components of the light system
#TODO: pick a graceful failure behavior and implement it
def registerComponent(component, cid=None):
if cid != None:
globals()['Registry'][cid] = component
else:
try:
cid = component['Id']
except KeyError:
cid = getNewId()
component['Id'] = cid
main_log.debug(cid + 'automatically assigned')
globals()['Registry'][cid] = component
return cid
def removeComponent(cid):
globals()['Registry'].pop(cid)
def getComponent(cid):
return globals()['Registry'][cid]
def getNewId():
trialKey = len(globals()['Registry'])
trialId = hashlib.md5(str(trialKey)).hexdigest()
while trialId in globals()['Registry']:
trialKey += 1
trialId = hashlib.md5(str(trialKey)).hexdigest()
return trialId
|