##// END OF EJS Templates
ui.py: change the overlay from a dict to a SafeConfigParser....
Alexis S. L. Carvalho -
r3344:d9b3d3d3 default
parent child Browse files
Show More
@@ -2463,7 +2463,7 b' def serve(ui, repo, **opts):'
2463 " accesslog errorlog webdir_conf")
2463 " accesslog errorlog webdir_conf")
2464 for o in optlist.split():
2464 for o in optlist.split():
2465 if opts[o]:
2465 if opts[o]:
2466 ui.setconfig("web", o, opts[o])
2466 ui.setconfig("web", o, str(opts[o]))
2467
2467
2468 if repo is None and not ui.config("web", "webdir_conf"):
2468 if repo is None and not ui.config("web", "webdir_conf"):
2469 raise hg.RepoError(_("There is no Mercurial repository here"
2469 raise hg.RepoError(_("There is no Mercurial repository here"
@@ -10,10 +10,22 b' from demandload import *'
10 demandload(globals(), "errno getpass os re socket sys tempfile")
10 demandload(globals(), "errno getpass os re socket sys tempfile")
11 demandload(globals(), "ConfigParser mdiff templater traceback util")
11 demandload(globals(), "ConfigParser mdiff templater traceback util")
12
12
13 def dupconfig(orig):
14 new = ConfigParser.SafeConfigParser(orig.defaults())
15 updateconfig(orig, new)
16 return new
17
18 def updateconfig(source, dest):
19 for section in source.sections():
20 if not dest.has_section(section):
21 dest.add_section(section)
22 for name, value in source.items(section, raw=True):
23 dest.set(section, name, value)
24
13 class ui(object):
25 class ui(object):
14 def __init__(self, verbose=False, debug=False, quiet=False,
26 def __init__(self, verbose=False, debug=False, quiet=False,
15 interactive=True, traceback=False, parentui=None):
27 interactive=True, traceback=False, parentui=None):
16 self.overlay = {}
28 self.overlay = None
17 self.header = []
29 self.header = []
18 self.prev_header = []
30 self.prev_header = []
19 if parentui is None:
31 if parentui is None:
@@ -34,13 +46,9 b' class ui(object):'
34 # parentui may point to an ui object which is already a child
46 # parentui may point to an ui object which is already a child
35 self.parentui = parentui.parentui or parentui
47 self.parentui = parentui.parentui or parentui
36 self.readhooks = self.parentui.readhooks[:]
48 self.readhooks = self.parentui.readhooks[:]
37 parent_cdata = self.parentui.cdata
49 self.cdata = dupconfig(self.parentui.cdata)
38 self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults())
50 if self.parentui.overlay:
39 # make interpolation work
51 self.overlay = dupconfig(self.parentui.overlay)
40 for section in parent_cdata.sections():
41 self.cdata.add_section(section)
42 for name, value in parent_cdata.items(section, raw=True):
43 self.cdata.set(section, name, value)
44
52
45 def __getattr__(self, key):
53 def __getattr__(self, key):
46 return getattr(self.parentui, key)
54 return getattr(self.parentui, key)
@@ -78,18 +86,24 b' class ui(object):'
78 for name, path in self.configitems("paths"):
86 for name, path in self.configitems("paths"):
79 if path and "://" not in path and not os.path.isabs(path):
87 if path and "://" not in path and not os.path.isabs(path):
80 self.cdata.set("paths", name, os.path.join(root, path))
88 self.cdata.set("paths", name, os.path.join(root, path))
89 # override data from config files with data set with ui.setconfig
90 if self.overlay:
91 updateconfig(self.overlay, self.cdata)
81 for hook in self.readhooks:
92 for hook in self.readhooks:
82 hook(self)
93 hook(self)
83
94
84 def addreadhook(self, hook):
95 def addreadhook(self, hook):
85 self.readhooks.append(hook)
96 self.readhooks.append(hook)
86
97
87 def setconfig(self, section, name, val):
98 def setconfig(self, section, name, value):
88 self.overlay[(section, name)] = val
99 if not self.overlay:
100 self.overlay = ConfigParser.SafeConfigParser()
101 for cdata in (self.overlay, self.cdata):
102 if not cdata.has_section(section):
103 cdata.add_section(section)
104 cdata.set(section, name, value)
89
105
90 def _config(self, section, name, default, funcname):
106 def _config(self, section, name, default, funcname):
91 if self.overlay.has_key((section, name)):
92 return self.overlay[(section, name)]
93 if self.cdata.has_option(section, name):
107 if self.cdata.has_option(section, name):
94 try:
108 try:
95 func = getattr(self.cdata, funcname)
109 func = getattr(self.cdata, funcname)
@@ -132,17 +146,11 b' class ui(object):'
132 return x
146 return x
133
147
134 def walkconfig(self):
148 def walkconfig(self):
135 seen = {}
136 for (section, name), value in self.overlay.iteritems():
137 yield section, name, value
138 seen[section, name] = 1
139 sections = self.cdata.sections()
149 sections = self.cdata.sections()
140 sections.sort()
150 sections.sort()
141 for section in sections:
151 for section in sections:
142 for name, value in self.configitems(section):
152 for name, value in self.configitems(section):
143 if (section, name) in seen: continue
144 yield section, name, value.replace('\n', '\\n')
153 yield section, name, value.replace('\n', '\\n')
145 seen[section, name] = 1
146
154
147 def extensions(self):
155 def extensions(self):
148 result = self.configitems("extensions")
156 result = self.configitems("extensions")
General Comments 0
You need to be logged in to leave comments. Login now