Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/ui.py @ 3339:a7cec14c9b40
ui.py: move common code out of config and configbool
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Tue, 10 Oct 2006 18:43:20 -0300 |
parents | 929d04962115 |
children | 4eeb79b4da30 |
comparison
equal
deleted
inserted
replaced
3338:929d04962115 | 3339:a7cec14c9b40 |
---|---|
85 self.readhooks.append(hook) | 85 self.readhooks.append(hook) |
86 | 86 |
87 def setconfig(self, section, name, val): | 87 def setconfig(self, section, name, val): |
88 self.overlay[(section, name)] = val | 88 self.overlay[(section, name)] = val |
89 | 89 |
90 def config(self, section, name, default=None): | 90 def _config(self, section, name, default, funcname): |
91 if self.overlay.has_key((section, name)): | 91 if self.overlay.has_key((section, name)): |
92 return self.overlay[(section, name)] | 92 return self.overlay[(section, name)] |
93 if self.cdata.has_option(section, name): | 93 if self.cdata.has_option(section, name): |
94 try: | 94 try: |
95 return self.cdata.get(section, name) | 95 func = getattr(self.cdata, funcname) |
96 return func(section, name) | |
96 except ConfigParser.InterpolationError, inst: | 97 except ConfigParser.InterpolationError, inst: |
97 raise util.Abort(_("Error in configuration section [%s] " | 98 raise util.Abort(_("Error in configuration section [%s] " |
98 "parameter '%s':\n%s") | 99 "parameter '%s':\n%s") |
99 % (section, name, inst)) | 100 % (section, name, inst)) |
100 if self.parentui is None: | 101 if self.parentui is None: |
101 return default | 102 return default |
102 else: | 103 else: |
103 return self.parentui.config(section, name, default) | 104 return self.parentui._config(section, name, default, funcname) |
105 | |
106 def config(self, section, name, default=None): | |
107 return self._config(section, name, default, 'get') | |
108 | |
109 def configbool(self, section, name, default=False): | |
110 return self._config(section, name, default, 'getboolean') | |
104 | 111 |
105 def configlist(self, section, name, default=None): | 112 def configlist(self, section, name, default=None): |
106 """Return a list of comma/space separated strings""" | 113 """Return a list of comma/space separated strings""" |
107 result = self.config(section, name) | 114 result = self.config(section, name) |
108 if result is None: | 115 if result is None: |
109 result = default or [] | 116 result = default or [] |
110 if isinstance(result, basestring): | 117 if isinstance(result, basestring): |
111 result = result.replace(",", " ").split() | 118 result = result.replace(",", " ").split() |
112 return result | 119 return result |
113 | |
114 def configbool(self, section, name, default=False): | |
115 if self.overlay.has_key((section, name)): | |
116 return self.overlay[(section, name)] | |
117 if self.cdata.has_option(section, name): | |
118 try: | |
119 return self.cdata.getboolean(section, name) | |
120 except ConfigParser.InterpolationError, inst: | |
121 raise util.Abort(_("Error in configuration section [%s] " | |
122 "parameter '%s':\n%s") | |
123 % (section, name, inst)) | |
124 if self.parentui is None: | |
125 return default | |
126 else: | |
127 return self.parentui.configbool(section, name, default) | |
128 | 120 |
129 def has_config(self, section): | 121 def has_config(self, section): |
130 '''tell whether section exists in config.''' | 122 '''tell whether section exists in config.''' |
131 return self.cdata.has_section(section) | 123 return self.cdata.has_section(section) |
132 | 124 |