Package schrodinger :: Package application :: Module inputconfig :: Class InputConfig
[hide private]
[frames] | no frames]

Class InputConfig

   object --+            
            |            
         dict --+        
                |        
configobj.Section --+    
                    |    
  configobj.ConfigObj --+
                        |
                       InputConfig
Known Subclasses:

Parse keyword-value input files and make the settings available in a dictionary-like fashion.

Typical usage:

   list_of_specs = ["NUM_RINGS = integer(min=1, max=100, default=1)"]
   config = InputConfig(filename, list_of_specs)
   if config['NUM_RINGS'] > 4:
       do_something()
Instance Methods [hide private]
new empty dictionary

__init__(self, infile=None, specs=None)
Parse a config file or create a config file object.
 
getSpecsString(self)
Return a string of specifications.
 
printout(self)
Print all keywords of this instance to stdout.
 
writeInputFile(self, filename, ignore_none=False, yesno=False, smartsort=False)
Write the configuration to a file in the InputConfig format.
 
validateValues(self, preserve_errors=True, copy=True)
Validate the values read in from the InputConfig file.
 
_quote(self, value, multiline=True)
Overwrite ConfigObj's quoting method to ensure that values with spaces get quoted.

Inherited from configobj.ConfigObj: __repr__, reload, reset, validate, write

Inherited from configobj.ConfigObj (private): _a_to_u, _decode, _decode_element, _get_single_quote, _get_triple_quote, _handle_bom, _handle_comment, _handle_configspec, _handle_error, _handle_value, _initialise, _load, _match_depth, _multiline, _parse, _set_configspec, _str, _unquote, _write_line, _write_marker

Inherited from configobj.Section: __delitem__, __getitem__, __iter__, __reduce__, __setitem__, __setstate__, __str__, as_bool, as_float, as_int, as_list, clear, dict, get, items, iteritems, iterkeys, itervalues, keys, merge, pop, popitem, rename, restore_default, restore_defaults, setdefault, update, values, walk

Inherited from configobj.Section (private): _interpolate

Inherited from dict: __cmp__, __contains__, __eq__, __ge__, __getattribute__, __gt__, __le__, __len__, __lt__, __ne__, __new__, __sizeof__, copy, fromkeys, has_key, viewitems, viewkeys, viewvalues

Inherited from object: __delattr__, __format__, __reduce_ex__, __setattr__, __subclasshook__

Class Variables [hide private]

Inherited from configobj.ConfigObj (private): _bools, _keyword, _listvalueexp, _multi_line_double, _multi_line_single, _nolistvalue, _sectionmarker, _single_line_double, _single_line_single, _triple_quote, _valueexp

Inherited from dict: __hash__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, infile=None, specs=None)
(Constructor)

 

Parse a config file or create a config file object.

``ConfigObj(infile=None, configspec=None, encoding=None,
            interpolation=True, raise_errors=False, list_values=True,
            create_empty=False, file_error=False, stringify=True,
            indent_type=None, default_encoding=None, unrepr=False,
            write_empty_values=False, _inspec=False)``

Parameters:
  • infile (string) - The name of the input file.
  • specs (list of strings) - A list of strings, each in the format <keywordname> = <validator>(<validatoroptions>). An example string is NUM_RINGS = integer(min=1, max=100, default=1). For available validators, see: http://www.voidspace.org.uk/python/validate.html.
Returns:
new empty dictionary

Overrides: object.__init__

getSpecsString(self)

 

Return a string of specifications. One keywords per line. Raises ValueError if this class has no specifications.

printout(self)

 

Print all keywords of this instance to stdout.

This method is meant for debugging purposes.

writeInputFile(self, filename, ignore_none=False, yesno=False, smartsort=False)

 

Write the configuration to a file in the InputConfig format.

Parameters:
  • filename (a file path or an open file handle) - The file to write the configuration to.
  • ignore_none (bool) - If True, keywords with a value of None will not be written to the input file.
  • yesno (bool) - If True, boolean keywords will be written as "yes" and "no", if False, as "True" and "False".
  • smartsort (bool) - If True, keywords that are identical except for the numbers at the end will be sorted such that "2" will go before "10".

validateValues(self, preserve_errors=True, copy=True)

 

Validate the values read in from the InputConfig file.

Provide values for keywords with validators that have default values.

If a validator for a keyword is specified without a default and the keyword is missing from the input file, a RuntimeError will be raised.

Parameters:
  • preserve_errors (bool) - If set to False, this method returns True if all tests passed, and False if there is a failure. If set to True, then instead of getting False for failed checkes, the actual detailed errors are printed for any validation errors encountered.

    Even if preserve_errors is True, missing keys or sections will still be represented by a False in the results dictionary.

  • copy (bool) - If False, default values (as specified in the 'specs' strings in the constructor) will not be copied to object's "defaults" list, which will cause them to not be written out when writeInputFile() method is called. If True, then all keywords with a default will be written out to the file via the writeInputFile() method. NOTE: Default is True, while in ConfigObj default is False.

_quote(self, value, multiline=True)

 

Overwrite ConfigObj's quoting method to ensure that values with spaces get quoted. (ConfigObj quotes only values that start and/or end with spaces).

Overrides: configobj.ConfigObj._quote