Bases: object
Class for parsing python configuration files
Case1: Normal usage >>> f = open(“test.py”, “w”) >>> f.write(‘modules = {“local”:”/path/to/local”, “svn”:”path/to/svn”}; ‘) >>> f.write(‘fetchto = ”..”’ ) >>> f.close() >>> p = ConfigParser() >>> p.add_option(“modules”, type={}) >>> p.add_option(“fetchto”, type=’‘) >>> p.add_config_file(“test.py”) >>> p.parse() {‘modules’: {‘svn’: ‘path/to/svn’, ‘local’: ‘/path/to/local’}, ‘fetchto’: ‘..’}
Case2: Default value and lack of a variable >>> f = open(“test.py”, “w”) >>> f.write(‘a=”123”’) >>> f.close() >>> p = ConfigParser() >>> p.add_option(“a”, type=’‘) >>> p.add_option(“b”, type=’‘, default=’borsuk’) >>> p.add_config_file(“test.py”) >>> p.parse() {‘a’: ‘123’, ‘b’: ‘borsuk’}
Case3: Multiple types for a variable >>> f = open(“test.py”, “w”) >>> f.write(‘a=[1,2,3]’) >>> f.close() >>> p = ConfigParser() >>> p.add_option(“a”, type=1, default=12) >>> p.add_type(“a”, type=[]) >>> p.add_config_file(“test.py”) >>> p.parse() {‘a’: [1, 2, 3]}
Case4: Unrecognized options >>> f = open(“test.py”, “w”) >>> f.write(‘a = 123’) >>> f.close() >>> p = ConfigParser() >>> p.add_option(“b”, type=’‘) >>> p.add_config_file(“test.py”) >>> p.parse() Traceback (most recent call last):
File “<stdin>”, line 1, in <module> File “configparser.py”, line 107, in parse raise NameError(“Unrecognized option: ” + key)
NameError: Unrecognized option: a
Case5: Invalid parameter type >>> f = open(“test.py”,”w”) >>> f.write(‘a=”123”’) >>> f.close() >>> p = ConfigParser() >>> p.add_option(“a”, type=0) >>> p.add_config_file(“test.py”) >>> p.parse() Traceback (most recent call last):
File “<stdin>”, line 1, in <module> File “configparser.py”, line 110, in parse raise RuntimeError(“Given option: “+str(type(val))+” doesn’t match specified types:”+str(opt.types))
RuntimeError: Given option: <type ‘str’> doesn’t match specified types:[<type ‘int’>]
Case6: >>> f = open(“test.py”,”w”) >>> f.write(‘a={“zupa”:1}’) >>> f.close() >>> p = ConfigParser() >>> p.add_option(“a”, type={}) >>> p.add_allowed_key(“a”, “zupa”) >>> p.add_config_file(“test.py”) >>> p.parse() {‘a’: {‘zupa’: 1}}
Case7 >>> f = open(“test.py”,”w”) >>> f.write(‘a={“kot”:1}’) >>> f.close() >>> p = ConfigParser() >>> p.add_option(“a”, type={}) >>> p.add_allowed_key(“a”, “kniaz”) >>> p.add_config_file(“test.py”) >>> p.parse() Traceback (most recent call last):
File “<stdin>”, line 1, in <module> File “configparser.py”, line 184, in parse raise RuntimeError(“Encountered unallowed key: ” +key+ ” for options ‘”+opt_name+”’”)
RuntimeError: Encountered unallowed key: kot for options ‘a’
Cleanup: >>> import os >>> os.remove(“test.py”)
converts a relative path to an absolute path.
@param path the path to convert - if already absolute, is returned without conversion. @param base - optional. Defaults to the current directory. The base is intelligently concatenated to the given relative path. @return the relative path of path from base
Look for manifest in the given folder
Get basename from an url
Check if link to a repo seems to be correct. Filter revision number and branch
ANSII Color formatting for output in terminal.
Colorize text.
Print colorize text.
It accepts arguments of print function.