Beispiel #1
0
def test_Display_banner_get_text_width(monkeypatch):
    initialize_locale()
    display = Display()
    display_mock = MagicMock()
    monkeypatch.setattr(display, 'display', display_mock)

    display.banner(u'🚀🐮', color=False, cows=False)
    args, kwargs = display_mock.call_args
    msg = args[0]
    stars = u' %s' % (75 * u'*')
    assert msg.endswith(stars)
Beispiel #2
0
def test_get_text_width():
    initialize_locale()
    assert get_text_width(u'コンニチハ') == 10
    assert get_text_width(u'abコcd') == 6
    assert get_text_width(u'café') == 4
    assert get_text_width(u'four') == 4
    assert get_text_width(u'\u001B') == 0
    assert get_text_width(u'ab\u0000') == 2
    assert get_text_width(u'abコ\u0000') == 4
    assert get_text_width(u'🚀🐮') == 4
    assert get_text_width(u'\x08') == 0
    assert get_text_width(u'\x08\x08') == 0
    assert get_text_width(u'ab\x08cd') == 3
    assert get_text_width(u'ab\x1bcd') == 3
    assert get_text_width(u'ab\x7fcd') == 3
    assert get_text_width(u'ab\x94cd') == 3

    pytest.raises(TypeError, get_text_width, 1)
    pytest.raises(TypeError, get_text_width, b'four')
    def run(self):
        super().run()

        # Required to fix the warning "ansible.utils.display.initialize_locale has not been called..."
        initialize_locale()
        display.verbosity = self.options.verbosity
        grapher = Grapher(self.options.playbook_filenames)
        grapher.parse(
            include_role_tasks=self.options.include_role_tasks,
            tags=self.options.tags,
            skip_tags=self.options.skip_tags,
            group_roles_by_name=self.options.group_roles_by_name,
        )
        digraph = grapher.graph(
            open_protocol_handler=self.options.open_protocol_handler,
            open_protocol_custom_formats=self.options.
            open_protocol_custom_formats,
        )

        display.display("Rendering the graph...")
        svg_path = digraph.render(
            cleanup=not self.options.save_dot_file,
            format="svg",
            filename=self.options.output_filename,
            view=self.options.view,
        )

        post_processor = GraphVizPostProcessor(svg_path=svg_path)
        display.v("Post processing the SVG...")
        post_processor.post_process(grapher.playbook_nodes)
        post_processor.write()

        display.display(f"The graph has been exported to {svg_path}",
                        color="green")
        if self.options.save_dot_file:
            # add .dot extension. The render doesn't add an extension
            final_name = self.options.output_filename + ".dot"
            os.rename(self.options.output_filename, final_name)
            display.display(
                f"Graphviz dot file has been exported to {final_name}")

        return svg_path
Beispiel #4
0
    raise SystemExit(
        'ERROR: Ansible requires Jinja2 3.0 or newer on the controller. '
        'Current version: %s' % jinja2_version)

import errno
import getpass
import os
import subprocess
import traceback
from abc import ABC, abstractmethod
from pathlib import Path

try:
    from ansible import constants as C
    from ansible.utils.display import Display, initialize_locale
    initialize_locale()
    display = Display()
except Exception as e:
    print('ERROR: %s' % e, file=sys.stderr)
    sys.exit(5)

from ansible import context
from ansible.cli.arguments import option_helpers as opt_help
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
from ansible.inventory.manager import InventoryManager
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_bytes, to_text
from ansible.parsing.dataloader import DataLoader
from ansible.parsing.vault import PromptVaultSecret, get_file_vault_secret
from ansible.plugins.loader import add_all_plugin_dirs
from ansible.release import __version__