diff options
Diffstat (limited to 'mercurial/ui.py')
-rw-r--r-- | mercurial/ui.py | 76 |
1 files changed, 17 insertions, 59 deletions
diff --git a/mercurial/ui.py b/mercurial/ui.py index 5d80df4..8f3b1eb 100644 --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -7,7 +7,7 @@ from i18n import _ import errno, getpass, os, socket, sys, tempfile, traceback -import config, scmutil, util, error, formatter +import config, scmutil, util, error class ui(object): def __init__(self, src=None): @@ -19,7 +19,6 @@ class ui(object): self._ucfg = config.config() # untrusted self._trustusers = set() self._trustgroups = set() - self.callhooks = True if src: self.fout = src.fout @@ -32,7 +31,6 @@ class ui(object): self._trustusers = src._trustusers.copy() self._trustgroups = src._trustgroups.copy() self.environ = src.environ - self.callhooks = src.callhooks self.fixconfig() else: self.fout = sys.stdout @@ -48,10 +46,7 @@ class ui(object): def copy(self): return self.__class__(self) - def formatter(self, topic, opts): - return formatter.formatter(self, topic, opts) - - def _trusted(self, fp, f): + def _is_trusted(self, fp, f): st = util.fstat(fp) if util.isowner(st): return True @@ -66,7 +61,7 @@ class ui(object): return True if self._reportuntrusted: - self.warn(_('not trusting file %s from untrusted ' + self.warn(_('Not trusting file %s from untrusted ' 'user %s, group %s\n') % (f, user, group)) return False @@ -80,15 +75,14 @@ class ui(object): raise cfg = config.config() - trusted = sections or trust or self._trusted(fp, filename) + trusted = sections or trust or self._is_trusted(fp, filename) try: cfg.read(filename, fp, sections=sections, remap=remap) - fp.close() except error.ConfigError, inst: if trusted: raise - self.warn(_("ignored: %s\n") % str(inst)) + self.warn(_("Ignored: %s\n") % str(inst)) if self.plain(): for k in ('debug', 'fallbackencoding', 'quiet', 'slash', @@ -147,15 +141,6 @@ class ui(object): self._trustusers.update(self.configlist('trusted', 'users')) self._trustgroups.update(self.configlist('trusted', 'groups')) - def backupconfig(self, section, item): - return (self._ocfg.backup(section, item), - self._tcfg.backup(section, item), - self._ucfg.backup(section, item),) - def restoreconfig(self, data): - self._ocfg.restore(data[0]) - self._tcfg.restore(data[1]) - self._ucfg.restore(data[2]) - def setconfig(self, section, name, value, overlay=True): if overlay: self._ocfg.set(section, name, value) @@ -170,19 +155,7 @@ class ui(object): return self._data(untrusted).source(section, name) or 'none' def config(self, section, name, default=None, untrusted=False): - if isinstance(name, list): - alternates = name - else: - alternates = [name] - - for n in alternates: - value = self._data(untrusted).get(section, name, None) - if value is not None: - name = n - break - else: - value = default - + value = self._data(untrusted).get(section, name, default) if self.debugflag and not untrusted and self._reportuntrusted: uvalue = self._ucfg.get(section, name) if uvalue is not None and uvalue != value: @@ -191,14 +164,12 @@ class ui(object): return value def configpath(self, section, name, default=None, untrusted=False): - 'get a path config item, expanded relative to repo root or config file' + 'get a path config item, expanded relative to config file' v = self.config(section, name, default, untrusted) - if v is None: - return None if not os.path.isabs(v) or "://" not in v: src = self.configsource(section, name, untrusted) if ':' in src: - base = os.path.dirname(src.rsplit(':')[0]) + base = os.path.dirname(src.rsplit(':')) v = os.path.join(base, os.path.expanduser(v)) return v @@ -411,7 +382,7 @@ class ui(object): if user is None and not self.interactive(): try: user = '%s@%s' % (util.getuser(), socket.getfqdn()) - self.warn(_("no username found, using '%s' instead\n") % user) + self.warn(_("No username found, using '%s' instead\n") % user) except KeyError: pass if not user: @@ -485,19 +456,14 @@ class ui(object): if not getattr(self.ferr, 'closed', False): self.ferr.flush() except IOError, inst: - if inst.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): + if inst.errno not in (errno.EPIPE, errno.EIO): raise def flush(self): try: self.fout.flush() - except (IOError, ValueError): pass + except: pass try: self.ferr.flush() - except (IOError, ValueError): pass - - def _isatty(self, fh): - if self.configbool('ui', 'nontty', False): - return False - return util.isatty(fh) + except: pass def interactive(self): '''is interactive input allowed? @@ -517,7 +483,7 @@ class ui(object): if i is None: # some environments replace stdin without implementing isatty # usually those are non-interactive - return self._isatty(self.fin) + return util.isatty(self.fin) return i @@ -555,12 +521,12 @@ class ui(object): if i is None: # some environments replace stdout without implementing isatty # usually those are non-interactive - return self._isatty(self.fout) + return util.isatty(self.fout) return i def _readline(self, prompt=''): - if self._isatty(self.fin): + if util.isatty(self.fin): try: # magically add command line editing support, where # available @@ -687,25 +653,17 @@ class ui(object): printed.''' if self.tracebackflag: if exc: - traceback.print_exception(exc[0], exc[1], exc[2], - file=self.ferr) + traceback.print_exception(exc[0], exc[1], exc[2], file=self.ferr) else: traceback.print_exc(file=self.ferr) return self.tracebackflag def geteditor(self): '''return editor to use''' - if sys.platform == 'plan9': - # vi is the MIPS instruction simulator on Plan 9. We - # instead default to E to plumb commit messages to - # avoid confusion. - editor = 'E' - else: - editor = 'vi' return (os.environ.get("HGEDITOR") or self.config("ui", "editor") or os.environ.get("VISUAL") or - os.environ.get("EDITOR", editor)) + os.environ.get("EDITOR", "vi")) def progress(self, topic, pos, item="", unit="", total=None): '''show a progress message |