Mercurial > hg
annotate mercurial/ui.py @ 376:fadc9e126369
hgweb: fix deleted file in filediff key error
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
hgweb: fix deleted file in filediff key error
manifest hash: f751d213d2d2d49b3631dbe72699554e58ae590a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCsQOVW7P1GVgWeRoRAvRAAJ9cLxO+QLg6gEnn/0XPZJP1G/8/KQCfdygL
b+awDXRJmE0onoNzvzzIcBg=
=jDV4
-----END PGP SIGNATURE-----
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Thu, 16 Jun 2005 05:44:05 +0100 |
parents | b4e0e20646bb |
children | 1f81ebff98c9 |
rev | line source |
---|---|
207 | 1 # ui.py - user interface bits for mercurial |
2 # | |
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
4 # | |
5 # This software may be used and distributed according to the terms | |
6 # of the GNU General Public License, incorporated herein by reference. | |
7 | |
285 | 8 import os, sys, re, ConfigParser |
207 | 9 |
10 class ui: | |
11 def __init__(self, verbose=False, debug=False, quiet=False, | |
12 interactive=True): | |
285 | 13 self.cdata = ConfigParser.SafeConfigParser() |
14 self.cdata.read(os.path.expanduser("~/.hgrc")) | |
15 | |
16 self.quiet = self.configbool("ui", "quiet") | |
17 self.verbose = self.configbool("ui", "verbose") | |
18 self.debugflag = self.configbool("ui", "debug") | |
19 self.interactive = self.configbool("ui", "interactive", True) | |
20 | |
21 self.quiet = (self.quiet or quiet) and not verbose and not debug | |
22 self.verbose = (self.verbose or verbose) or debug | |
23 self.debugflag = (self.debugflag or debug) | |
24 self.interactive = (self.interactive and interactive) | |
25 | |
337 | 26 def readconfig(self, fp): |
27 self.cdata.readfp(fp) | |
28 | |
285 | 29 def config(self, section, val, default=None): |
30 if self.cdata.has_option(section, val): | |
31 return self.cdata.get(section, val) | |
32 return default | |
33 | |
34 def configbool(self, section, val, default=False): | |
35 if self.cdata.has_option(section, val): | |
36 return self.cdata.getboolean(section, val) | |
37 return default | |
38 | |
39 def configitems(self, section): | |
40 if self.cdata.has_section(section): | |
41 return self.cdata.items(section) | |
42 return [] | |
43 | |
207 | 44 def write(self, *args): |
45 for a in args: | |
46 sys.stdout.write(str(a)) | |
47 def readline(self): | |
48 return sys.stdin.readline()[:-1] | |
49 def prompt(self, msg, pat, default = "y"): | |
50 if not self.interactive: return default | |
51 while 1: | |
52 self.write(msg, " ") | |
53 r = self.readline() | |
54 if re.match(pat, r): | |
55 return r | |
56 else: | |
57 self.write("unrecognized response\n") | |
58 def status(self, *msg): | |
59 if not self.quiet: self.write(*msg) | |
234
3427806d5ab9
ui.warn can use more than one argument like the other ui methods.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
207
diff
changeset
|
60 def warn(self, *msg): |
207 | 61 self.write(*msg) |
62 def note(self, *msg): | |
63 if self.verbose: self.write(*msg) | |
64 def debug(self, *msg): | |
65 if self.debugflag: self.write(*msg) | |
66 def edit(self, text): | |
249 | 67 import tempfile |
207 | 68 (fd, name) = tempfile.mkstemp("hg") |
69 f = os.fdopen(fd, "w") | |
70 f.write(text) | |
71 f.close() | |
72 | |
73 editor = os.environ.get("HGEDITOR") or os.environ.get("EDITOR", "vi") | |
74 r = os.system("%s %s" % (editor, name)) | |
75 | |
76 if r: | |
77 raise "Edit failed!" | |
78 | |
79 t = open(name).read() | |
80 t = re.sub("(?m)^HG:.*\n", "", t) | |
81 | |
82 return t | |
83 |