1""" 2Simple text outputter 3===================== 4 5The ``txt`` outputter has been developed to make the output from shell commands 6on minions appear as they do when the command is executed on the minion. 7 8CLI Example: 9 10.. code-block:: bash 11 12 salt '*' foo.bar --out=txt 13""" 14 15import pprint 16 17 18def output(data, **kwargs): # pylint: disable=unused-argument 19 """ 20 Output the data in lines, very nice for running commands 21 """ 22 ret = "" 23 if hasattr(data, "keys"): 24 for key in data: 25 value = data[key] 26 # Don't blow up on non-strings 27 try: 28 for line in value.splitlines(): 29 ret += "{}: {}\n".format(key, line) 30 except AttributeError: 31 ret += "{}: {}\n".format(key, value) 32 else: 33 try: 34 ret += data + "\n" 35 except TypeError: 36 # For non-dictionary, non-string data, just use print 37 ret += "{}\n".format(pprint.pformat(data)) 38 39 return ret 40