import Nice
import BasdaMoccaX as moccaX
import BasdaMoccaWheel as moccaW

def get_named_pos(al):
	endPointSvc = "[ALIAS={}]".format(al)
	print (endPointSvc)
	if "dep" in al:
	    service1 = moccaX.X.connectWithEndpoint(al, endPointSvc)
	if "_w" in al:
	    service2 = moccaW.Wheel.connectWithEndpoint(al, endPointSvc)
	endPointDev = "[ALIAS={}-dev]".format(al)
	print (endPointDev)
	epDev = Nice.Endpoint.fromString(endPointDev)

	niceApp = Nice.AppConfigClient.connectWithEndpoint(epDev, True)

	namedPosIdx = 0
	niceNode = niceApp.config().node("1.CFG.NAMED_POS.ABS.{:d}".format(namedPosIdx))
	while niceNode.hasLeaf():
	    niceProp = niceNode.leaf()
	    print ("{:d} - {:s}".format(namedPosIdx, niceProp.getAttrString("NAME")))
	    namedPosIdx += 1
	    niceNode = niceApp.config().node("1.CFG.NAMED_POS.ABS.{:d}".format(namedPosIdx))

aliasName = ["inbeam_dep", "apodizer_w"]


#get_named_pos(aliasName[0])
get_named_pos(aliasName[1])
