Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: bin/, cnf/
Date: Wed, 28 Sep 2011 18:42:09
Message-Id: 3be910392f1186cacf0796e952fb5dae38b10f57.zmedico@gentoo
1 commit: 3be910392f1186cacf0796e952fb5dae38b10f57
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Wed Sep 28 18:41:44 2011 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Wed Sep 28 18:41:44 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=3be91039
7
8 dispatch-conf: support PAGER var for bug #384663
9
10 ---
11 bin/dispatch-conf | 32 ++++++++++++++++++++++++++++++++
12 cnf/dispatch-conf.conf | 10 +++++++++-
13 2 files changed, 41 insertions(+), 1 deletions(-)
14
15 diff --git a/bin/dispatch-conf b/bin/dispatch-conf
16 index 497927d..55d7f13 100755
17 --- a/bin/dispatch-conf
18 +++ b/bin/dispatch-conf
19 @@ -64,6 +64,20 @@ atexit.register(cleanup)
20
21 MANDATORY_OPTS = [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wscomments', 'merge' ]
22
23 +def cmd_var_is_valid(cmd):
24 + """
25 + Return true if the first whitespace-separated token contained
26 + in cmd is an executable file, false otherwise.
27 + """
28 + cmd = portage.util.shlex_split(cmd)
29 + if not cmd:
30 + return False
31 +
32 + if os.path.isabs(cmd[0]):
33 + return os.access(cmd[0], os.EX_OK)
34 +
35 + return find_binary(cmd[0]) is not None
36 +
37 class dispatch:
38 options = {}
39
40 @@ -84,6 +98,22 @@ class dispatch:
41 else:
42 self.options["log-file"] = "/dev/null"
43
44 + pager = self.options.get("pager")
45 + if pager is None or not cmd_var_is_valid(pager):
46 + pager = os.environ.get("PAGER")
47 + if pager is None or not cmd_var_is_valid(pager):
48 + pager = "cat"
49 +
50 + if os.path.basename(pager) == "less":
51 + less_opts = self.options.get("less-opts")
52 + if less_opts is not None and less_opts.strip():
53 + pager += " " + less_opts
54 +
55 + if os.path.basename(portage.util.shlex_split(pager)[0]) == "cat":
56 + pager = ""
57 + else:
58 + pager = " | " + pager
59 +
60 #
61 # Build list of extant configs
62 #
63 @@ -226,10 +256,12 @@ class dispatch:
64 clear_screen()
65 if show_new_diff:
66 cmd = self.options['diff'] % (conf['new'], mrgconf)
67 + cmd += pager
68 spawn_shell(cmd)
69 show_new_diff = 0
70 else:
71 cmd = self.options['diff'] % (conf['current'], newconf)
72 + cmd += pager
73 spawn_shell(cmd)
74
75 print()
76
77 diff --git a/cnf/dispatch-conf.conf b/cnf/dispatch-conf.conf
78 index b51b61a..c4ab33f 100644
79 --- a/cnf/dispatch-conf.conf
80 +++ b/cnf/dispatch-conf.conf
81 @@ -22,7 +22,15 @@ use-rcs=no
82 # %s new file
83 # If using colordiff instead of diff, the less -R option may be required
84 # for correct display.
85 -diff="diff -Nu '%s' '%s' | less --no-init --QUIT-AT-EOF"
86 +diff="diff -Nu '%s' '%s'"
87 +
88 +# Set the pager for use with diff commands (this will
89 +# cause the PAGER environment variable to be ignored).
90 +# Setting pager="cat" will disable pager usage.
91 +pager=""
92 +
93 +# Default options used if less is the pager
94 +less-opts="--no-init --QUIT-AT-EOF"
95
96 # Diff for interactive merges.
97 # %s output file