package for organizing program configurations. It can read/write configurations file, parse arguments from command lines, and also parse arguments passed from method/function calling inside python.
Note: for python 2.6, argparse and orderedDict is required, install them with easy_install
Bases: object
_optdatalist_default, _optdatalist are metadata used to initialize the options, see below for examples
options presents in –help (in cmd), config file, headers have same order as in these list, so arrange them in right order here.
optional args to control if the options presents in args, config file or file header
so in short mode, all options with ‘a’ will be written, in full mode, all options with ‘a’ or ‘f’ will be written
get a header of configurations values,
Parameters: |
|
---|---|
Returns: | string, lines with line break that can be directly writen to a text file |
init config class and add options to class
IMPORTANT: call this method after you define the metadata of your config class to add options as class attributes!!!
parse args and update the value in self.*option*, this will call the self.args() to parse args,
Parameters: | pargs – list of string, arguments to parse, usually comming from sys.argv |
---|
read a config file and update the self.*option*
Parameters: | filename – str, file name of config file (include path) |
---|
update self.*option* values according to the kwargs
Parameters: | kwargs – dict, keywords=value |
---|
reset all values to their default value
Parameters: | optnames – list of str, name of options to reset, None for all options |
---|
update config according to config file, args(from sys.argv) or **kwargs
Parameters: |
|
---|---|
Returns: | True if anything updated, False if nothing updated |
write config to file. the file is compatiable with python package ConfigParser
Parameters: |
|
---|
Bases: object
A fake configfile object used in reading config from header of data or a real config file.
close the file
readline function
get the type (a converter function) according to the opttype
the function doesn’t take list
Parameters: | opttype – string, a type of options, could be ‘str’, ‘int’, ‘float’, or ‘bool’ |
---|---|
Returns: | type (converter function) |
calculate the crc32 value of file
Parameters: | filename – path to the file |
---|---|
Returns: | crc32 value of file |
check file integrity using crc32 and md5. It will read file twice then compare the crc32 and md5. If two results doesn’t match, it will wait until the file is completed written to disk.
Parameters: | filename – path to the file |
---|
calculate the MD5 value of file
Parameters: | filename – path to the file |
---|---|
Returns: | md5 value of file |
turn the value of one option to string, according to the option type list of values are truned into “value1, value2, value3...”
Parameters: |
|
---|---|
Returns: | string, usually stored in ConfigBase.config |
convert the string to value of one option, according to the option type
Parameters: |
|
---|---|
Returns: | value of the option, usually stored in ConfigBase.config |
turn string to bool
Definition of __version__, __date__, __gitsha__.