Mercurial > hg
comparison mercurial/configitems.py @ 32984:6d983e8af49c
configitems: introduce a central registry for config option
We now have the appropriate infrastructure to register config items. Usage will
added in the next changeset.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 17 Jun 2017 18:43:27 +0200 |
parents | 0d757af1ea67 |
children | 2529e2ae9f4c |
comparison
equal
deleted
inserted
replaced
32983:0d757af1ea67 | 32984:6d983e8af49c |
---|---|
4 # | 4 # |
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | |
10 from . import ( | |
11 error, | |
12 ) | |
9 | 13 |
10 class configitem(object): | 14 class configitem(object): |
11 """represent a known config item | 15 """represent a known config item |
12 | 16 |
13 :section: the official config section where to find this item, | 17 :section: the official config section where to find this item, |
17 | 21 |
18 def __init__(self, section, name, default=None): | 22 def __init__(self, section, name, default=None): |
19 self.section = section | 23 self.section = section |
20 self.name = name | 24 self.name = name |
21 self.default = default | 25 self.default = default |
26 | |
27 coreitems = {} | |
28 | |
29 def coreconfigitem(*args, **kwargs): | |
30 item = configitem(*args, **kwargs) | |
31 section = coreitems.setdefault(item.section, {}) | |
32 if item.name in section: | |
33 msg = "duplicated config item registration for '%s.%s'" | |
34 raise error.ProgrammingError(msg % (item.section, item.name)) | |
35 section[item.name] = item |