Added support for messages via echo and dialog.

development
Shawn Davis 4 years ago
parent c855ba7fb7
commit 87dc71d926
  1. 33
      scripttease/library/overlays/posix.py
  2. 15
      tests/test_library_overlays_posix.py

@ -10,6 +10,8 @@ __all__ = (
"POSIX_MAPPINGS",
"archive",
"certbot",
"dialog",
"echo",
"extract",
"file_append",
"file_copy",
@ -91,6 +93,35 @@ def certbot(domain_name, email=None, webroot=None, **kwargs):
return Command(name, **kwargs)
def dialog(message, height=15, title="Message", width=100, **kwargs):
"""Display a dialog message.
- message (str): The message to be displayed.
- height (int): The height of the dialog.
- title (str): The title of the dialog.
- width (int): The width of the dialog.
"""
kwargs.setdefault("comment", "display a dialog message")
a = list()
a.append('dialog --clear --backtitle "%s"' % title)
a.append('--msgbox "%s" %s %s; clear;' % (message, height, width))
return Command(" ".join(a), **kwargs)
def echo(message, **kwargs):
"""Echo a message.
- message (str): The message to be printed to screen.
"""
kwargs.setdefault("comment", "print message to screen")
return Command('echo "%s"' % message, **kwargs)
def extract(from_path, absolute=False, exclude=None, strip=None, to_path=None, view=False, **kwargs):
"""Extract a file archive.
@ -537,6 +568,8 @@ POSIX_MAPPINGS = {
'archive': archive,
'certbot': certbot,
'copy': file_copy,
'dialog': dialog,
'echo': echo,
'extract': extract,
'func': Function,
# 'function': Function,

@ -27,6 +27,21 @@ def test_certbot():
assert "--webroot -w /var/www/domains/example_com/www -d example.com" in s
def test_dialog():
c = dialog("This is a test.", title="Testing")
s = c.get_statement(suppress_comment=True)
# dialog --clear --backtitle "Testing" --msgbox "This is a test." 15 100; clear;
assert 'dialog --clear --backtitle "Testing"' in s
assert '--msgbox "This is a test." 15 100; clear;'
def test_echo():
c = echo("This is a test.")
s = c.get_statement(suppress_comment=True)
assert "echo" in s
assert "This is a test." in s
def test_extract():
c = extract(
"/path/to/archive.tgz",

Loading…
Cancel
Save