A ConfigParser specialised for idle configuration file handling
| 37 | class InvalidTheme(Exception): pass |
| 38 | |
| 39 | class IdleConfParser(ConfigParser): |
| 40 | """ |
| 41 | A ConfigParser specialised for idle configuration file handling |
| 42 | """ |
| 43 | def __init__(self, cfgFile, cfgDefaults=None): |
| 44 | """ |
| 45 | cfgFile - string, fully specified configuration file name |
| 46 | """ |
| 47 | self.file = cfgFile # This is currently '' when testing. |
| 48 | ConfigParser.__init__(self, defaults=cfgDefaults, strict=False) |
| 49 | |
| 50 | def Get(self, section, option, type=None, default=None, raw=False): |
| 51 | """ |
| 52 | Get an option value for given section/option or return default. |
| 53 | If type is specified, return as type. |
| 54 | """ |
| 55 | # TODO Use default as fallback, at least if not None |
| 56 | # Should also print Warning(file, section, option). |
| 57 | # Currently may raise ValueError |
| 58 | if not self.has_option(section, option): |
| 59 | return default |
| 60 | if type == 'bool': |
| 61 | return self.getboolean(section, option) |
| 62 | elif type == 'int': |
| 63 | return self.getint(section, option) |
| 64 | else: |
| 65 | return self.get(section, option, raw=raw) |
| 66 | |
| 67 | def GetOptionList(self, section): |
| 68 | "Return a list of options for given section, else []." |
| 69 | if self.has_section(section): |
| 70 | return self.options(section) |
| 71 | else: #return a default value |
| 72 | return [] |
| 73 | |
| 74 | def Load(self): |
| 75 | "Load the configuration file from disk." |
| 76 | if self.file: |
| 77 | self.read(self.file) |
| 78 | |
| 79 | class IdleUserConfParser(IdleConfParser): |
| 80 | """ |
no outgoing calls
no test coverage detected
searching dependent graphs…