コード例 #1
0
 def checkFloatValBounds(self,
                         dictKey,
                         valueString,
                         lowerBound=None,
                         upperBound=None):
     val = self.configParser.getfloat(dictKey, valueString)
     if lowerBound != None:
         if val < lowerBound:
             val = self.getFloatDefault(dictKey, valueString)
             Log.err("value of " + valueString + " must be >= " +
                     str(lowerBound) + ", using default instead = " +
                     str(val))
     if upperBound != None:
         if val > upperBound:
             val = self.getFloatDefault(dictKey, valueString)
             Log.err("value of " + valueString + " must be <= " +
                     str(upperBound) + ", using default instead = " +
                     str(val))
     return val
コード例 #2
0
    def SetConfiguration(self):
        """Reads the values from the config.ini file into a dictionary and returns it.
        
        Returns dict() <str, dyanmic>
        """

        try:
            self.configParser.read(os.getcwd() + "\\config.ini")
            sections = self.configParser.sections()

            if len(sections) == 0:
                self.__reconstruct()
                return self.SetConfiguration()

            for section in xrange(len(sections)):
                configSettings = dict()
                str = sections[section]
                if str == "World":
                    configSettings[
                        "bIsToroidal"] = self.configParser.getboolean(
                            str, "bIsToroidal")
                    configSettings["iGridWidth"] = self.checkIntValBounds(
                        str, "iGridWidth", 1)
                    configSettings["iGridHeight"] = self.checkIntValBounds(
                        str, "iGridHeight", 1)
                    Worldspace.Configure(configSettings)
                elif str == "General":
                    self.configSettings[
                        "iNumberOfRuns"] = self.checkIntValBounds(
                            str, "iNumberOfRuns", 1)
                    self.configSettings["iRunTime"] = self.checkIntValBounds(
                        str, "iRunTime", 0)
                    self.configSettings[
                        "bDebugTextEnabled"] = self.configParser.getboolean(
                            str, "bDebugTextEnabled")
                elif str == "Interface":
                    pass
                elif str == "ImmuneSystem":
                    configSettings["fBaseImmCell"] = self.checkFloatValBounds(
                        str, "fBaseImmCell", 0)
                    configSettings[
                        "bIsEnabled"] = self.configParser.getboolean(
                            str, "bIsEnabled")
                    configSettings["fRecruitment"] = self.checkFloatValBounds(
                        str, "fRecruitment", 0)
                    configSettings["iRecruitDelay"] = self.checkIntValBounds(
                        str, "iRecruitDelay", 0)
                    Systems.ImmuneSystem.Configure(configSettings)
                elif str == "EpithelialSystem":
                    configSettings["fInfectInit"] = self.checkFloatValBounds(
                        str, "fInfectInit", 0)
                    configSettings[
                        "bRegenEnabled"] = self.configParser.getboolean(
                            str, "bRegenEnabled")
                    configSettings[
                        "bRandomAge"] = self.configParser.getboolean(
                            str, "bRandomAge")
                    Systems.EpithelialSystem.Configure(configSettings)
                elif str == "FocusSystem":
                    configSettings[
                        "bIsEnabled"] = self.configParser.getboolean(
                            str, "bIsEnabled")
                    configSettings[
                        "iCollisionsForMergePercentage"] = self.checkIntValBounds(
                            str, "iCollisionsForMergePercentage", 0, 100)
                    configSettings[
                        "bDebugTextEnabled"] = self.configParser.getboolean(
                            str, "bDebugTextEnabled")
                    Systems.FocusSystem.Configure(configSettings)
                elif str == "ImmuneCell":
                    configSettings["iImmuneLifespan"] = self.checkIntValBounds(
                        str, "iImmuneLifespan", 0)
                    Cells.ImmuneCell.Configure(configSettings)
                elif str == "EpithelialCell":
                    configSettings[
                        "iEpithelialLifespan"] = self.checkIntValBounds(
                            str, "iEpithelialLifespan", 0)
                    configSettings["iDivisionTime"] = self.checkIntValBounds(
                        str, "iDivisionTime", 0)
                    configSettings["iExpressDelay"] = self.checkIntValBounds(
                        str, "iExpressDelay", 0)
                    configSettings["iInfectDelay"] = self.checkIntValBounds(
                        str, "iInfectDelay", 0)
                    configSettings["iInfectLifespan"] = self.checkIntValBounds(
                        str, "iInfectLifespan", 0)
                    configSettings["fInfectRate"] = self.checkFloatValBounds(
                        str, "iInfectRate", 0)
                    Cells.EpithelialCell.Configure(configSettings)
                elif str == "SimulationVisualisation":
                    configSettings[
                        "bIsEnabled"] = self.configParser.getboolean(
                            str, "bIsEnabled")
                    configSettings[
                        "bSnapshotEnabled"] = self.configParser.getboolean(
                            str, "bSnapshotEnabled")
                    configSettings["iSnapshotHeight"] = self.checkIntValBounds(
                        str, "iSnapshotHeight", 0)
                    configSettings["iSnapshotWidth"] = self.checkIntValBounds(
                        str, "iSnapshotWidth", 0)
                    configSettings["iSquareSize"] = self.checkIntValBounds(
                        str, "iSquareSize", 1)
                    configSettings[
                        "bDebugFocusIdEnabled"] = self.configParser.getboolean(
                            str, "bDebugFocusIdEnabled")
                    configSettings[
                        "bHighlightCollisions"] = self.configParser.getboolean(
                            str, "bHighlightCollisions")
                    SimulationVisualization.SimVis.Configure(configSettings)
                elif str == "Graph":
                    configSettings[
                        "bShowGraphOnFinish"] = self.configParser.getboolean(
                            str, "bShowGraphOnFinish")
                    Graph.Graph.Configure(configSettings)

        except Exception as e:
            if self.reconstruct == False:
                Log.err("Error in config file: " + e.message)
                Log.err("Restoring to defaults...")
                self.__reconstruct()
                return self.SetConfiguration()
            else:
                raise Exception("Failed to reconstruct config.ini file")

        return self.configSettings