Show More
@@ -1,79 +1,82 b'' | |||
|
1 | 1 | # configitems.py - centralized declaration of configuration option |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2017 Pierre-Yves David <pierre-yves.david@octobus.net> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import functools |
|
11 | 11 | |
|
12 | 12 | from . import ( |
|
13 | 13 | error, |
|
14 | 14 | ) |
|
15 | 15 | |
|
16 | 16 | def loadconfigtable(ui, extname, configtable): |
|
17 | 17 | """update config item known to the ui with the extension ones""" |
|
18 | 18 | for section, items in configtable.items(): |
|
19 | 19 | knownitems = ui._knownconfig.setdefault(section, {}) |
|
20 | 20 | knownkeys = set(knownitems) |
|
21 | 21 | newkeys = set(items) |
|
22 | 22 | for key in sorted(knownkeys & newkeys): |
|
23 | 23 | msg = "extension '%s' overwrite config item '%s.%s'" |
|
24 | 24 | msg %= (extname, section, key) |
|
25 | 25 | ui.develwarn(msg, config='warn-config') |
|
26 | 26 | |
|
27 | 27 | knownitems.update(items) |
|
28 | 28 | |
|
29 | 29 | class configitem(object): |
|
30 | 30 | """represent a known config item |
|
31 | 31 | |
|
32 | 32 | :section: the official config section where to find this item, |
|
33 | 33 | :name: the official name within the section, |
|
34 | 34 | :default: default value for this item, |
|
35 | 35 | """ |
|
36 | 36 | |
|
37 | 37 | def __init__(self, section, name, default=None): |
|
38 | 38 | self.section = section |
|
39 | 39 | self.name = name |
|
40 | 40 | self.default = default |
|
41 | 41 | |
|
42 | 42 | coreitems = {} |
|
43 | 43 | |
|
44 | 44 | def _register(configtable, *args, **kwargs): |
|
45 | 45 | item = configitem(*args, **kwargs) |
|
46 | 46 | section = configtable.setdefault(item.section, {}) |
|
47 | 47 | if item.name in section: |
|
48 | 48 | msg = "duplicated config item registration for '%s.%s'" |
|
49 | 49 | raise error.ProgrammingError(msg % (item.section, item.name)) |
|
50 | 50 | section[item.name] = item |
|
51 | 51 | |
|
52 | 52 | # Registering actual config items |
|
53 | 53 | |
|
54 | 54 | def getitemregister(configtable): |
|
55 | 55 | return functools.partial(_register, configtable) |
|
56 | 56 | |
|
57 | 57 | coreconfigitem = getitemregister(coreitems) |
|
58 | 58 | |
|
59 | 59 | coreconfigitem('devel', 'all-warnings', |
|
60 | 60 | default=False, |
|
61 | 61 | ) |
|
62 | 62 | coreconfigitem('devel', 'bundle2.debug', |
|
63 | 63 | default=False, |
|
64 | 64 | ) |
|
65 | 65 | coreconfigitem('devel', 'check-locks', |
|
66 | 66 | default=False, |
|
67 | 67 | ) |
|
68 | coreconfigitem('devel', 'check-relroot', | |
|
69 | default=False, | |
|
70 | ) | |
|
68 | 71 | coreconfigitem('patch', 'fuzz', |
|
69 | 72 | default=2, |
|
70 | 73 | ) |
|
71 | 74 | coreconfigitem('ui', 'clonebundleprefers', |
|
72 | 75 | default=list, |
|
73 | 76 | ) |
|
74 | 77 | coreconfigitem('ui', 'interactive', |
|
75 | 78 | default=None, |
|
76 | 79 | ) |
|
77 | 80 | coreconfigitem('ui', 'quiet', |
|
78 | 81 | default=False, |
|
79 | 82 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now