##// END OF EJS Templates
pager: use absolute_import
Augie Fackler -
r28320:63c2864a default
parent child Browse files
Show More
@@ -1,158 +1,170
1 1 # pager.py - display output using a pager
2 2 #
3 3 # Copyright 2008 David Soria Parra <dsp@php.net>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7 #
8 8 # To load the extension, add it to your configuration file:
9 9 #
10 10 # [extension]
11 11 # pager =
12 12 #
13 13 # Run "hg help pager" to get info on configuration.
14 14
15 15 '''browse command output with an external pager
16 16
17 17 To set the pager that should be used, set the application variable::
18 18
19 19 [pager]
20 20 pager = less -FRX
21 21
22 22 If no pager is set, the pager extensions uses the environment variable
23 23 $PAGER. If neither pager.pager, nor $PAGER is set, no pager is used.
24 24
25 25 You can disable the pager for certain commands by adding them to the
26 26 pager.ignore list::
27 27
28 28 [pager]
29 29 ignore = version, help, update
30 30
31 31 You can also enable the pager only for certain commands using
32 32 pager.attend. Below is the default list of commands to be paged::
33 33
34 34 [pager]
35 35 attend = annotate, cat, diff, export, glog, log, qdiff
36 36
37 37 Setting pager.attend to an empty value will cause all commands to be
38 38 paged.
39 39
40 40 If pager.attend is present, pager.ignore will be ignored.
41 41
42 42 Lastly, you can enable and disable paging for individual commands with
43 43 the attend-<command> option. This setting takes precedence over
44 44 existing attend and ignore options and defaults::
45 45
46 46 [pager]
47 47 attend-cat = false
48 48
49 49 To ignore global commands like :hg:`version` or :hg:`help`, you have
50 50 to specify them in your user configuration file.
51 51
52 52 To control whether the pager is used at all for an individual command,
53 53 you can use --pager=<value>::
54 54
55 55 - use as needed: `auto`.
56 56 - require the pager: `yes` or `on`.
57 57 - suppress the pager: `no` or `off` (any unrecognized value
58 58 will also work).
59 59
60 60 '''
61 from __future__ import absolute_import
61 62
62 import atexit, sys, os, signal, subprocess
63 from mercurial import commands, dispatch, util, extensions, cmdutil
63 import atexit
64 import os
65 import signal
66 import subprocess
67 import sys
68
69 from mercurial import (
70 cmdutil,
71 commands,
72 dispatch,
73 extensions,
74 util,
75 )
64 76 from mercurial.i18n import _
65 77
66 78 # Note for extension authors: ONLY specify testedwith = 'internal' for
67 79 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
68 80 # be specifying the version(s) of Mercurial they are tested with, or
69 81 # leave the attribute unspecified.
70 82 testedwith = 'internal'
71 83
72 84 def _runpager(ui, p):
73 85 pager = subprocess.Popen(p, shell=True, bufsize=-1,
74 86 close_fds=util.closefds, stdin=subprocess.PIPE,
75 87 stdout=sys.stdout, stderr=sys.stderr)
76 88
77 89 # back up original file objects and descriptors
78 90 olduifout = ui.fout
79 91 oldstdout = sys.stdout
80 92 stdoutfd = os.dup(sys.stdout.fileno())
81 93 stderrfd = os.dup(sys.stderr.fileno())
82 94
83 95 # create new line-buffered stdout so that output can show up immediately
84 96 ui.fout = sys.stdout = newstdout = os.fdopen(sys.stdout.fileno(), 'wb', 1)
85 97 os.dup2(pager.stdin.fileno(), sys.stdout.fileno())
86 98 if ui._isatty(sys.stderr):
87 99 os.dup2(pager.stdin.fileno(), sys.stderr.fileno())
88 100
89 101 @atexit.register
90 102 def killpager():
91 103 if util.safehasattr(signal, "SIGINT"):
92 104 signal.signal(signal.SIGINT, signal.SIG_IGN)
93 105 pager.stdin.close()
94 106 ui.fout = olduifout
95 107 sys.stdout = oldstdout
96 108 # close new stdout while it's associated with pager; otherwise stdout
97 109 # fd would be closed when newstdout is deleted
98 110 newstdout.close()
99 111 # restore original fds: stdout is open again
100 112 os.dup2(stdoutfd, sys.stdout.fileno())
101 113 os.dup2(stderrfd, sys.stderr.fileno())
102 114 pager.wait()
103 115
104 116 def uisetup(ui):
105 117 if '--debugger' in sys.argv or not ui.formatted():
106 118 return
107 119
108 120 def pagecmd(orig, ui, options, cmd, cmdfunc):
109 121 p = ui.config("pager", "pager", os.environ.get("PAGER"))
110 122 usepager = False
111 123 always = util.parsebool(options['pager'])
112 124 auto = options['pager'] == 'auto'
113 125
114 126 if not p:
115 127 pass
116 128 elif always:
117 129 usepager = True
118 130 elif not auto:
119 131 usepager = False
120 132 else:
121 133 attend = ui.configlist('pager', 'attend', attended)
122 134 ignore = ui.configlist('pager', 'ignore')
123 135 cmds, _ = cmdutil.findcmd(cmd, commands.table)
124 136
125 137 for cmd in cmds:
126 138 var = 'attend-%s' % cmd
127 139 if ui.config('pager', var):
128 140 usepager = ui.configbool('pager', var)
129 141 break
130 142 if (cmd in attend or
131 143 (cmd not in ignore and not attend)):
132 144 usepager = True
133 145 break
134 146
135 147 setattr(ui, 'pageractive', usepager)
136 148
137 149 if usepager:
138 150 ui.setconfig('ui', 'formatted', ui.formatted(), 'pager')
139 151 ui.setconfig('ui', 'interactive', False, 'pager')
140 152 if util.safehasattr(signal, "SIGPIPE"):
141 153 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
142 154 _runpager(ui, p)
143 155 return orig(ui, options, cmd, cmdfunc)
144 156
145 157 # Wrap dispatch._runcommand after color is loaded so color can see
146 158 # ui.pageractive. Otherwise, if we loaded first, color's wrapped
147 159 # dispatch._runcommand would run without having access to ui.pageractive.
148 160 def afterloaded(loaded):
149 161 extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
150 162 extensions.afterloaded('color', afterloaded)
151 163
152 164 def extsetup(ui):
153 165 commands.globalopts.append(
154 166 ('', 'pager', 'auto',
155 167 _("when to paginate (boolean, always, auto, or never)"),
156 168 _('TYPE')))
157 169
158 170 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']
@@ -1,171 +1,170
1 1 #require test-repo
2 2
3 3 $ cd "$TESTDIR"/..
4 4
5 5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
6 6 contrib/casesmash.py not using absolute_import
7 7 contrib/check-code.py not using absolute_import
8 8 contrib/check-code.py requires print_function
9 9 contrib/check-config.py not using absolute_import
10 10 contrib/check-config.py requires print_function
11 11 contrib/debugcmdserver.py not using absolute_import
12 12 contrib/debugcmdserver.py requires print_function
13 13 contrib/debugshell.py not using absolute_import
14 14 contrib/fixpax.py not using absolute_import
15 15 contrib/fixpax.py requires print_function
16 16 contrib/hgclient.py not using absolute_import
17 17 contrib/hgclient.py requires print_function
18 18 contrib/hgfixes/fix_bytes.py not using absolute_import
19 19 contrib/hgfixes/fix_bytesmod.py not using absolute_import
20 20 contrib/hgfixes/fix_leftover_imports.py not using absolute_import
21 21 contrib/import-checker.py not using absolute_import
22 22 contrib/import-checker.py requires print_function
23 23 contrib/memory.py not using absolute_import
24 24 contrib/perf.py not using absolute_import
25 25 contrib/python-hook-examples.py not using absolute_import
26 26 contrib/revsetbenchmarks.py not using absolute_import
27 27 contrib/revsetbenchmarks.py requires print_function
28 28 contrib/showstack.py not using absolute_import
29 29 contrib/synthrepo.py not using absolute_import
30 30 contrib/win32/hgwebdir_wsgi.py not using absolute_import
31 31 doc/check-seclevel.py not using absolute_import
32 32 doc/gendoc.py not using absolute_import
33 33 doc/hgmanpage.py not using absolute_import
34 34 hgext/__init__.py not using absolute_import
35 35 hgext/color.py not using absolute_import
36 36 hgext/convert/__init__.py not using absolute_import
37 37 hgext/convert/bzr.py not using absolute_import
38 38 hgext/convert/common.py not using absolute_import
39 39 hgext/convert/convcmd.py not using absolute_import
40 40 hgext/convert/cvs.py not using absolute_import
41 41 hgext/convert/cvsps.py not using absolute_import
42 42 hgext/convert/darcs.py not using absolute_import
43 43 hgext/convert/filemap.py not using absolute_import
44 44 hgext/convert/git.py not using absolute_import
45 45 hgext/convert/gnuarch.py not using absolute_import
46 46 hgext/convert/hg.py not using absolute_import
47 47 hgext/convert/monotone.py not using absolute_import
48 48 hgext/convert/p4.py not using absolute_import
49 49 hgext/convert/subversion.py not using absolute_import
50 50 hgext/convert/transport.py not using absolute_import
51 51 hgext/eol.py not using absolute_import
52 52 hgext/extdiff.py not using absolute_import
53 53 hgext/factotum.py not using absolute_import
54 54 hgext/fetch.py not using absolute_import
55 55 hgext/gpg.py not using absolute_import
56 56 hgext/graphlog.py not using absolute_import
57 57 hgext/hgcia.py not using absolute_import
58 58 hgext/hgk.py not using absolute_import
59 59 hgext/highlight/__init__.py not using absolute_import
60 60 hgext/highlight/highlight.py not using absolute_import
61 61 hgext/histedit.py not using absolute_import
62 62 hgext/keyword.py not using absolute_import
63 63 hgext/largefiles/__init__.py not using absolute_import
64 64 hgext/largefiles/basestore.py not using absolute_import
65 65 hgext/largefiles/lfcommands.py not using absolute_import
66 66 hgext/largefiles/lfutil.py not using absolute_import
67 67 hgext/largefiles/localstore.py not using absolute_import
68 68 hgext/largefiles/overrides.py not using absolute_import
69 69 hgext/largefiles/proto.py not using absolute_import
70 70 hgext/largefiles/remotestore.py not using absolute_import
71 71 hgext/largefiles/reposetup.py not using absolute_import
72 72 hgext/largefiles/uisetup.py not using absolute_import
73 73 hgext/largefiles/wirestore.py not using absolute_import
74 74 hgext/mq.py not using absolute_import
75 75 hgext/notify.py not using absolute_import
76 hgext/pager.py not using absolute_import
77 76 hgext/patchbomb.py not using absolute_import
78 77 hgext/purge.py not using absolute_import
79 78 hgext/rebase.py not using absolute_import
80 79 hgext/record.py not using absolute_import
81 80 hgext/relink.py not using absolute_import
82 81 hgext/schemes.py not using absolute_import
83 82 hgext/share.py not using absolute_import
84 83 hgext/shelve.py not using absolute_import
85 84 hgext/strip.py not using absolute_import
86 85 hgext/transplant.py not using absolute_import
87 86 hgext/win32mbcs.py not using absolute_import
88 87 hgext/win32text.py not using absolute_import
89 88 i18n/check-translation.py not using absolute_import
90 89 i18n/polib.py not using absolute_import
91 90 mercurial/cmdutil.py not using absolute_import
92 91 mercurial/commands.py not using absolute_import
93 92 setup.py not using absolute_import
94 93 tests/filterpyflakes.py requires print_function
95 94 tests/generate-working-copy-states.py requires print_function
96 95 tests/get-with-headers.py requires print_function
97 96 tests/heredoctest.py requires print_function
98 97 tests/hypothesishelpers.py not using absolute_import
99 98 tests/hypothesishelpers.py requires print_function
100 99 tests/killdaemons.py not using absolute_import
101 100 tests/md5sum.py not using absolute_import
102 101 tests/mockblackbox.py not using absolute_import
103 102 tests/printenv.py not using absolute_import
104 103 tests/readlink.py not using absolute_import
105 104 tests/readlink.py requires print_function
106 105 tests/revlog-formatv0.py not using absolute_import
107 106 tests/run-tests.py not using absolute_import
108 107 tests/seq.py not using absolute_import
109 108 tests/seq.py requires print_function
110 109 tests/silenttestrunner.py not using absolute_import
111 110 tests/silenttestrunner.py requires print_function
112 111 tests/sitecustomize.py not using absolute_import
113 112 tests/svn-safe-append.py not using absolute_import
114 113 tests/svnxml.py not using absolute_import
115 114 tests/test-ancestor.py requires print_function
116 115 tests/test-atomictempfile.py not using absolute_import
117 116 tests/test-batching.py not using absolute_import
118 117 tests/test-batching.py requires print_function
119 118 tests/test-bdiff.py not using absolute_import
120 119 tests/test-bdiff.py requires print_function
121 120 tests/test-context.py not using absolute_import
122 121 tests/test-context.py requires print_function
123 122 tests/test-demandimport.py not using absolute_import
124 123 tests/test-demandimport.py requires print_function
125 124 tests/test-dispatch.py not using absolute_import
126 125 tests/test-dispatch.py requires print_function
127 126 tests/test-doctest.py not using absolute_import
128 127 tests/test-duplicateoptions.py not using absolute_import
129 128 tests/test-duplicateoptions.py requires print_function
130 129 tests/test-filecache.py not using absolute_import
131 130 tests/test-filecache.py requires print_function
132 131 tests/test-filelog.py not using absolute_import
133 132 tests/test-filelog.py requires print_function
134 133 tests/test-hg-parseurl.py not using absolute_import
135 134 tests/test-hg-parseurl.py requires print_function
136 135 tests/test-hgweb-auth.py not using absolute_import
137 136 tests/test-hgweb-auth.py requires print_function
138 137 tests/test-hgwebdir-paths.py not using absolute_import
139 138 tests/test-hybridencode.py not using absolute_import
140 139 tests/test-hybridencode.py requires print_function
141 140 tests/test-lrucachedict.py not using absolute_import
142 141 tests/test-lrucachedict.py requires print_function
143 142 tests/test-manifest.py not using absolute_import
144 143 tests/test-minirst.py not using absolute_import
145 144 tests/test-minirst.py requires print_function
146 145 tests/test-parseindex2.py not using absolute_import
147 146 tests/test-parseindex2.py requires print_function
148 147 tests/test-pathencode.py not using absolute_import
149 148 tests/test-pathencode.py requires print_function
150 149 tests/test-propertycache.py not using absolute_import
151 150 tests/test-propertycache.py requires print_function
152 151 tests/test-revlog-ancestry.py not using absolute_import
153 152 tests/test-revlog-ancestry.py requires print_function
154 153 tests/test-run-tests.py not using absolute_import
155 154 tests/test-simplemerge.py not using absolute_import
156 155 tests/test-status-inprocess.py not using absolute_import
157 156 tests/test-status-inprocess.py requires print_function
158 157 tests/test-symlink-os-yes-fs-no.py not using absolute_import
159 158 tests/test-trusted.py not using absolute_import
160 159 tests/test-trusted.py requires print_function
161 160 tests/test-ui-color.py not using absolute_import
162 161 tests/test-ui-color.py requires print_function
163 162 tests/test-ui-config.py not using absolute_import
164 163 tests/test-ui-config.py requires print_function
165 164 tests/test-ui-verbosity.py not using absolute_import
166 165 tests/test-ui-verbosity.py requires print_function
167 166 tests/test-url.py not using absolute_import
168 167 tests/test-url.py requires print_function
169 168 tests/test-walkrepo.py requires print_function
170 169 tests/test-wireproto.py requires print_function
171 170 tests/tinyproxy.py requires print_function
General Comments 0
You need to be logged in to leave comments. Login now