def _setINIFile(self,path,iniDict): path = os.path.join(self.mainDaemon.ETC_DIR,path) #create folder if does not exist pathDir = os.path.dirname(path) if not os.path.isdir(pathDir): os.mkdir(pathDir) iniSource = getINIstringtoDict(self._getINIFile(path)) newConfig={} for section in iniDict.keys(): if section in iniSource: newConfig[section] = mergeDicts(iniSource[section],iniDict[section]) else: newConfig[section] = iniDict[section] config = dictToConfig(newConfig) try: #shutil.copy(path,path + "." + str(int(time.time()))) pass except: pass config.write(open(path,"w")) #print newConfig return {"succeeded": True}
def loadINIFileConfig(configPath): ''' Get the config on an ini file @param configPath: the path to the config relative to etc @return: a dict of the config ''' iniString = getINIFile(configPath) INIFileDict = getINIstringtoDict(iniString) return INIFileDict
def deleteINISectionCommand(self,path,section): try: iniFileDict = getINIstringtoDict(self._getINIFile(path)) iniFileDict.pop(section) self._setINIFile(path,iniFileDict) return {"succeeded" : True} except: pass return {"succeeded" : False, "error" : "Failed remove section " + section + " in file " + path}