# running from IOC_Status.opi # bild a dinamic list of IOCs # Jan 2018 # authors: Vanik Kakoyan and Hovanes Egiyan # from org.csstudio.opibuilder.scriptUtil import PVUtil from org.csstudio.opibuilder.scriptUtil import WidgetUtil from org.csstudio.opibuilder.scriptUtil import ConsoleUtil from org.csstudio.utility.pv import PVFactory from org.csstudio.opibuilder.scriptUtil import ColorFontUtil from java.lang import Thread, Runnable import re import os import time import sys, glob import threading from operator import * appDirectory = os.getenv( "APP" ) iocDirectory = appDirectory + "/scripts/IOC/" sys.path.append( iocDirectory ) import iocPortMap # iocPortMap #import iocPortMap class MyTask_table(Runnable): def __init__(self, wid ) : self.widget = wid #self.widget.removeAllChildren() #self.widget.setPropertyValue("height",1140.0) self.lc = [] self.addedChannels = [] return def AddContainer(self) : columnMutex.acquire() for iLC in range( 0, len(self.lc) ): self.widget.addChildToBottom( self.lc[iLC] ) #self.widget.addChildToRight( self.lc[iLC] ) #ConsoleUtil.writeInfo("Added "+str(iLC+1) + " of " + str(len(self.lc))) #ConsoleUtil.writeInfo("Added PVName "+str(self.addedChannels[iLC]) ) columnMutex.release() return #----- def run(self): columnMutex.acquire() try: Pref= widget.getParent().getMacroValue("pref") grName = widget.getParent().getMacroValue("grName") NColumn = self.widget.getMacroValue("nColumn") ##ConsoleUtil.writeInfo( "-----------------" ) ##ConsoleUtil.writeInfo( "Number of groups: " + str( len(iocPortMap.iocGroupMap) ) ) #-- for all Groups # ConsoleUtil.writeInfo( "Path: " + iocDirectory ) for groupName in iocPortMap.iocGroupMap.keys() : if groupName != str(grName): continue ##ConsoleUtil.writeInfo( " Group "+" *** "+str(groupName) + " *** " ) #----------------- iocNameList = iocPortMap.iocGroupMap[groupName] N_ioc=0 for iocTuple in sorted( iocPortMap.hostPortMap.items(),key=lambda x:getitem(x[1],'title') ): iocName=str(iocTuple[0]) #ConsoleUtil.writeInfo( "iocName : "+str(iocTuple[0])) if iocName not in iocNameList: continue if iocTuple[1]["enable"] != "enabled": #ConsoleUtil.writeInfo("**** EnableDisable ="+ str(iocTuple[1]["enable"])) continue N_ioc=N_ioc+1 ##ConsoleUtil.writeInfo( "iocNameList : "+str(iocNameList)) ##ConsoleUtil.writeInfo( "-N IOCs in group "+ str(groupName) +": "+ str(len( iocNameList ))+"; 'enabled': "+ str(N_ioc)) NiocInColumn=int(round(N_ioc/2.)) height_n=(NiocInColumn)*42.3 if groupName == "GENERAL": NiocInColumn=int(round(N_ioc/3.)) height_n=(NiocInColumn+1)*42.3 self.widget.setPropertyValue("height",height_n) i=0 ##ConsoleUtil.writeInfo( " N ioc in column: "+str(NiocInColumn)) ##ConsoleUtil.writeInfo( " Column: " + str(NColumn)) for iocTuple in sorted( iocPortMap.hostPortMap.items(),key=lambda x:getitem(x[1],'title') ): iocName=str(iocTuple[0]) #ConsoleUtil.writeInfo( "iocName : "+str(iocTuple[0])) IOC_LABEL= iocTuple[1]["title"] #ConsoleUtil.writeInfo( "IOC_LABEL ="+ IOC_LABEL) if iocTuple[1]["enable"] == "disabled": #ConsoleUtil.writeInfo("****IOC_LABEL ="+ str(IOC_LABEL) +" ++EnableDisable ="+ str(iocTuple[1]["enable"])) continue if iocName not in iocNameList: continue if (int(NColumn)==1): i=i+1 if i> NiocInColumn: ##ConsoleUtil.writeInfo( "continue : "+str(i)) continue if (int(NColumn)==2): i=i+1 if (i<= NiocInColumn or i> NiocInColumn*2): ##ConsoleUtil.writeInfo( "continue : "+str(i)) continue if (int(NColumn)==3): i=i+1 if i<= NiocInColumn*2: ##ConsoleUtil.writeInfo( "continue : "+str(i)) continue ##ConsoleUtil.writeInfo(str(i)+ " iocName: "+str(iocTuple[0]) + "; IOC_Label: "+ str(IOC_LABEL)+ "; "+str(iocTuple[1]["enable"])) ioc=iocName #----------- locLC = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer") locLC.setPropertyValue("opi_file", "statusOfSingleIOC.opi") locLC.setPropertyValue("auto_size", True) locLC.setPropertyValue("zoom_to_fit", False) locLC.setPropertyValue("border_style", 0) locLC.setPropertyValue("x", 2 ) locLC.addMacro("IOC_LABEL", IOC_LABEL) locLC.addMacro("ioc", ioc) #self.addedChannels.append(IOC_LABEL) self.lc.append( locLC ) return except Exception, e: ConsoleUtil.writeInfo( "There was a problem : " + str(e) ) raise e finally: #ConsoleUtil.writeInfo( "Finally" ) columnMutex.release() return ####################################################################################################################################### task = MyTask_table( widget ) columnMutex = threading.BoundedSemaphore(1) thread = Thread( task ) thread.start() Thread.sleep(1) #task.AddContainer() while( not columnMutex.acquire( 0 ) ) : #ConsoleUtil.writeInfo( "Locked" ) Thread.sleep( 1 ) columnMutex.release() #ConsoleUtil.writeInfo( "Now unlocked" ) task.AddContainer()