From 87dc71d926d948f539520177d4da8e848fed22f0 Mon Sep 17 00:00:00 2001 From: Shawn Davis Date: Sun, 6 Sep 2020 12:59:10 -0400 Subject: [PATCH] Added support for messages via echo and dialog. --- scripttease/library/overlays/posix.py | 33 +++++++++++++++++++++++++++ tests/test_library_overlays_posix.py | 15 ++++++++++++ 2 files changed, 48 insertions(+) diff --git a/scripttease/library/overlays/posix.py b/scripttease/library/overlays/posix.py index 6e9e070..eee10d4 100644 --- a/scripttease/library/overlays/posix.py +++ b/scripttease/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, diff --git a/tests/test_library_overlays_posix.py b/tests/test_library_overlays_posix.py index 2cbeba1..9c80e97 100644 --- a/tests/test_library_overlays_posix.py +++ b/tests/test_library_overlays_posix.py @@ -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",