Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.core
Commits
ca850fa6
Commit
ca850fa6
authored
Oct 24, 2018
by
Jérome Perrin
Committed by
Rafael Monnerat
Oct 24, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy show: uses $PAGER to paginate output
parent
530f422b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
2 deletions
+40
-2
slapos/cli/proxy_show.py
slapos/cli/proxy_show.py
+17
-2
slapos/tests/cli.py
slapos/tests/cli.py
+23
-0
No files found.
slapos/cli/proxy_show.py
View file @
ca850fa6
...
...
@@ -32,6 +32,9 @@ import hashlib
import
json
import
logging
import
sys
import
os
import
subprocess
import
StringIO
import
lxml.etree
import
prettytable
...
...
@@ -201,9 +204,13 @@ def log_network(logger, conn):
def
do_show
(
conf
):
# Because this command uses logging facility to output,
# setup a logger which displays on stdout.
# setup a logger which displays on stdout and uses a pager
# to paginate input, honoring $PAGER.
output
=
sys
.
stdout
if
output
.
isatty
():
output
=
StringIO
.
StringIO
()
proxy_show_logger
=
logging
.
getLogger
(
__name__
)
handler
=
logging
.
StreamHandler
(
sys
.
stdo
ut
)
handler
=
logging
.
StreamHandler
(
outp
ut
)
handler
.
setLevel
(
logging
.
DEBUG
)
formatter
=
logging
.
Formatter
(
'%(message)s'
)
handler
.
setFormatter
(
formatter
)
...
...
@@ -234,3 +241,11 @@ def do_show(conf):
func
(
proxy_show_logger
,
conn
)
if
idx
<
len
(
to_call
)
-
1
:
proxy_show_logger
.
info
(
' '
)
if
sys
.
stdout
.
isatty
():
pager
=
subprocess
.
Popen
(
os
.
getenv
(
'PAGER'
,
'less --quit-if-one-screen --no-init'
),
close_fds
=
True
,
shell
=
True
,
stdin
=
subprocess
.
PIPE
,)
pager
.
communicate
(
output
.
getvalue
().
encode
(
'utf-8'
))
slapos/tests/cli.py
View file @
ca850fa6
...
...
@@ -166,6 +166,29 @@ class TestCliProxyShow(CliMixin):
self
.
assertIn
(
'287375f0cba269902ba1bc50242839d7'
,
stdout
.
getvalue
())
self
.
assertEqual
(
''
,
stderr
.
getvalue
())
def
test_proxy_show_use_pager
(
self
):
saved_stderr
=
sys
.
stderr
saved_stdout
=
sys
.
stdout
sys
.
stderr
=
stderr
=
StringIO
.
StringIO
()
sys
.
stdout
=
stdout
=
StringIO
.
StringIO
()
stdout
.
isatty
=
lambda
*
args
:
True
# use a pager that just output to a file.
tmp
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
)
self
.
addCleanup
(
os
.
unlink
,
tmp
.
name
)
os
.
environ
[
'PAGER'
]
=
'cat > {}'
.
format
(
tmp
.
name
)
try
:
slapos
.
cli
.
proxy_show
.
do_show
(
self
.
conf
)
finally
:
sys
.
stderr
=
saved_stderr
sys
.
stdout
=
saved_stdout
self
.
assertEqual
(
''
,
stdout
.
getvalue
())
self
.
assertEqual
(
''
,
stderr
.
getvalue
())
# our pager was set to output to this temporary file
self
.
assertIn
(
'287375f0cba269902ba1bc50242839d7'
,
open
(
tmp
.
name
,
'r'
).
read
())
class
TestCliNode
(
CliMixin
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment