示例#1
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
示例#2
0
    def GET(self, *args, **kwargs):

        #Infinite geo-location checks by default
        result = {
            'SDCERR': weblcm_def.WEBLCM_ERRORS.get('SDCERR_SUCCESS'),
            'InfoMsg': 'AWM configuration only supported in LITE mode',
            'geolocation_scanning_enable': 1,
        }

        # check if there is a configuration file which contains a "scan_attempts:0" entry
        # if configuration file does not exist, scan_attempts is not disabled
        f = cherrypy.request.app.config['weblcm'].get('awm_cfg', None)
        if not f:
            return result
        if not os.path.isfile(f):
            return result

        config = Config()
        with AWMCfgManage._lock:
            config.readFile(f)
            if config.exists("scan_attempts"):
                result['geolocation_scanning_enable'] = config.value(
                    "scan_attempts")[0]
                result['ErrorMesg'] = ''

        return result
示例#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 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()