def getServerDependencyMap(plugin,serverName): factory = ServerNetworkFactory(plugin.mainDaemon) serversNetwork=factory.buildNetwork(plugin.mainDaemon.ETC_DIR) returnValue = {} returnValue['available'] = {} returnValue['disabled'] = {} returnValue['existing'] = {} for possibleServer in serversNetwork.getSortedNodeListIndex(): if possibleServer != serverName: returnValue['available'][possibleServer] = iniToDict(os.path.join(plugin.mainDaemon.SERVERS_DIR,possibleServer + ".ini"))["server"]["comment"] try: serversNetwork.addDependency(serverName, possibleServer) #if all went well, remove dependency try: serversNetwork.removeDependency( possibleServer,serverName ) except ValueError: pass except DependencyException as e: returnValue['available'].pop(possibleServer) returnValue['disabled'][possibleServer] = e.list except AdditionError: #Happens if dependency already exists returnValue['existing'][possibleServer] = returnValue['available'].pop(possibleServer) return returnValue
def _getObjectDict(self,returnVariable,objectFolder): #Sanitize if the folder does not exist if not os.path.isdir(objectFolder): return {returnVariable : "{}"} returnValue = {} for obj in os.listdir(objectFolder): obj = os.path.join(objectFolder,obj) objectDict = iniToDict(obj) objName = os.path.splitext(os.path.basename(obj))[0] returnValue[objName] = objectDict return {returnVariable : json.dumps(returnValue)}
def _getAvailableServerObjs(self,server,obj): returnValue = OrderedDict() serverPath = os.path.join(self.mainDaemon.SERVERS_DIR,server + ".ini") serverDict = iniToDict(serverPath) #Get checked items in order try: for objItem in json.loads(serverDict["server"][obj + "s"]): returnValue[objItem] = serverDict[objItem] except: pass serverDict.pop("server") for section in serverDict.keys(): if obj in serverDict[section] and not section in returnValue: #we have an outlet/tester returnValue[section] = serverDict[section] return returnValue