def PUT(self): # Enable/disable geolocation scanning # 0: disable geolocation scanning # others: enable geolocation scanning result = { 'SDCERR': weblcm_def.WEBLCM_ERRORS.get('SDCERR_FAIL'), 'InfoMsg': "AWM's geolocation scanning configuration only supported in LITE mode", 'geolocation_scanning_enable': 1, } # determine if in LITE mode litemode = False try: file = open("/etc/default/adaptive_ww", "r") for line in file: if re.search('LITE', line): litemode = True break except Exception as e: pass if not litemode: return result #prep for next error condition result['InfoMsg'] = 'No writable configuration file found' # check if there is a configuration file which contains a "scan_attempts:0" entry # if writable configuration file does not exist, scan_attempts can not be modified fp = cherrypy.request.app.config['weblcm'].get('awm_cfg', None) if not fp: return result d = Path(os.path.dirname(fp)) d.mkdir(exist_ok=True) geolocation_scanning_enable = cherrypy.request.json.get( 'geolocation_scanning_enable', 0) config = Config() with AWMCfgManage._lock: if os.path.isfile(fp): config.readFile(fp) if geolocation_scanning_enable: if config.exists("scan_attempts"): config.remove("", "scan_attempts") config.writeFile(fp) else: if not config.exists("scan_attempts"): config.addInteger("", "scan_attempts") config.setValue("scan_attempts", geolocation_scanning_enable) config.writeFile(fp) result['geolocation_scanning_enable'] = geolocation_scanning_enable result['SDCERR'] = weblcm_def.WEBLCM_ERRORS.get('SDCERR_SUCCESS') result['InfoMsg'] = '' return result
def test_greeting ( self ): config = Config () config.addString ( "", "test" ) config.setValue ( "test", "value" ) self.assert_ ( config.value ( "test" )[0] == "value" ) self.assert_ ( config.value ( "test" )[1] == True ) self.assert_ ( config.value ( "loose" )[1] == False ) config.writeFile ( "test.conf" ) self.assert_ ( os.path.exists ( "./test.conf" ) == True ) config.readFile ( "test.conf" ) self.assert_ ( config.value ( "test" )[0] == "value" ) self.assert_ ( config.value ( "test" )[1] == True ) os.remove ( "./test.conf" )
config.addGroup("", "runConfig") config.addList("runConfig", "subConfigs") iRun = 0 for temperature in temperatures: runName = "temperature%04d" % iRun subConfigFileName = join(runName, "step0.cfg") subConfigEndFileName = join(runName, "step1.cfg") subConfigFilePath = join(defaultConfigDir, subConfigFileName) subConfigEndFilePath = join(defaultConfigDir, subConfigEndFileName) makedirsSilent(split(subConfigFilePath)[0]) subConfigStart = Config() subConfigStart.readFile(defaultConfigFilePath) oldSaveFile = subConfigStart.value("simulation.saveFileName")[0] newSaveFile = oldSaveFile.replace("$DATEDIR", "$DATEDIR/" + runName) subConfigStart.setValue("simulation.saveFileName", newSaveFile) subConfigStart.setValue("initialization.[1].initialTemperature", temperature) subConfigStart.setValue("modifiers.[0].targetTemperature", temperature) subConfigStart.writeFile(subConfigFilePath) subConfigEnd = Config() subConfigEnd.readFile(defaultEndConfigFilePath) oldSaveFile = subConfigEnd.value("simulation.saveFileName")[0] newSaveFile = oldSaveFile.replace("$DATEDIR", "$DATEDIR/" + runName) subConfigEnd.setValue("simulation.saveFileName", newSaveFile) oldLoadFile = subConfigEnd.value("initialization.[0].fileName")[0] newLoadFile = oldLoadFile.replace("$DATEDIR", "$DATEDIR/" + runName) subConfigEnd.setValue("initialization.[0].fileName", newLoadFile) subConfigEnd.writeFile(subConfigEndFilePath)
from sys import argv from os.path import split, join from fys4460 import makedirsSilent defaultConfigFilePath = "1k-temperature/default.cfg" defaultConfigDir, defaultConfigFileName = split(defaultConfigFilePath) systemSizes = [6, 7, 8, 9, 10, 11, 12] config = Config() config.addGroup("", "runConfig") config.addList("runConfig", "subConfigs") iRun = 0 for systemSize in systemSizes: runName = "systemsize%04d" % systemSize subConfigFileName = join(runName, runName + ".cfg") subConfigFilePath = join(defaultConfigDir, subConfigFileName) print split(subConfigFilePath)[0] makedirsSilent(split(subConfigFilePath)[0]) subConfig = Config() subConfig.readFile(defaultConfigFilePath) subConfig.setValue("initialization.[0].nCells", systemSize) saveFileName = subConfig.value("simulation.saveFileName")[0] saveFileName = saveFileName.replace("$DATEDIR", "$DATEDIR/" + runName) subConfig.setValue("simulation.saveFileName", saveFileName) subConfig.writeFile(subConfigFilePath) config.appendToList("runConfig.subConfigs", subConfigFileName) iRun += 1 config.writeFile(join(defaultConfigDir, "systemsizes.cfg"))
def test_greeting ( self ): config = Config () config.addString ( "", "test" ) config.setValue ( "test", "value" ) config.addBoolean ( "", "test_bool") config.setValue ( "test_bool", True ) config.addInteger ( "", "test_int") config.setValue ( "test_int", 9 ) config.addInteger ( "", "test_unsigned_int") config.setValue ( "test_unsigned_int", -9 ) config.addFloat ( "", "test_float") config.setValue ( "test_float", 82.1002 ) self.assert_ ( config.value ( "test" )[0] == "value" ) self.assert_ ( config.value ( "test" )[1] == True ) self.assert_ ( config.value ( "test_bool" )[0] == True ) self.assert_ ( config.value ( "loose" )[1] == False ) self.assert_ ( config.value ( "test_int" )[0] == 9 ) self.assert_ ( config.value ( "test_unsigned_int" )[0] == -9 ) self.assert_ ( fabs( config.value ( "test_float" )[0] - 82.1002) < 0.00001 ) config.setValue( "test_bool", False ) config.writeFile ( "test.conf" ) self.assert_ ( os.path.exists ( "./test.conf" ) == True ) config.readFile ( "test.conf" ) self.assert_ ( config.value ( "test" )[0] == "value" ) self.assert_ ( config.value ( "test" )[1] == True ) os.remove ( "./test.conf" )
def test_greeting(self): config = Config() config.addString("", "test") config.setValue("test", "value") config.addBoolean("", "test_bool") config.setValue("test_bool", True) config.addInteger("", "test_int") config.setValue("test_int", 9) config.addInteger("", "test_unsigned_int") config.setValue("test_unsigned_int", -9) config.addFloat("", "test_float") config.setValue("test_float", 82.1002) self.assert_(config.value("test")[0] == "value") self.assert_(config.value("test")[1] == True) self.assert_(config.value("test_bool")[0] == True) self.assert_(config.value("loose")[1] == False) self.assert_(config.value("test_int")[0] == 9) self.assert_(config.value("test_unsigned_int")[0] == -9) self.assert_(fabs(config.value("test_float")[0] - 82.1002) < 0.00001) config.setValue("test_bool", False) config.writeFile("test.conf") self.assert_(os.path.exists("./test.conf") == True) config.readFile("test.conf") self.assert_(config.value("test")[0] == "value") self.assert_(config.value("test")[1] == True) os.remove("./test.conf")