comparison mercurial/ui.py @ 8197:d94f17c27505

ui: simplify fixconfig
author Matt Mackall <mpm@selenic.com>
date Sun, 26 Apr 2009 16:50:43 -0500
parents b7c85a809a54
children cf9accffd0b3
comparison
equal deleted inserted replaced
8196:b7c85a809a54 8197:d94f17c27505
96 96
97 if root is None: 97 if root is None:
98 root = os.path.expanduser('~') 98 root = os.path.expanduser('~')
99 self.fixconfig(root=root) 99 self.fixconfig(root=root)
100 100
101 def fixconfig(self, section=None, name=None, value=None, root=None): 101 def fixconfig(self, root=None):
102 # translate paths relative to root (or home) into absolute paths 102 # translate paths relative to root (or home) into absolute paths
103 if section is None or section == 'paths': 103 root = root or os.getcwd()
104 if root is None: 104 for c in self.cdata, self.ucdata, self.overlay:
105 root = os.getcwd() 105 for n, p in c.items('paths'):
106 items = section and [(name, value)] or [] 106 if p and "://" not in p and not os.path.isabs(p):
107 for cdata in self.cdata, self.ucdata, self.overlay: 107 c.set("paths", n, os.path.normpath(os.path.join(root, p)))
108 if not items and 'paths' in cdata:
109 pathsitems = cdata.items('paths')
110 else:
111 pathsitems = items
112 for n, path in pathsitems:
113 if path and "://" not in path and not os.path.isabs(path):
114 cdata.set("paths", n,
115 os.path.normpath(os.path.join(root, path)))
116 108
117 # update ui options 109 # update ui options
118 if section is None or section == 'ui': 110 self.debugflag = self.configbool('ui', 'debug')
119 self.debugflag = self.configbool('ui', 'debug') 111 self.verbose = self.debugflag or self.configbool('ui', 'verbose')
120 self.verbose = self.debugflag or self.configbool('ui', 'verbose') 112 self.quiet = not self.debugflag and self.configbool('ui', 'quiet')
121 self.quiet = not self.debugflag and self.configbool('ui', 'quiet') 113 if self.verbose and self.quiet:
122 if self.verbose and self.quiet: 114 self.quiet = self.verbose = False
123 self.quiet = self.verbose = False 115 self.report_untrusted = self.configbool("ui", "report_untrusted", True)
124 116 self.interactive = self.configbool("ui", "interactive", self.isatty())
125 self.report_untrusted = self.configbool("ui", "report_untrusted", 117 self.traceback = self.configbool('ui', 'traceback', False)
126 True)
127 self.interactive = self.configbool("ui", "interactive",
128 self.isatty())
129 self.traceback = self.configbool('ui', 'traceback', False)
130 118
131 # update trust information 119 # update trust information
132 if section is None or section == 'trusted': 120 for user in self.configlist('trusted', 'users'):
133 for user in self.configlist('trusted', 'users'): 121 self.trusted_users[user] = 1
134 self.trusted_users[user] = 1 122 for group in self.configlist('trusted', 'groups'):
135 for group in self.configlist('trusted', 'groups'): 123 self.trusted_groups[group] = 1
136 self.trusted_groups[group] = 1
137 124
138 def setconfig(self, section, name, value): 125 def setconfig(self, section, name, value):
139 for cdata in (self.overlay, self.cdata, self.ucdata): 126 for cdata in (self.overlay, self.cdata, self.ucdata):
140 cdata.set(section, name, value) 127 cdata.set(section, name, value)
141 self.fixconfig(section, name, value) 128 self.fixconfig()
142 129
143 def _get_cdata(self, untrusted): 130 def _get_cdata(self, untrusted):
144 if untrusted: 131 if untrusted:
145 return self.ucdata 132 return self.ucdata
146 return self.cdata 133 return self.cdata
229 def _path(self, loc): 216 def _path(self, loc):
230 p = self.config('paths', loc) 217 p = self.config('paths', loc)
231 if p and '%%' in p: 218 if p and '%%' in p:
232 ui.warn('(deprecated \'\%\%\' in path %s=%s from %s)\n' % 219 ui.warn('(deprecated \'\%\%\' in path %s=%s from %s)\n' %
233 (loc, p, self.configsource('paths', loc))) 220 (loc, p, self.configsource('paths', loc)))
234 return p.replace('%%', '%') 221 p = p.replace('%%', '%')
235 return p 222 return p
236 223
237 def expandpath(self, loc, default=None): 224 def expandpath(self, loc, default=None):
238 """Return repository location relative to cwd or from [paths]""" 225 """Return repository location relative to cwd or from [paths]"""
239 if "://" in loc or os.path.isdir(os.path.join(loc, '.hg')): 226 if "://" in loc or os.path.isdir(os.path.join(loc, '.hg')):