comparison mercurial/ui.py @ 8134:e74e0c259bd3

ui: always have an overlay
author Matt Mackall <mpm@selenic.com>
date Thu, 23 Apr 2009 15:40:10 -0500
parents 57a2a0070d6b
children 16771d7c64e2
comparison
equal deleted inserted replaced
8133:57a2a0070d6b 8134:e74e0c259bd3
25 25
26 class ui(object): 26 class ui(object):
27 def __init__(self, verbose=False, debug=False, quiet=False, 27 def __init__(self, verbose=False, debug=False, quiet=False,
28 interactive=True, traceback=False, report_untrusted=True, 28 interactive=True, traceback=False, report_untrusted=True,
29 parentui=None): 29 parentui=None):
30 self.overlay = None
31 self.buffers = [] 30 self.buffers = []
32 if parentui is None: 31 if parentui is None:
33 # this is the parent of all ui children 32 # this is the parent of all ui children
34 self.parentui = None 33 self.parentui = None
35 self.quiet = quiet 34 self.quiet = quiet
38 self.interactive = interactive 37 self.interactive = interactive
39 self.traceback = traceback 38 self.traceback = traceback
40 self.report_untrusted = report_untrusted 39 self.report_untrusted = report_untrusted
41 self.trusted_users = {} 40 self.trusted_users = {}
42 self.trusted_groups = {} 41 self.trusted_groups = {}
42 self.overlay = util.configparser()
43 # if ucdata is not None, its keys must be a superset of cdata's 43 # if ucdata is not None, its keys must be a superset of cdata's
44 self.cdata = util.configparser() 44 self.cdata = util.configparser()
45 self.ucdata = None 45 self.ucdata = None
46 # we always trust global config files 46 # we always trust global config files
47 self.readconfig(util.rcpath(), assumetrusted=True) 47 self.readconfig(util.rcpath(), assumetrusted=True)
50 # parentui may point to an ui object which is already a child 50 # parentui may point to an ui object which is already a child
51 self.parentui = parentui.parentui or parentui 51 self.parentui = parentui.parentui or parentui
52 self.trusted_users = parentui.trusted_users.copy() 52 self.trusted_users = parentui.trusted_users.copy()
53 self.trusted_groups = parentui.trusted_groups.copy() 53 self.trusted_groups = parentui.trusted_groups.copy()
54 self.cdata = dupconfig(self.parentui.cdata) 54 self.cdata = dupconfig(self.parentui.cdata)
55 self.overlay = dupconfig(self.parentui.overlay)
55 if self.parentui.ucdata: 56 if self.parentui.ucdata:
56 self.ucdata = dupconfig(self.parentui.ucdata) 57 self.ucdata = dupconfig(self.parentui.ucdata)
57 if self.parentui.overlay: 58 if self.parentui is not parentui:
58 self.overlay = dupconfig(self.parentui.overlay) 59 self.overlay = util.configparser()
59 if self.parentui is not parentui and parentui.overlay is not None:
60 if self.overlay is None:
61 self.overlay = util.configparser()
62 updateconfig(parentui.overlay, self.overlay) 60 updateconfig(parentui.overlay, self.overlay)
63 self.buffers = parentui.buffers 61 self.buffers = parentui.buffers
64 62
65 def __getattr__(self, key): 63 def __getattr__(self, key):
66 return getattr(self.parentui, key) 64 return getattr(self.parentui, key)
152 if cdata != self.cdata: 150 if cdata != self.cdata:
153 updateconfig(cdata, self.cdata) 151 updateconfig(cdata, self.cdata)
154 if self.ucdata is not None: 152 if self.ucdata is not None:
155 updateconfig(cdata, self.ucdata) 153 updateconfig(cdata, self.ucdata)
156 # override data from config files with data set with ui.setconfig 154 # override data from config files with data set with ui.setconfig
157 if self.overlay: 155 updateconfig(self.overlay, self.cdata)
158 updateconfig(self.overlay, self.cdata)
159 if root is None: 156 if root is None:
160 root = os.path.expanduser('~') 157 root = os.path.expanduser('~')
161 self.fixconfig(root=root) 158 self.fixconfig(root=root)
162 159
163 def readsections(self, filename, *sections): 160 def readsections(self, filename, *sections):
227 self.trusted_users[user] = 1 224 self.trusted_users[user] = 1
228 for group in self.configlist('trusted', 'groups'): 225 for group in self.configlist('trusted', 'groups'):
229 self.trusted_groups[group] = 1 226 self.trusted_groups[group] = 1
230 227
231 def setconfig(self, section, name, value): 228 def setconfig(self, section, name, value):
232 if not self.overlay:
233 self.overlay = util.configparser()
234 for cdata in (self.overlay, self.cdata, self.ucdata): 229 for cdata in (self.overlay, self.cdata, self.ucdata):
235 if not cdata: continue 230 if not cdata: continue
236 if not cdata.has_section(section): 231 if not cdata.has_section(section):
237 cdata.add_section(section) 232 cdata.add_section(section)
238 cdata.set(section, name, value) 233 cdata.set(section, name, value)