Code Duplication    Length = 27-27 lines in 2 locations

client/osci/config.py 1 location

@@ 58-84 (lines=27) @@
55
        self._config.write(fh)
56
        fh.close()
57
58
class Section:
59
    """Represent section of ConfigParser class.
60
61
    Attributes of this class represents options
62
    of given section. when asking for option
63
    value None value is returned if given option
64
    does not exist, otherwise option value is
65
    returned.
66
    """
67
    def __init__(self, config, name):
68
        self.__dict__["_config"] = config
69
        self.__dict__["section"] = name
70
71
    def __getattr__(self, name):
72
        if self._config.has_option(self.section, name):
73
            return self._config.get(self.section, name)
74
        else:
75
            return None
76
77
    def __setattr__(self, name, value):
78
        if value is None:
79
            self._config.remove_option(self.section, name)
80
            if not self._config.options(self.section):
81
                # no option -- delete me
82
                self._config.remove_section(self.section)
83
        else:
84
            self._config.set(self.section, name, str(value))
85

server/lib/ige/Config.py 1 location

@@ 64-90 (lines=27) @@
61
        with open(_file, 'w') as fh:
62
            self._config.write(fh)
63
64
class Section:
65
    """Represent section of ConfigParser class.
66
67
    Attributes of this class represents options
68
    of given section. when asking for option
69
    value None value is returned if given option
70
    does not exist, otherwise option value is
71
    returned.
72
    """
73
    def __init__(self, config, name):
74
        self.__dict__["_config"] = config
75
        self.__dict__["section"] = name
76
77
    def __getattr__(self, name):
78
        if self._config.has_option(self.section, name):
79
            return self._config.get(self.section, name)
80
        else:
81
            return None
82
83
    def __setattr__(self, name, value):
84
        if value is None:
85
            self._config.remove_option(self.section, name)
86
            if not self._config.options(self.section):
87
                # no option -- delete me
88
                self._config.remove_section(self.section)
89
        else:
90
            self._config.set(self.section, name, str(value))
91