Manage a user's proposed configuration option changes. Names used across multiple methods: page -- one of the 4 top-level dicts representing a .idlerc/config-x.cfg file. config_type -- name of a page. section -- a section within a page/file. optio
| 780 | |
| 781 | |
| 782 | class ConfigChanges(dict): |
| 783 | """Manage a user's proposed configuration option changes. |
| 784 | |
| 785 | Names used across multiple methods: |
| 786 | page -- one of the 4 top-level dicts representing a |
| 787 | .idlerc/config-x.cfg file. |
| 788 | config_type -- name of a page. |
| 789 | section -- a section within a page/file. |
| 790 | option -- name of an option within a section. |
| 791 | value -- value for the option. |
| 792 | |
| 793 | Methods |
| 794 | add_option: Add option and value to changes. |
| 795 | save_option: Save option and value to config parser. |
| 796 | save_all: Save all the changes to the config parser and file. |
| 797 | delete_section: If section exists, |
| 798 | delete from changes, userCfg, and file. |
| 799 | clear: Clear all changes by clearing each page. |
| 800 | """ |
| 801 | def __init__(self): |
| 802 | "Create a page for each configuration file" |
| 803 | self.pages = [] # List of unhashable dicts. |
| 804 | for config_type in idleConf.config_types: |
| 805 | self[config_type] = {} |
| 806 | self.pages.append(self[config_type]) |
| 807 | |
| 808 | def add_option(self, config_type, section, item, value): |
| 809 | "Add item/value pair for config_type and section." |
| 810 | page = self[config_type] |
| 811 | value = str(value) # Make sure we use a string. |
| 812 | if section not in page: |
| 813 | page[section] = {} |
| 814 | page[section][item] = value |
| 815 | |
| 816 | @staticmethod |
| 817 | def save_option(config_type, section, item, value): |
| 818 | """Return True if the configuration value was added or changed. |
| 819 | |
| 820 | Helper for save_all. |
| 821 | """ |
| 822 | if idleConf.defaultCfg[config_type].has_option(section, item): |
| 823 | if idleConf.defaultCfg[config_type].Get(section, item) == value: |
| 824 | # The setting equals a default setting, remove it from user cfg. |
| 825 | return idleConf.userCfg[config_type].RemoveOption(section, item) |
| 826 | # If we got here, set the option. |
| 827 | return idleConf.userCfg[config_type].SetOption(section, item, value) |
| 828 | |
| 829 | def save_all(self): |
| 830 | """Save configuration changes to the user config file. |
| 831 | |
| 832 | Clear self in preparation for additional changes. |
| 833 | Return changed for testing. |
| 834 | """ |
| 835 | idleConf.userCfg['main'].Save() |
| 836 | |
| 837 | changed = False |
| 838 | for config_type in self: |
| 839 | cfg_type_changed = False |
no outgoing calls
no test coverage detected
searching dependent graphs…