Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/ui.py @ 294:f8d56da6ac8f
hg patch: fix to actually take a list of patches
author | mpm@selenic.com |
---|---|
date | Wed, 08 Jun 2005 21:22:38 -0800 |
parents | 5a1e6d27f399 |
children | c3d873ef4b31 b2293093b89e |
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 | |
26 def config(self, section, val, default=None): | |
27 if self.cdata.has_option(section, val): | |
28 return self.cdata.get(section, val) | |
29 return default | |
30 | |
31 def configbool(self, section, val, default=False): | |
32 if self.cdata.has_option(section, val): | |
33 return self.cdata.getboolean(section, val) | |
34 return default | |
35 | |
36 def configitems(self, section): | |
37 if self.cdata.has_section(section): | |
38 return self.cdata.items(section) | |
39 return [] | |
40 | |
207 | 41 def write(self, *args): |
42 for a in args: | |
43 sys.stdout.write(str(a)) | |
44 def readline(self): | |
45 return sys.stdin.readline()[:-1] | |
46 def prompt(self, msg, pat, default = "y"): | |
47 if not self.interactive: return default | |
48 while 1: | |
49 self.write(msg, " ") | |
50 r = self.readline() | |
51 if re.match(pat, r): | |
52 return r | |
53 else: | |
54 self.write("unrecognized response\n") | |
55 def status(self, *msg): | |
56 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
|
57 def warn(self, *msg): |
207 | 58 self.write(*msg) |
59 def note(self, *msg): | |
60 if self.verbose: self.write(*msg) | |
61 def debug(self, *msg): | |
62 if self.debugflag: self.write(*msg) | |
63 def edit(self, text): | |
249 | 64 import tempfile |
207 | 65 (fd, name) = tempfile.mkstemp("hg") |
66 f = os.fdopen(fd, "w") | |
67 f.write(text) | |
68 f.close() | |
69 | |
70 editor = os.environ.get("HGEDITOR") or os.environ.get("EDITOR", "vi") | |
71 r = os.system("%s %s" % (editor, name)) | |
72 | |
73 if r: | |
74 raise "Edit failed!" | |
75 | |
76 t = open(name).read() | |
77 t = re.sub("(?m)^HG:.*\n", "", t) | |
78 | |
79 return t | |
80 |