configitems.py
47 lines
| 1.2 KiB
| text/x-python
|
PythonLexer
/ mercurial / configitems.py
r32983 | # configitems.py - centralized declaration of configuration option | |||
# | ||||
# Copyright 2017 Pierre-Yves David <pierre-yves.david@octobus.net> | ||||
# | ||||
# This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | ||||
from __future__ import absolute_import | ||||
r32984 | from . import ( | |||
error, | ||||
) | ||||
r32983 | class configitem(object): | |||
"""represent a known config item | ||||
:section: the official config section where to find this item, | ||||
:name: the official name within the section, | ||||
:default: default value for this item, | ||||
""" | ||||
def __init__(self, section, name, default=None): | ||||
self.section = section | ||||
self.name = name | ||||
self.default = default | ||||
r32984 | ||||
coreitems = {} | ||||
def coreconfigitem(*args, **kwargs): | ||||
item = configitem(*args, **kwargs) | ||||
section = coreitems.setdefault(item.section, {}) | ||||
if item.name in section: | ||||
msg = "duplicated config item registration for '%s.%s'" | ||||
raise error.ProgrammingError(msg % (item.section, item.name)) | ||||
section[item.name] = item | ||||
r32986 | ||||
# Registering actual config items | ||||
r32988 | coreconfigitem('patch', 'fuzz', | |||
default=2, | ||||
) | ||||
r32989 | coreconfigitem('ui', 'clonebundleprefers', | |||
default=[], | ||||
) | ||||
r32986 | coreconfigitem('ui', 'quiet', | |||
default=False, | ||||
) | ||||