Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/ui.py @ 610:4c02464cb9f0
check export options for changeset before running
# HG changeset patch
# User shaleh@speakeasy.net
# Node ID 0cc64f4312540b2081c76dc589cc825d734676d8
# Parent f7bfe827ea381afc89f486b2d93d7f4fe86de04d
check export options for changeset before running
diff -r f7bfe827ea38 -r 0cc64f431254 mercurial/commands.py
author | shaleh@speakeasy.net |
---|---|
date | Mon, 04 Jul 2005 11:06:01 -0800 |
parents | d2994b5298fb |
children | 5374955ec5b1 |
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 | |
508 | 8 import os, sys, re, ConfigParser, util |
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 | |
608
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
44 def username(self): |
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
45 return (self.config("ui", "username") or |
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
46 os.environ.get("HGUSER") or |
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
47 os.environ.get("EMAIL") or |
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
48 (os.environ.get("LOGNAME", |
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
49 os.environ.get("USERNAME", "unknown")) |
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
50 + '@' + socket.getfqdn())) |
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
51 |
506 | 52 def expandpath(self, loc): |
53 paths = {} | |
54 for name, path in self.configitems("paths"): | |
55 paths[name] = path | |
56 | |
57 return paths.get(loc, loc) | |
58 | |
207 | 59 def write(self, *args): |
60 for a in args: | |
61 sys.stdout.write(str(a)) | |
565 | 62 |
63 def write_err(self, *args): | |
64 sys.stdout.flush() | |
65 for a in args: | |
66 sys.stderr.write(str(a)) | |
67 | |
207 | 68 def readline(self): |
69 return sys.stdin.readline()[:-1] | |
70 def prompt(self, msg, pat, default = "y"): | |
71 if not self.interactive: return default | |
72 while 1: | |
73 self.write(msg, " ") | |
74 r = self.readline() | |
75 if re.match(pat, r): | |
76 return r | |
77 else: | |
78 self.write("unrecognized response\n") | |
79 def status(self, *msg): | |
80 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
|
81 def warn(self, *msg): |
565 | 82 self.write_err(*msg) |
207 | 83 def note(self, *msg): |
84 if self.verbose: self.write(*msg) | |
85 def debug(self, *msg): | |
86 if self.debugflag: self.write(*msg) | |
87 def edit(self, text): | |
249 | 88 import tempfile |
207 | 89 (fd, name) = tempfile.mkstemp("hg") |
90 f = os.fdopen(fd, "w") | |
91 f.write(text) | |
92 f.close() | |
93 | |
608
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
94 editor = (self.config("ui", "editor") or |
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
95 os.environ.get("HGEDITOR") or |
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
96 os.environ.get("EDITOR", "vi")) |
d2994b5298fb
Add username/merge/editor to .hgrc
Matt Mackall <mpm@selenic.com>
parents:
565
diff
changeset
|
97 |
508 | 98 util.system("%s %s" % (editor, name), errprefix = "edit failed") |
207 | 99 |
100 t = open(name).read() | |
101 t = re.sub("(?m)^HG:.*\n", "", t) | |
102 | |
103 return t |