def _loadControllerConfig(controllerName):
    ''' Get the config Dict of a controller
    
    :param controllerName: The name of the controller
    :return: a config dict of the controller'''
    configPath= os.path.join(getControllerFolder() , controllerName + '.ini')
    return loadINIFileConfig(configPath)
def _loadServerConfig(serverName):
    ''' Get the config Dict of a server
    
    :param serverName: The name of the server
    :return: a config dict of the server'''
    configPath= _getServerConfigPath(serverName)
    return loadINIFileConfig(configPath)
def _loadTesterConfig(testerName):
    ''' Get the config Dict of a Tester
    
    :param testerName: The name of the tester
    :return: a config dict of the tester'''
    configPath= os.path.join(getTesterFolder() , testerName + '.ini')
    return loadINIFileConfig(configPath)
def _loadPDUConfig(PDUName):
    ''' Get the config Dict of a PDU
    
    :param PDUName: The name of the PDU
    :return: a config dict of the PDU'''
    configPath= os.path.join(getPDUFolder() , PDUName + '.ini')
    return loadINIFileConfig(configPath)
Beispiel #5
0
def _serverObjectDelete(objectType,name,objectName,path):
    item = objectType+ "s"
    serverDict = loadINIFileConfig(path)
    
    if not serverDict["server"][item].startswith("["):
        serverDict["server"][item] = '["' + serverDict["server"][item] + '"]'
        
    enabledOutlets = json.loads(serverDict["server"][item])
    if name in enabledOutlets:
        return "Please uncheck " + objectType + " in server before deleting."
    return True
Beispiel #6
0
def config_view(request):
    
    pluginList = getINIFolderTemplate("plugins")
    
    configPath = "config.ini"
    INIFileDict = loadINIFileConfig(configPath)
    iniTemplate = loadINIFileTemplate([configPath] + pluginList)
    INIFileDict = __fillINIwithTemplate(iniTemplate,INIFileDict)
    
    multiListChoices = _makeMultichoice("plugins","pluginlist",getAvailablePluginsList,INIFileDict)        
    
    return {"layout": site_layout(),
            "config_sidebar_head" : config_sidebar_head(),
            "config_sidebar_body" : config_sidebar_body(),
            "INI_InputArea_head" : INI_InputArea_head(),
            "INI_InputArea_body" : INI_InputArea_body(),
            "page_title": "General",
            "INIFileDict" : INIFileDict,
            "INIFileTemplate" : iniTemplate,
            "configPath" : configPath,
            "multiListChoices" : multiListChoices}
Beispiel #7
0
def updates_view(request):
    ''' This view takes a rendered INI config page and parses it back to an INI file
    '''
    rawiniDict={}
    iniDict={}
    
    jsonData = request.json_body["configINI"]
    iniFilePath = request.json_body["path"]
    
    for i in jsonData:
        rawiniDict[i["name"]] =i["value"]
    
    for key in rawiniDict.keys():
        dataKey = key.split("$")
        section = dataKey[0]
        item = dataKey[1]
        
        if not section in iniDict:
            iniDict[section] = {}
        
        multiListItem = item.split("*")
        if len(multiListItem) > 1: #multilist item detection
            item= multiListItem[0]
            itemOption=multiListItem[1]
            if not item in iniDict[section]:
                iniDict[section][item]=[]
            
            if itemOption != "__null__":
                iniDict[section][item].append(itemOption)
            
        else: #normal non-multilist item
            iniDict[section][item] = rawiniDict[key] 
    
    for section in iniDict.keys():
        for item in iniDict[section]:
            if type(iniDict[section][item]) == list:
                iniDict[section][item]=json.dumps(iniDict[section][item])
    

    #convert sections that were nameless on creation
    #TODO find a way to make this not hard-coded
    PARAMS_LIST=["outletParams","testParams","controlParams"]
    for param in PARAMS_LIST:
        if param in iniDict.keys():
            iniDict[iniDict[param]["name"]] = iniDict[section]
            iniDict[iniDict[param]["name"]].pop("name")
            iniDict.pop(param)
    
    #Add sections that were dropped
    oldINIDict = loadINIFileConfig(iniFilePath)
    for section in oldINIDict.keys():
        if not section in iniDict:
            iniDict[section] = oldINIDict[section]
            
    
    result =  setINIFile(iniFilePath,iniDict)
    
    returnValue={}
    
    if result["succeeded"] == "True":
        returnValue["color"] = "green"
        returnValue["message"] ="Configuration saved"
    else:
        returnValue["color"] = "red"
        returnValue["message"] ="Configuration failed"
    return returnValue