* [PATCH v4 0/2] Refactor and improve full help output from tools
@ 2021-09-08 11:38 Paul Barker
2021-09-08 11:38 ` [PATCH v4 1/2] tools: Refactor full help printing Paul Barker
2021-09-08 11:38 ` [PATCH v4 2/2] tools: Handle PAGER containing arguments Paul Barker
0 siblings, 2 replies; 5+ messages in thread
From: Paul Barker @ 2021-09-08 11:38 UTC (permalink / raw)
To: Simon Glass, Tom Rini, u-boot; +Cc: Paul Barker
Changes from v3:
* I found some more Python madness:
>>> bool([])
False
>>> bool([None])
True
So we need to ensure that if `shlex.which(less)` returns None we don't set
pager to `[None]` else we won't be able to fall back to using more as the
pager.
Apologies for the noise in having to send v4 so quickly!
Changes from v2:
* Handle the case where `PAGER` is unset. For some absolutely crazy reason
`shlex.split(None)` reads the string to split from stdin so we need to
ensure that `os.getenv()` returns an empty string instead of None if `PAGER`
is unset.
Changes from v1:
* Collected the full help printing code from patman, buildman & binman into a
single function so that when support for PAGER containing arguments is added
it applies to all the relevant tools.
Paul Barker (2):
tools: Refactor full help printing
tools: Handle PAGER containing arguments
tools/binman/control.py | 9 +++------
tools/buildman/control.py | 10 ++++------
tools/patman/main.py | 12 ++++--------
tools/patman/tools.py | 15 +++++++++++++++
4 files changed, 26 insertions(+), 20 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/2] tools: Refactor full help printing
2021-09-08 11:38 [PATCH v4 0/2] Refactor and improve full help output from tools Paul Barker
@ 2021-09-08 11:38 ` Paul Barker
2021-09-25 0:37 ` Tom Rini
2021-09-08 11:38 ` [PATCH v4 2/2] tools: Handle PAGER containing arguments Paul Barker
1 sibling, 1 reply; 5+ messages in thread
From: Paul Barker @ 2021-09-08 11:38 UTC (permalink / raw)
To: Simon Glass, Tom Rini, u-boot; +Cc: Paul Barker
Collect the code for printing the full help message of patman, buildman
and binman into a single function in patman.tools.
Signed-off-by: Paul Barker <paul.barker@sancloud.com>
---
tools/binman/control.py | 9 +++------
tools/buildman/control.py | 10 ++++------
tools/patman/main.py | 12 ++++--------
tools/patman/tools.py | 13 +++++++++++++
4 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/tools/binman/control.py b/tools/binman/control.py
index dcba02ff7f8a..0dbcbc28e991 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -565,12 +565,9 @@ def Binman(args):
global state
if args.full_help:
- pager = os.getenv('PAGER')
- if not pager:
- pager = 'more'
- fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
- 'README.rst')
- command.Run(pager, fname)
+ tools.PrintFullHelp(
+ os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README.rst')
+ )
return 0
# Put these here so that we can import this module without libfdt
diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index a98d1b4c06f3..fd9664c85d88 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -16,6 +16,7 @@ from patman import command
from patman import gitutil
from patman import patchstream
from patman import terminal
+from patman import tools
from patman.terminal import Print
def GetPlural(count):
@@ -133,12 +134,9 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
global builder
if options.full_help:
- pager = os.getenv('PAGER')
- if not pager:
- pager = 'more'
- fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
- 'README')
- command.Run(pager, fname)
+ tools.PrintFullHelp(
+ os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README')
+ )
return 0
gitutil.Setup()
diff --git a/tools/patman/main.py b/tools/patman/main.py
index 04e37a593139..e5be28e3316c 100755
--- a/tools/patman/main.py
+++ b/tools/patman/main.py
@@ -28,6 +28,7 @@ from patman import settings
from patman import terminal
from patman import test_util
from patman import test_checkpatch
+from patman import tools
epilog = '''Create patches from commits in a branch, check them and email them
as specified by tags you place in the commits. Use -n to do a dry run first.'''
@@ -170,14 +171,9 @@ elif args.cmd == 'send':
fd.close()
elif args.full_help:
- pager = os.getenv('PAGER')
- if not pager:
- pager = shutil.which('less')
- if not pager:
- pager = 'more'
- fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
- 'README')
- command.Run(pager, fname)
+ tools.PrintFullHelp(
+ os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'README')
+ )
else:
# If we are not processing tags, no need to warning about bad ones
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 877e37cd8da1..96882264a2f9 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -581,3 +581,16 @@ def ToHexSize(val):
hex value of size, or 'None' if the value is None
"""
return 'None' if val is None else '%#x' % len(val)
+
+def PrintFullHelp(fname):
+ """Print the full help message for a tool using an appropriate pager.
+
+ Args:
+ fname: Path to a file containing the full help message
+ """
+ pager = os.getenv('PAGER')
+ if not pager:
+ pager = shutil.which('less')
+ if not pager:
+ pager = 'more'
+ command.Run(pager, fname)
--
2.33.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4 2/2] tools: Handle PAGER containing arguments
2021-09-08 11:38 [PATCH v4 0/2] Refactor and improve full help output from tools Paul Barker
2021-09-08 11:38 ` [PATCH v4 1/2] tools: Refactor full help printing Paul Barker
@ 2021-09-08 11:38 ` Paul Barker
2021-09-25 0:37 ` Tom Rini
1 sibling, 1 reply; 5+ messages in thread
From: Paul Barker @ 2021-09-08 11:38 UTC (permalink / raw)
To: Simon Glass, Tom Rini, u-boot; +Cc: Paul Barker
When printing full help output from a tool, we should be able to handle
a PAGER variable which includes arguments, e.g. PAGER='less -F'.
Signed-off-by: Paul Barker <paul.barker@sancloud.com>
---
tools/patman/tools.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 96882264a2f9..710f1fdcd361 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -5,6 +5,7 @@
import glob
import os
+import shlex
import shutil
import struct
import sys
@@ -588,9 +589,10 @@ def PrintFullHelp(fname):
Args:
fname: Path to a file containing the full help message
"""
- pager = os.getenv('PAGER')
+ pager = shlex.split(os.getenv('PAGER', ''))
if not pager:
- pager = shutil.which('less')
+ lesspath = shutil.which('less')
+ pager = [lesspath] if lesspath else None
if not pager:
- pager = 'more'
- command.Run(pager, fname)
+ pager = ['more']
+ command.Run(*pager, fname)
--
2.33.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4 1/2] tools: Refactor full help printing
2021-09-08 11:38 ` [PATCH v4 1/2] tools: Refactor full help printing Paul Barker
@ 2021-09-25 0:37 ` Tom Rini
0 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2021-09-25 0:37 UTC (permalink / raw)
To: Paul Barker; +Cc: Simon Glass, u-boot
[-- Attachment #1: Type: text/plain, Size: 301 bytes --]
On Wed, Sep 08, 2021 at 12:38:01PM +0100, Paul Barker wrote:
> Collect the code for printing the full help message of patman, buildman
> and binman into a single function in patman.tools.
>
> Signed-off-by: Paul Barker <paul.barker@sancloud.com>
Applied to u-boot/next, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 2/2] tools: Handle PAGER containing arguments
2021-09-08 11:38 ` [PATCH v4 2/2] tools: Handle PAGER containing arguments Paul Barker
@ 2021-09-25 0:37 ` Tom Rini
0 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2021-09-25 0:37 UTC (permalink / raw)
To: Paul Barker; +Cc: Simon Glass, u-boot
[-- Attachment #1: Type: text/plain, Size: 315 bytes --]
On Wed, Sep 08, 2021 at 12:38:02PM +0100, Paul Barker wrote:
> When printing full help output from a tool, we should be able to handle
> a PAGER variable which includes arguments, e.g. PAGER='less -F'.
>
> Signed-off-by: Paul Barker <paul.barker@sancloud.com>
Applied to u-boot/next, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-25 0:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08 11:38 [PATCH v4 0/2] Refactor and improve full help output from tools Paul Barker
2021-09-08 11:38 ` [PATCH v4 1/2] tools: Refactor full help printing Paul Barker
2021-09-25 0:37 ` Tom Rini
2021-09-08 11:38 ` [PATCH v4 2/2] tools: Handle PAGER containing arguments Paul Barker
2021-09-25 0:37 ` Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).