JCvConfigParser v0.200
Expansion Compatibility: All
Patch Compatibility: All
This module has a single class that extends the ConfigParser class and
allows easy retrieval of data from Civ4 Mod INI Config files.
This module was based on CvConfigParser from Civilization IV Alerts
mod by Gillmer J. Derge (on CivFanatics aka "Dr. Elmer Jiggle's")
and should be compatable with any code using that file.
This class extends the base functionality of the Python ConfigParser
class by adding support for a default value in the event that the option
is not given in the configuration file.
Inaddition three new methods have been added, one to retrieve lists, one
to retrieve tuples, and one to retrieve dictionaries. The getlist and
gettuple methods are secure, but do not handle lists or tuples that contain
other lists, tuples, or dictionaries. However, getdict is still being
tested and may not operate as expected in any/all situations.
To use this module you import it and then instance the class CvConfigParser.
The constructor takes 1 argument, a String File Name.
The constructor has 1 optional argument, a String Directory Path.
import CvConfigParser
pConfig = CvConfigParser.CvConfigParser(sFile, sDirectoryPath = None)
If sDirectoryPath is a path to a valid directory that contains sFile then the
INI file will be loaded. If sDirectoryPath is None or blank then default
locations will be checked for sFile and if found it will be loaded.
The supported methods are:
Config File Methods:
isLoaded()
"Return True or False"
This tells you if the INI File of a Config Object was loaded successfully or not.
Changed Methods:
These Methods work just as there ConfigParser conterparts except they take an
optional default argument and return the default if sSection or sOption are
not found.
get(sSection, sOption, sDefault = None)
"Return String Option or sDefault"
This retrieves an INI Value and returns it. All INI Values are Strings.
getint(sSection, sOption, iDefault = None)
"Return Intager Option or iDefault"
This retrieves an INI Value and returns it as an intager number.
getfloat(sSection, sOption, fDefault = None)
"Return Float Option or fDefault"
This retrieves an INI Value and returns it as a floating point number.
getboolean(sSection, sOption, bDefault = None)
"Return Boolean Option or bDefault"
This retrieves an INI Value and returns it as a boolean.
New Methods:
These Methods work similar to the other get Methods in this class, but before
returning the Value an attempt is made to parse the Value and turn it into a
List, Tuple, or Dictionary. In all cases, the first evaluation splits the Value
by ",". Due to this no INI Value can contain internal Lists, Tuples, or Dictionaries.
For example:
Valid:
nums = 1, 2, 3
nums = [1,2, 3]
nums = (1 ,2, 3)
Invalid:
nums = 1, 2, [3, 4, 5], 6
nums = 1, (2, 3)
nums = 1, {2:3, 4:5}
Once Value is split into a list by the commas, each item in the list is then
evaluated in the order as follows (note case is not considered):
If the item is None, "none", or "" then None is returned.
If the item is "true", "yes", or "on" then True will be returned.
If the item is "false", "no", or "off" then False will be returned.
If int(item) doesn't raise an exception then it is returned.
If float(item) doesn't raise an exception then it is returned.
If item matches the pattern: <some text>(<0 or more characters>)
then it is returned as a string.
Finnaly if nothing else it is returned unchanged.
getlist(sSection, sOption, lDefault = None)
"Return List Option or lDefault"
This retrieves an INI Value and returns it as a list.
gettuple(sSection, sOption, tDefault = None)
"Return Tuple Option or tDefault"
This retrieves an INI Value and returns it as a tuple.
getdict(sSection, sOption, dDefault = None)
"Return Dictionary Option or dDefault"
This retrieves an INI Value and returns it as a dictionary.
Dictionary Keys are not evaluated and will always be return as strings.
Dictionary Values are evaluated just like the items of getlist and gettuple.
Expansion Compatibility: All
Patch Compatibility: All
This module has a single class that extends the ConfigParser class and
allows easy retrieval of data from Civ4 Mod INI Config files.
This module was based on CvConfigParser from Civilization IV Alerts
mod by Gillmer J. Derge (on CivFanatics aka "Dr. Elmer Jiggle's")
and should be compatable with any code using that file.
This class extends the base functionality of the Python ConfigParser
class by adding support for a default value in the event that the option
is not given in the configuration file.
Inaddition three new methods have been added, one to retrieve lists, one
to retrieve tuples, and one to retrieve dictionaries. The getlist and
gettuple methods are secure, but do not handle lists or tuples that contain
other lists, tuples, or dictionaries. However, getdict is still being
tested and may not operate as expected in any/all situations.
To use this module you import it and then instance the class CvConfigParser.
The constructor takes 1 argument, a String File Name.
The constructor has 1 optional argument, a String Directory Path.
import CvConfigParser
pConfig = CvConfigParser.CvConfigParser(sFile, sDirectoryPath = None)
If sDirectoryPath is a path to a valid directory that contains sFile then the
INI file will be loaded. If sDirectoryPath is None or blank then default
locations will be checked for sFile and if found it will be loaded.
The supported methods are:
Config File Methods:
isLoaded()
"Return True or False"
This tells you if the INI File of a Config Object was loaded successfully or not.
Changed Methods:
These Methods work just as there ConfigParser conterparts except they take an
optional default argument and return the default if sSection or sOption are
not found.
get(sSection, sOption, sDefault = None)
"Return String Option or sDefault"
This retrieves an INI Value and returns it. All INI Values are Strings.
getint(sSection, sOption, iDefault = None)
"Return Intager Option or iDefault"
This retrieves an INI Value and returns it as an intager number.
getfloat(sSection, sOption, fDefault = None)
"Return Float Option or fDefault"
This retrieves an INI Value and returns it as a floating point number.
getboolean(sSection, sOption, bDefault = None)
"Return Boolean Option or bDefault"
This retrieves an INI Value and returns it as a boolean.
New Methods:
These Methods work similar to the other get Methods in this class, but before
returning the Value an attempt is made to parse the Value and turn it into a
List, Tuple, or Dictionary. In all cases, the first evaluation splits the Value
by ",". Due to this no INI Value can contain internal Lists, Tuples, or Dictionaries.
For example:
Valid:
nums = 1, 2, 3
nums = [1,2, 3]
nums = (1 ,2, 3)
Invalid:
nums = 1, 2, [3, 4, 5], 6
nums = 1, (2, 3)
nums = 1, {2:3, 4:5}
Once Value is split into a list by the commas, each item in the list is then
evaluated in the order as follows (note case is not considered):
If the item is None, "none", or "" then None is returned.
If the item is "true", "yes", or "on" then True will be returned.
If the item is "false", "no", or "off" then False will be returned.
If int(item) doesn't raise an exception then it is returned.
If float(item) doesn't raise an exception then it is returned.
If item matches the pattern: <some text>(<0 or more characters>)
then it is returned as a string.
Finnaly if nothing else it is returned unchanged.
getlist(sSection, sOption, lDefault = None)
"Return List Option or lDefault"
This retrieves an INI Value and returns it as a list.
gettuple(sSection, sOption, tDefault = None)
"Return Tuple Option or tDefault"
This retrieves an INI Value and returns it as a tuple.
getdict(sSection, sOption, dDefault = None)
"Return Dictionary Option or dDefault"
This retrieves an INI Value and returns it as a dictionary.
Dictionary Keys are not evaluated and will always be return as strings.
Dictionary Values are evaluated just like the items of getlist and gettuple.