IdleConfigParser specialised for user configuration handling.
| 77 | self.read(self.file) |
| 78 | |
| 79 | class IdleUserConfParser(IdleConfParser): |
| 80 | """ |
| 81 | IdleConfigParser specialised for user configuration handling. |
| 82 | """ |
| 83 | |
| 84 | def SetOption(self, section, option, value): |
| 85 | """Return True if option is added or changed to value, else False. |
| 86 | |
| 87 | Add section if required. False means option already had value. |
| 88 | """ |
| 89 | if self.has_option(section, option): |
| 90 | if self.get(section, option) == value: |
| 91 | return False |
| 92 | else: |
| 93 | self.set(section, option, value) |
| 94 | return True |
| 95 | else: |
| 96 | if not self.has_section(section): |
| 97 | self.add_section(section) |
| 98 | self.set(section, option, value) |
| 99 | return True |
| 100 | |
| 101 | def RemoveOption(self, section, option): |
| 102 | """Return True if option is removed from section, else False. |
| 103 | |
| 104 | False if either section does not exist or did not have option. |
| 105 | """ |
| 106 | if self.has_section(section): |
| 107 | return self.remove_option(section, option) |
| 108 | return False |
| 109 | |
| 110 | def AddSection(self, section): |
| 111 | "If section doesn't exist, add it." |
| 112 | if not self.has_section(section): |
| 113 | self.add_section(section) |
| 114 | |
| 115 | def RemoveEmptySections(self): |
| 116 | "Remove any sections that have no options." |
| 117 | for section in self.sections(): |
| 118 | if not self.GetOptionList(section): |
| 119 | self.remove_section(section) |
| 120 | |
| 121 | def IsEmpty(self): |
| 122 | "Return True if no sections after removing empty sections." |
| 123 | self.RemoveEmptySections() |
| 124 | return not self.sections() |
| 125 | |
| 126 | def Save(self): |
| 127 | """Update user configuration file. |
| 128 | |
| 129 | If self not empty after removing empty sections, write the file |
| 130 | to disk. Otherwise, remove the file from disk if it exists. |
| 131 | """ |
| 132 | fname = self.file |
| 133 | if fname and fname[0] != '#': |
| 134 | if not self.IsEmpty(): |
| 135 | try: |
| 136 | cfgFile = open(fname, 'w') |
no outgoing calls
no test coverage detected
searching dependent graphs…