Пример #1
0
    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" )
Пример #2
0
    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")
Пример #3
0
def parseAndRun(executable, configFile, runDir, args=None):
    # Build run dir name
    
    print "Parsing configuration...\nConfigFile: " + configFile + "\nRunDir: " + runDir
    
    configFileDir, configFileName = split(configFile)
    if runDir == "":
        runDir = join(configFileDir, "runs", dateDir)
    makedirsSilent(runDir)  
    
    config = Config()
    config.readFile(configFile)
    
    if config.exists("runConfig.subConfigs"):
        print "This is a parallel config. Launching subconfigs..."
        for subConfigValue in config.children("runConfig.subConfigs"):
            subConfigFile = join(configFileDir, config.value(subConfigValue)[0])
            subConfigFileDir, subConfigFileName = split(subConfigFile)
            subConfigRunDir = join(runDir, subConfigFileName).replace(".cfg", "")
            parseAndRun(executable, subConfigFile, subConfigRunDir, args)
        
        config.writeFile(join(runDir, configFileName))
    else:
        print "This is a singular config. Launching it alone..."
        runConfigFile = join(runDir, configFileName)
        config.writeFile(runConfigFile)
        run(executable, runConfigFile, dateDir, runDir, args)
Пример #4
0
    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
Пример #5
0
    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" )
Пример #6
0
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)
    
    stepConfig = Config()
    stepConfig.addGroup("", "runConfig")
    stepConfig.addList("runConfig", "subConfigs")
Пример #7
0
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"))
Пример #8
0
def run(executable, configFile, dateDir, runDir, args=None):
    executable = os.path.realpath(executable)
    temp,configFileName = os.path.split(configFile)    
    configName = configFileName.replace(".cfg", "")
    
    config = Config()
    config.readFile(configFile)
    
    replaceDateDir(config, dateDir)
    
    if(config.exists("runInformation")):
        if args.force:
                config.remove("", "runInformation")
        else:
            print "Config cannot contain section runInformation already. It would be overwritten."
            raise Exception
    
    ### Git info ###
#    repo = Repo(".")
#    head = repo.heads[0]
#    commitSHA = getattr(head.commit, "id")
    commitSHA = "N/A"
    
    ### Run information ###
    config.addGroup("", "runInformation")
    addRunInformation(config, "hostname", socket.gethostname())
    addRunInformation(config, "timestamp", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    addRunInformation(config, "gitCommitSHA", commitSHA)
    addRunInformation(config, "dateDir", dateDir)
    addRunInformation(config, "runDir", runDir)
    addRunInformation(config, "configFile", configFile)
    
    config.writeFile(configFile)

    selectConfig(os.path.abspath(configFile))

    # Input stuff to database
#    database = sqlite3.connect("test.db")
#    values = [executable, runDir]
#    insertID = database.execute("INSERT INTO run (executable, dir) VALUES (?, ?)", values)
#    printChildren(database, insertID.lastrowid, config, "")
#    database.commit()
#    database.close()
    
    # Create symlinks
#    createSymlink(os.getcwd() + "/" + runDir, "/tmp/latest")
#    saveFile = config.value("simulation.saveFileName")[0]
#    saveFile = expanduser(saveFile)
#    saveDir = os.path.dirname(saveFile)
#    createSymlink(saveDir, "/tmp/latestsavedir")
    
    runList = []
    nProcesses = 1
    if config.exists("mpi"):
        nProcesses = config.value("mpi.nProcesses")[0]
        runList = ["mpirun", "-n", str(nProcesses), "nice", "-n", "19", executable, configFileName]        
    else:
        runList = ["nice", "-n", "19", executable, configFileName]
    
    logFilePath = join(runDir, "run_" + configFileName.replace(".cfg", "") + ".log")
    f = open(logFilePath, "w")
    print "RunList: " + str(runList) + "\nRunDir: " + runDir + "\nLogFile: " + logFilePath
    print "Starting..."
#    try:
#    progressProcessList = ["python", "progressreporter.py", configName + " " + runDir, join(runDir, "runprogress.txt")]
#    progressProcess = subprocess.Popen(progressProcessList)
    process = subprocess.Popen(runList, cwd=runDir, stdout=f, stderr=subprocess.STDOUT)
    process.wait()
#    print "Waiting for progressreporter to finish..."
#    progressProcess.wait()
#    except Exception:
#        process.kill()
#        f.close()
        
    f.close()