comparison mercurial/ui.py @ 2343:af81d8770620

add ui.has_config method.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Tue, 23 May 2006 14:57:45 -0700
parents f0680b2d1d64
children 62ce297f214f 74d569332f8b
comparison
equal deleted inserted replaced
2342:c6391adc356a 2343:af81d8770620
106 raise util.Abort(_("Error in configuration:\n%s") % inst) 106 raise util.Abort(_("Error in configuration:\n%s") % inst)
107 if self.parentui is None: 107 if self.parentui is None:
108 return default 108 return default
109 else: 109 else:
110 return self.parentui.configbool(section, name, default) 110 return self.parentui.configbool(section, name, default)
111
112 def has_config(self, section):
113 '''tell whether section exists in config.'''
114 return self.cdata.has_section(section)
111 115
112 def configitems(self, section): 116 def configitems(self, section):
113 items = {} 117 items = {}
114 if self.parentui is not None: 118 if self.parentui is not None:
115 items = dict(self.parentui.configitems(section)) 119 items = dict(self.parentui.configitems(section))
177 181
178 Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL 182 Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL
179 and stop searching if one of these is set. 183 and stop searching if one of these is set.
180 Abort if found username is an empty string to force specifying 184 Abort if found username is an empty string to force specifying
181 the commit user elsewhere, e.g. with line option or repo hgrc. 185 the commit user elsewhere, e.g. with line option or repo hgrc.
182 If not found, use $LOGNAME or $USERNAME +"@full.hostname". 186 If not found, use ($LOGNAME or $USER or $LNAME or
187 $USERNAME) +"@full.hostname".
183 """ 188 """
184 user = os.environ.get("HGUSER") 189 user = os.environ.get("HGUSER")
185 if user is None: 190 if user is None:
186 user = self.config("ui", "username") 191 user = self.config("ui", "username")
187 if user is None: 192 if user is None:
188 user = os.environ.get("EMAIL") 193 user = os.environ.get("EMAIL")
189 if user is None: 194 if user is None:
190 user = os.environ.get("LOGNAME") or os.environ.get("USERNAME") 195 try:
191 if user: 196 user = '%s@%s' % (getpass.getuser(), socket.getfqdn())
192 user = "%s@%s" % (user, socket.getfqdn()) 197 except KeyError:
193 if not user: 198 raise util.Abort(_("Please specify a username."))
194 raise util.Abort(_("Please specify a username."))
195 return user 199 return user
196 200
197 def shortuser(self, user): 201 def shortuser(self, user):
198 """Return a short representation of a user name or email address.""" 202 """Return a short representation of a user name or email address."""
199 if not self.verbose: user = util.shortuser(user) 203 if not self.verbose: user = util.shortuser(user)